@@ -24,7 +24,10 @@ use stackable_operator::{
2424 container:: ContainerBuilder ,
2525 resources:: ResourceRequirementsBuilder ,
2626 security:: PodSecurityContextBuilder ,
27- volume:: { ListenerOperatorVolumeSourceBuilderError , SecretFormat } ,
27+ volume:: {
28+ ListenerOperatorVolumeSourceBuilderError , SecretFormat ,
29+ SecretOperatorVolumeSourceBuilder , VolumeBuilder ,
30+ } ,
2831 } ,
2932 } ,
3033 client:: Client ,
@@ -106,7 +109,7 @@ use crate::{
106109 AUTHORIZERS_XML_FILE_NAME , LOGIN_IDENTITY_PROVIDERS_XML_FILE_NAME ,
107110 NifiAuthenticationConfig , STACKABLE_SERVER_TLS_DIR , STACKABLE_TLS_STORE_PASSWORD ,
108111 } ,
109- authorization:: NifiAuthorizationConfig ,
112+ authorization:: { NifiAuthorizationConfig , OPA_TLS_MOUNT_PATH , OPA_TLS_VOLUME_NAME } ,
110113 build_tls_volume, check_or_generate_oidc_admin_password, check_or_generate_sensitive_key,
111114 tls:: { KEYSTORE_NIFI_CONTAINER_MOUNT , KEYSTORE_VOLUME_NAME , TRUSTSTORE_VOLUME_NAME } ,
112115 } ,
@@ -343,6 +346,12 @@ pub enum Error {
343346 BuildListenerVolume {
344347 source : ListenerOperatorVolumeSourceBuilderError ,
345348 } ,
349+
350+ #[ snafu( display( "failed to build OPA TLS certificate volume" ) ) ]
351+ OpaTlsCertSecretClassVolumeBuild {
352+ source : stackable_operator:: builder:: pod:: volume:: SecretOperatorVolumeSourceBuilderError ,
353+ } ,
354+
346355 #[ snafu( display( "failed to apply group listener" ) ) ]
347356 ApplyGroupListener {
348357 source : stackable_operator:: cluster_resources:: Error ,
@@ -455,8 +464,16 @@ pub async fn reconcile_nifi(
455464 . context ( SecuritySnafu ) ?;
456465 }
457466
458- let authorization_config =
459- NifiAuthorizationConfig :: from ( & nifi. spec . cluster_config . authorization ) ;
467+ let authorization_config = NifiAuthorizationConfig :: from (
468+ & nifi. spec . cluster_config . authorization ,
469+ client,
470+ nifi. metadata
471+ . namespace
472+ . as_deref ( )
473+ . context ( ObjectHasNoNamespaceSnafu ) ?,
474+ )
475+ . await
476+ . context ( InvalidNifiAuthorizationConfigSnafu ) ?;
460477
461478 let ( rbac_sa, rbac_rolebinding) = build_rbac_resources (
462479 nifi,
@@ -770,6 +787,7 @@ async fn build_node_rolegroup_config_map(
770787 . clone ( ) ,
771788 role,
772789 & rolegroup. role_group ,
790+ Some ( authorization_config) ,
773791 )
774792 . context ( BootstrapConfigSnafu ) ?,
775793 )
@@ -978,6 +996,14 @@ async fn build_node_rolegroup_statefulset(
978996 . as_slice ( ) ,
979997 ) ;
980998
999+ // Add OPA certificate to truststore if OPA TLS is enabled
1000+ if authorization_config. has_opa_tls ( ) {
1001+ prepare_args. extend ( vec ! [
1002+ "echo Importing OPA CA certificate to truststore" . to_string( ) ,
1003+ format!( "keytool -importcert -file {OPA_TLS_MOUNT_PATH}/ca.crt -keystore {STACKABLE_SERVER_TLS_DIR}/truststore.p12 -storepass {STACKABLE_TLS_STORE_PASSWORD} -alias opa-ca -noprompt" ) ,
1004+ ] ) ;
1005+ }
1006+
9811007 prepare_args. extend ( vec ! [
9821008 "export LISTENER_DEFAULT_ADDRESS=$(cat /stackable/listener/default-address/address)"
9831009 . to_string( ) ,
@@ -1051,15 +1077,22 @@ async fn build_node_rolegroup_statefulset(
10511077 . add_volume_mount ( TRUSTSTORE_VOLUME_NAME , STACKABLE_SERVER_TLS_DIR )
10521078 . context ( AddVolumeMountSnafu ) ?
10531079 . add_volume_mount ( LISTENER_VOLUME_NAME , LISTENER_VOLUME_DIR )
1054- . context ( AddVolumeMountSnafu ) ?
1055- . resources (
1056- ResourceRequirementsBuilder :: new ( )
1057- . with_cpu_request ( "500m" )
1058- . with_cpu_limit ( "2000m" )
1059- . with_memory_request ( "4096Mi" )
1060- . with_memory_limit ( "4096Mi" )
1061- . build ( ) ,
1062- ) ;
1080+ . context ( AddVolumeMountSnafu ) ?;
1081+
1082+ if authorization_config. has_opa_tls ( ) {
1083+ container_prepare
1084+ . add_volume_mount ( OPA_TLS_VOLUME_NAME , OPA_TLS_MOUNT_PATH )
1085+ . context ( AddVolumeMountSnafu ) ?;
1086+ }
1087+
1088+ container_prepare. resources (
1089+ ResourceRequirementsBuilder :: new ( )
1090+ . with_cpu_request ( "500m" )
1091+ . with_cpu_limit ( "2000m" )
1092+ . with_memory_request ( "4096Mi" )
1093+ . with_memory_limit ( "4096Mi" )
1094+ . build ( ) ,
1095+ ) ;
10631096
10641097 let nifi_container_name = Container :: Nifi . to_string ( ) ;
10651098 let mut container_nifi_builder =
@@ -1083,6 +1116,13 @@ async fn build_node_rolegroup_statefulset(
10831116 create_vector_shutdown_file_command =
10841117 create_vector_shutdown_file_command( STACKABLE_LOG_DIR ) ,
10851118 } ] ;
1119+
1120+ if authorization_config. has_opa_tls ( ) {
1121+ container_nifi_builder
1122+ . add_volume_mount ( OPA_TLS_VOLUME_NAME , OPA_TLS_MOUNT_PATH )
1123+ . context ( AddVolumeMountSnafu ) ?;
1124+ }
1125+
10861126 let container_nifi = container_nifi_builder
10871127 . image_from_product_image ( resolved_product_image)
10881128 . command ( vec ! [
@@ -1366,7 +1406,22 @@ async fn build_node_rolegroup_statefulset(
13661406 )
13671407 . context ( AddVolumeSnafu ) ?
13681408 . add_empty_dir_volume ( TRUSTSTORE_VOLUME_NAME , None )
1369- . context ( AddVolumeSnafu ) ?
1409+ . context ( AddVolumeSnafu ) ?;
1410+
1411+ if let NifiAuthorizationConfig :: Opa { secret_class : Some ( secret_class) , .. } = authorization_config
1412+ {
1413+ pod_builder
1414+ . add_volume ( VolumeBuilder :: new ( OPA_TLS_VOLUME_NAME )
1415+ . ephemeral (
1416+ SecretOperatorVolumeSourceBuilder :: new ( secret_class)
1417+ . build ( )
1418+ . context ( OpaTlsCertSecretClassVolumeBuildSnafu ) ?,
1419+ )
1420+ . build ( ) )
1421+ . context ( AddVolumeSnafu ) ?;
1422+ }
1423+
1424+ pod_builder
13701425 . add_volume ( Volume {
13711426 name : "sensitiveproperty" . to_string ( ) ,
13721427 secret : Some ( SecretVolumeSource {
0 commit comments