use of org.bf2.operator.operands.KafkaInstanceConfiguration.AccessControl in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaCluster method addKafkaAuthorizerConfig.
private void addKafkaAuthorizerConfig(ManagedKafka managedKafka, Map<String, Object> config) {
List<String> owners = managedKafka.getSpec().getOwners();
AtomicInteger aclCount = new AtomicInteger(0);
AtomicInteger aclLoggingCount = new AtomicInteger(0);
AccessControl aclConfig = getAclConfig(managedKafka);
final String configPrefix = aclConfig.getConfigPrefix();
final String allowedListenersKey = configPrefix + "allowed-listeners";
final String resourceOperationsKey = configPrefix + "resource-operations";
final String aclKeyPrefix = configPrefix + "acl";
final String aclLoggingKeyPrefix = aclKeyPrefix + ".logging";
final String aclKeyTemplate = aclKeyPrefix + ".%03d";
final String aclLoggingKeyTemplate = aclLoggingKeyPrefix + ".%03d";
// Deprecated option: Remove when canary, must-gather, and SRE are configured via ManagedKafka CR
if (aclConfig.allowedListeners != null) {
config.put(allowedListenersKey, aclConfig.allowedListeners);
}
if (aclConfig.getLoggingSuppressionWindow() != null) {
String key = aclLoggingKeyPrefix + ".suppressionWindow";
if (aclConfig.getLoggingSuppressionWindow().getDuration() != null) {
config.put(key + ".duration", aclConfig.getLoggingSuppressionWindow().getDuration());
}
if (aclConfig.getLoggingSuppressionWindow().getApis() != null) {
config.put(key + ".apis", aclConfig.getLoggingSuppressionWindow().getApis());
}
if (aclConfig.getLoggingSuppressionWindow().getEventCount() != null) {
config.put(key + ".eventCount", aclConfig.getLoggingSuppressionWindow().getEventCount());
}
}
addAcl(aclConfig.getGlobal(), "", aclKeyTemplate, aclCount, config);
addAcl(aclConfig.getLogging(), "", aclLoggingKeyTemplate, aclLoggingCount, config);
config.put(resourceOperationsKey, aclConfig.getResourceOperations());
for (String owner : owners) {
addAcl(aclConfig.getOwner(), owner, aclKeyTemplate, aclCount, config);
}
Objects.requireNonNullElse(managedKafka.getSpec().getServiceAccounts(), Collections.<ServiceAccount>emptyList()).stream().forEach(account -> {
String aclKey = String.format(SERVICE_ACCOUNT_KEY, account.getName());
applicationConfig.getOptionalValue(aclKey, String.class).ifPresent(acl -> addAcl(acl, account.getPrincipal(), aclKeyTemplate, aclCount, config));
});
}
Aggregations