@@ -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) ]
@@ -325,6 +324,8 @@ mod tests {
325324 } ,
326325 } ;
327326
327+ const TEST_AIRFLOW_VERSION : & str = "3.0.1" ;
328+
328329 #[ test]
329330 fn test_auth_db_config ( ) {
330331 let authentication_config = AirflowClientAuthenticationDetailsResolved {
@@ -337,7 +338,13 @@ mod tests {
337338 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
338339
339340 let mut result = BTreeMap :: new ( ) ;
340- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
341+ add_airflow_config (
342+ & mut result,
343+ & authentication_config,
344+ & authorization_config,
345+ TEST_AIRFLOW_VERSION ,
346+ )
347+ . expect ( "Ok" ) ;
341348
342349 assert_eq ! (
343350 BTreeMap :: from( [
@@ -382,7 +389,13 @@ mod tests {
382389 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
383390
384391 let mut result = BTreeMap :: new ( ) ;
385- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
392+ add_airflow_config (
393+ & mut result,
394+ & authentication_config,
395+ & authorization_config,
396+ TEST_AIRFLOW_VERSION ,
397+ )
398+ . expect ( "Ok" ) ;
386399
387400 assert_eq ! ( BTreeMap :: from( [
388401 ( "AUTH_LDAP_ALLOW_SELF_SIGNED" . into( ) , "false" . into( ) ) ,
@@ -468,7 +481,13 @@ mod tests {
468481 let authorization_config = AirflowAuthorizationResolved { opa : None } ;
469482
470483 let mut result = BTreeMap :: new ( ) ;
471- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
484+ add_airflow_config (
485+ & mut result,
486+ & authentication_config,
487+ & authorization_config,
488+ TEST_AIRFLOW_VERSION ,
489+ )
490+ . expect ( "Ok" ) ;
472491
473492 assert_eq ! (
474493 BTreeMap :: from( [
@@ -532,16 +551,16 @@ mod tests {
532551 } ;
533552
534553 let mut result = BTreeMap :: new ( ) ;
535- add_airflow_config ( & mut result, & authentication_config, & authorization_config) . expect ( "Ok" ) ;
554+ add_airflow_config (
555+ & mut result,
556+ & authentication_config,
557+ & authorization_config,
558+ TEST_AIRFLOW_VERSION ,
559+ )
560+ . expect ( "Ok" ) ;
536561
537562 assert_eq ! (
538563 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- ) ,
545564 ( "AUTH_ROLES_SYNC_AT_LOGIN" . into( ) , "false" . into( ) ) ,
546565 ( "AUTH_TYPE" . into( ) , "AUTH_DB" . into( ) ) ,
547566 ( "AUTH_USER_REGISTRATION" . into( ) , "true" . into( ) ) ,
0 commit comments