@@ -13,7 +13,7 @@ use crate::crd::{
1313 AirflowAuthenticationClassResolved , AirflowClientAuthenticationDetailsResolved ,
1414 DEFAULT_OIDC_PROVIDER , FlaskRolesSyncMoment ,
1515 } ,
16- authorization:: { AirflowAuthorizationResolved , OpaConfigResolved } ,
16+ authorization:: AirflowAuthorizationResolved ,
1717} ;
1818
1919pub const PYTHON_IMPORTS : & [ & str ] = & [
@@ -41,6 +41,7 @@ pub fn add_airflow_config(
4141 config : & mut BTreeMap < String , String > ,
4242 authentication_config : & AirflowClientAuthenticationDetailsResolved ,
4343 authorization_config : & AirflowAuthorizationResolved ,
44+ product_version : & str ,
4445) -> Result < ( ) > {
4546 if !config. contains_key ( & * AirflowConfigOptions :: AuthType . to_string ( ) ) {
4647 config. insert (
@@ -51,7 +52,7 @@ pub fn add_airflow_config(
5152 }
5253
5354 append_authentication_config ( config, authentication_config) ?;
54- append_authorization_config ( config, authorization_config) ? ;
55+ append_authorization_config ( config, authorization_config, product_version ) ;
5556
5657 Ok ( ( ) )
5758}
@@ -275,32 +276,30 @@ fn append_oidc_config(
275276fn append_authorization_config (
276277 config : & mut BTreeMap < String , String > ,
277278 authorization_config : & AirflowAuthorizationResolved ,
278- ) -> Result < ( ) , Error > {
279- if let Some ( opa_config) = & authorization_config. opa {
280- append_opa_config ( config, opa_config) ?;
279+ product_version : & str ,
280+ ) {
281+ // See `env_vars::authorization_env_vars` for why we only care about Airflow 2
282+ if !product_version. starts_with ( "2." ) {
283+ return ;
281284 }
285+ let Some ( opa_config) = & authorization_config. opa else {
286+ return ;
287+ } ;
282288
283- Ok ( ( ) )
284- }
285-
286- fn append_opa_config (
287- config : & mut BTreeMap < String , String > ,
288- opa_config : & OpaConfigResolved ,
289- ) -> Result < ( ) , Error > {
290- config. insert (
291- AirflowConfigOptions :: AuthOpaRequestUrl . to_string ( ) ,
292- opa_config. connection_string . to_owned ( ) ,
293- ) ;
294- config. insert (
295- AirflowConfigOptions :: AuthOpaCacheTtlInSec . to_string ( ) ,
296- opa_config. cache_entry_time_to_live . as_secs ( ) . to_string ( ) ,
297- ) ;
298- config. insert (
299- AirflowConfigOptions :: AuthOpaCacheMaxsize . to_string ( ) ,
300- opa_config. cache_max_entries . to_string ( ) ,
301- ) ;
302-
303- Ok ( ( ) )
289+ config. extend ( [
290+ (
291+ AirflowConfigOptions :: AuthOpaRequestUrl . to_string ( ) ,
292+ opa_config. connection_string . to_owned ( ) ,
293+ ) ,
294+ (
295+ AirflowConfigOptions :: AuthOpaCacheTtlInSec . to_string ( ) ,
296+ opa_config. cache_entry_time_to_live . as_secs ( ) . to_string ( ) ,
297+ ) ,
298+ (
299+ AirflowConfigOptions :: AuthOpaCacheMaxsize . to_string ( ) ,
300+ opa_config. cache_max_entries . to_string ( ) ,
301+ ) ,
302+ ] ) ;
304303}
305304
306305#[ cfg( test) ]
@@ -309,10 +308,7 @@ mod tests {
309308
310309 use indoc:: formatdoc;
311310 use rstest:: rstest;
312- use stackable_operator:: {
313- crd:: authentication:: { ldap, oidc} ,
314- time:: Duration ,
315- } ;
311+ use stackable_operator:: crd:: authentication:: { ldap, oidc} ;
316312
317313 use crate :: {
318314 config:: add_airflow_config,
@@ -321,10 +317,12 @@ mod tests {
321317 AirflowAuthenticationClassResolved , AirflowClientAuthenticationDetailsResolved ,
322318 FlaskRolesSyncMoment , default_user_registration,
323319 } ,
324- authorization:: { AirflowAuthorizationResolved , OpaConfigResolved } ,
320+ authorization:: AirflowAuthorizationResolved ,
325321 } ,
326322 } ;
327323
324+ const TEST_AIRFLOW_VERSION : & str = "3.0.1" ;
325+
328326 #[ test]
329327 fn test_auth_db_config ( ) {
330328 let authentication_config = AirflowClientAuthenticationDetailsResolved {
@@ -337,7 +335,13 @@ mod tests {
337335 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
338336
339337 let mut result = BTreeMap :: new ( ) ;
340- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
338+ add_airflow_config (
339+ & mut result,
340+ & authentication_config,
341+ & authorization_config,
342+ TEST_AIRFLOW_VERSION ,
343+ )
344+ . expect ( "Ok" ) ;
341345
342346 assert_eq ! (
343347 BTreeMap :: from( [
@@ -382,7 +386,13 @@ mod tests {
382386 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
383387
384388 let mut result = BTreeMap :: new ( ) ;
385- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
389+ add_airflow_config (
390+ & mut result,
391+ & authentication_config,
392+ & authorization_config,
393+ TEST_AIRFLOW_VERSION ,
394+ )
395+ . expect ( "Ok" ) ;
386396
387397 assert_eq ! ( BTreeMap :: from( [
388398 ( "AUTH_LDAP_ALLOW_SELF_SIGNED" . into( ) , "false" . into( ) ) ,
@@ -468,7 +478,13 @@ mod tests {
468478 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
469479
470480 let mut result = BTreeMap :: new ( ) ;
471- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
481+ add_airflow_config (
482+ & mut result,
483+ & authentication_config,
484+ & authorization_config,
485+ TEST_AIRFLOW_VERSION ,
486+ )
487+ . expect ( "Ok" ) ;
472488
473489 assert_eq ! (
474490 BTreeMap :: from( [
@@ -513,41 +529,4 @@ mod tests {
513529 result
514530 ) ;
515531 }
516-
517- #[ test]
518- fn test_opa_config ( ) {
519- let authentication_config = AirflowClientAuthenticationDetailsResolved {
520- authentication_classes_resolved : vec ! [ ] ,
521- user_registration : true ,
522- user_registration_role : "User" . to_string ( ) ,
523- sync_roles_at : FlaskRolesSyncMoment :: Registration ,
524- } ;
525-
526- let authorization_config = AirflowAuthorizationResolved {
527- opa : Some ( OpaConfigResolved {
528- connection_string : "http://opa:8081/v1/data/airflow" . to_string ( ) ,
529- cache_entry_time_to_live : Duration :: from_secs ( 30 ) ,
530- cache_max_entries : 1000 ,
531- } ) ,
532- } ;
533-
534- let mut result = BTreeMap :: new ( ) ;
535- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
536-
537- assert_eq ! (
538- BTreeMap :: from( [
539- ( "AUTH_OPA_CACHE_MAXSIZE" . into( ) , "1000" . into( ) ) ,
540- ( "AUTH_OPA_CACHE_TTL_IN_SEC" . into( ) , "30" . into( ) ) ,
541- (
542- "AUTH_OPA_REQUEST_URL" . into( ) ,
543- "http://opa:8081/v1/data/airflow" . into( )
544- ) ,
545- ( "AUTH_ROLES_SYNC_AT_LOGIN" . into( ) , "false" . into( ) ) ,
546- ( "AUTH_TYPE" . into( ) , "AUTH_DB" . into( ) ) ,
547- ( "AUTH_USER_REGISTRATION" . into( ) , "true" . into( ) ) ,
548- ( "AUTH_USER_REGISTRATION_ROLE" . into( ) , "User" . into( ) )
549- ] ) ,
550- result
551- ) ;
552- }
553532}
0 commit comments