56
56
import io .strimzi .api .kafka .model .kafka .Kafka ;
57
57
import io .strimzi .api .kafka .model .kafka .KafkaAuthorization ;
58
58
import io .strimzi .api .kafka .model .kafka .KafkaAuthorizationKeycloak ;
59
+ import io .strimzi .api .kafka .model .kafka .KafkaAuthorizationOpa ;
59
60
import io .strimzi .api .kafka .model .kafka .KafkaClusterSpec ;
60
61
import io .strimzi .api .kafka .model .kafka .KafkaClusterTemplate ;
61
62
import io .strimzi .api .kafka .model .kafka .KafkaResources ;
64
65
import io .strimzi .api .kafka .model .kafka .cruisecontrol .CruiseControlResources ;
65
66
import io .strimzi .api .kafka .model .kafka .exporter .KafkaExporterResources ;
66
67
import io .strimzi .api .kafka .model .kafka .listener .GenericKafkaListener ;
68
+ import io .strimzi .api .kafka .model .kafka .listener .KafkaListenerAuthentication ;
67
69
import io .strimzi .api .kafka .model .kafka .listener .KafkaListenerAuthenticationCustom ;
68
70
import io .strimzi .api .kafka .model .kafka .listener .KafkaListenerAuthenticationOAuth ;
71
+ import io .strimzi .api .kafka .model .kafka .listener .KafkaListenerAuthenticationTls ;
69
72
import io .strimzi .api .kafka .model .kafka .listener .KafkaListenerType ;
70
73
import io .strimzi .api .kafka .model .kafka .quotas .QuotasPlugin ;
71
74
import io .strimzi .api .kafka .model .kafka .quotas .QuotasPluginStrimzi ;
100
103
import java .util .ArrayList ;
101
104
import java .util .Collections ;
102
105
import java .util .HashMap ;
106
+ import java .util .HashSet ;
103
107
import java .util .LinkedHashSet ;
104
108
import java .util .List ;
105
109
import java .util .Map ;
@@ -145,8 +149,6 @@ public class KafkaCluster extends AbstractModel implements SupportsMetrics, Supp
145
149
146
150
protected static final String ENV_VAR_KAFKA_INIT_EXTERNAL_ADDRESS = "EXTERNAL_ADDRESS" ;
147
151
private static final String ENV_VAR_KAFKA_JMX_EXPORTER_ENABLED = "KAFKA_JMX_EXPORTER_ENABLED" ;
148
- private static final String ENV_VAR_STRIMZI_OPA_AUTHZ_TRUSTED_CERTS = "STRIMZI_OPA_AUTHZ_TRUSTED_CERTS" ;
149
- private static final String ENV_VAR_STRIMZI_KEYCLOAK_AUTHZ_TRUSTED_CERTS = "STRIMZI_KEYCLOAK_AUTHZ_TRUSTED_CERTS" ;
150
152
private static final String ENV_VAR_KAFKA_CLUSTER_NAME = "KAFKA_CLUSTER_NAME" ;
151
153
152
154
// For port names in services, a 'tcp-' prefix is added to support Istio protocol selection
@@ -1479,7 +1481,7 @@ private List<VolumeMount> getVolumeMounts(Storage storage, ContainerTemplate con
1479
1481
volumeMountList .add (VolumeUtils .createVolumeMount ("custom-" + identifier + "-certs" , "/opt/kafka/certificates/custom-" + identifier + "-certs" ));
1480
1482
}
1481
1483
1482
- if (ListenersUtils .isListenerWithOAuth (listener )) {
1484
+ if (ListenersUtils .isListenerWithOAuth (listener ) && listener . getAuth () instanceof KafkaListenerAuthenticationOAuth oauth && oauth . getTlsTrustedCertificates () != null ) {
1483
1485
String oauthTrustedCertsSecret = KafkaResources .internalOauthTrustedCertsSecretName (cluster );
1484
1486
volumeMountList .add (VolumeUtils .createVolumeMount (oauthTrustedCertsSecret , TRUSTED_CERTS_BASE_VOLUME_MOUNT + "/" + oauthTrustedCertsSecret ));
1485
1487
}
@@ -1678,23 +1680,40 @@ public ClusterRoleBinding generateClusterRoleBinding(String assemblyNamespace) {
1678
1680
**
1679
1681
* @return role for the Kafka Cluster
1680
1682
*/
1683
+ @ SuppressWarnings ("deprecation" ) // OPA Authorization is deprecated
1681
1684
public Role generateRole () {
1682
- List <String > certSecretNames = new ArrayList <>();
1685
+ Set <String > certSecretNames = new HashSet <>();
1683
1686
certSecretNames .add (KafkaResources .clusterCaCertificateSecretName (cluster ));
1684
- certSecretNames .add (KafkaResources .clientsCaCertificateSecretName (cluster ));
1685
- certSecretNames .add (KafkaResources .internalAuthzTrustedCertsSecretName (cluster ));
1686
- certSecretNames .add (KafkaResources .internalOauthTrustedCertsSecretName (cluster ));
1687
1687
certSecretNames .addAll (nodes ().stream ().map (NodeRef ::podName ).toList ());
1688
1688
1689
+ for (GenericKafkaListener listener : listeners ) {
1690
+ if (listener .isTls ()) {
1691
+ if (listener .getConfiguration () != null ) {
1692
+ certSecretNames .add (listener .getConfiguration ().getBrokerCertChainAndKey ().getSecretName ());
1693
+ }
1694
+ }
1695
+
1696
+ KafkaListenerAuthentication auth = listener .getAuth ();
1697
+ if (auth instanceof KafkaListenerAuthenticationOAuth ) {
1698
+ certSecretNames .add (KafkaResources .internalOauthTrustedCertsSecretName (cluster ));
1699
+ } else if (auth instanceof KafkaListenerAuthenticationTls ) {
1700
+ certSecretNames .add (KafkaResources .clientsCaCertificateSecretName (cluster ));
1701
+ }
1702
+ }
1703
+
1704
+ if ((authorization instanceof KafkaAuthorizationOpa opa && opa .getTlsTrustedCertificates () != null && !opa .getTlsTrustedCertificates ().isEmpty ())
1705
+ || (authorization instanceof KafkaAuthorizationKeycloak kc && kc .getTlsTrustedCertificates () != null && !kc .getTlsTrustedCertificates ().isEmpty ())) {
1706
+ certSecretNames .add (KafkaResources .internalAuthzTrustedCertsSecretName (cluster ));
1707
+ }
1708
+
1689
1709
List <PolicyRule > rules = List .of (new PolicyRuleBuilder ()
1690
1710
.withApiGroups ("" )
1691
1711
.withResources ("secrets" )
1692
1712
.withVerbs ("get" )
1693
- .withResourceNames (certSecretNames )
1713
+ .withResourceNames (certSecretNames . stream (). toList () )
1694
1714
.build ());
1695
1715
1696
- Role role = RbacUtils .createRole (componentName , namespace , rules , labels , ownerReference , null );
1697
- return role ;
1716
+ return RbacUtils .createRole (componentName , namespace , rules , labels , ownerReference , null );
1698
1717
}
1699
1718
1700
1719
/**
@@ -1715,10 +1734,8 @@ public RoleBinding generateRoleBindingForRole() {
1715
1734
.withKind ("Role" )
1716
1735
.build ();
1717
1736
1718
- RoleBinding rb = RbacUtils
1737
+ return RbacUtils
1719
1738
.createRoleBinding (KafkaResources .kafkaRoleBindingName (cluster ), namespace , roleRef , List .of (subject ), labels , ownerReference , null );
1720
-
1721
- return rb ;
1722
1739
}
1723
1740
1724
1741
/**
0 commit comments