@@ -3,7 +3,6 @@ use std::{
33 collections:: { BTreeMap , HashMap } ,
44 convert:: Infallible ,
55 num:: ParseIntError ,
6- ops:: Div ,
76 str:: FromStr ,
87 sync:: Arc ,
98} ;
@@ -86,10 +85,9 @@ use crate::{
8685 v1alpha1, Container , TrinoRole , ACCESS_CONTROL_PROPERTIES , APP_NAME , CONFIG_DIR_NAME ,
8786 CONFIG_PROPERTIES , DATA_DIR_NAME , DISCOVERY_URI , ENV_INTERNAL_SECRET , HTTPS_PORT ,
8887 HTTPS_PORT_NAME , HTTP_PORT , HTTP_PORT_NAME , JVM_CONFIG , JVM_SECURITY_PROPERTIES ,
89- LOG_COMPRESSION , LOG_FORMAT , LOG_MAX_SIZE , LOG_MAX_TOTAL_SIZE , LOG_PATH , LOG_PROPERTIES ,
90- METRICS_PORT , METRICS_PORT_NAME , NODE_PROPERTIES , RW_CONFIG_DIR_NAME ,
91- STACKABLE_CLIENT_TLS_DIR , STACKABLE_INTERNAL_TLS_DIR , STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
92- STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR ,
88+ LOG_PROPERTIES , MAX_TRINO_LOG_FILES_SIZE , METRICS_PORT , METRICS_PORT_NAME , NODE_PROPERTIES ,
89+ RW_CONFIG_DIR_NAME , STACKABLE_CLIENT_TLS_DIR , STACKABLE_INTERNAL_TLS_DIR ,
90+ STACKABLE_MOUNT_INTERNAL_TLS_DIR , STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR ,
9391 } ,
9492 operations:: {
9593 add_graceful_shutdown_config, graceful_shutdown_config_properties, pdb:: add_pdbs,
@@ -110,11 +108,6 @@ pub const TRINO_UID: i64 = 1000;
110108pub const STACKABLE_LOG_DIR : & str = "/stackable/log" ;
111109pub const STACKABLE_LOG_CONFIG_DIR : & str = "/stackable/log_config" ;
112110
113- const LOG_FILE_COUNT : u32 = 2 ;
114- pub const MAX_TRINO_LOG_FILES_SIZE : MemoryQuantity = MemoryQuantity {
115- value : 10.0 ,
116- unit : BinaryMultiple :: Mebi ,
117- } ;
118111pub const MAX_PREPARE_LOG_FILE_SIZE : MemoryQuantity = MemoryQuantity {
119112 value : 1.0 ,
120113 unit : BinaryMultiple :: Mebi ,
@@ -663,7 +656,7 @@ fn build_rolegroup_config_map(
663656 . next ( )
664657 . context ( MissingCoordinatorPodsSnafu ) ?;
665658
666- // Add additional config files fore authentication
659+ // Add additional config files for authentication
667660 cm_conf_data. extend ( trino_authentication_config. config_files ( trino_role) ) ;
668661
669662 for ( property_name_kind, config) in config {
@@ -703,45 +696,6 @@ fn build_rolegroup_config_map(
703696 dynamic_resolved_config
704697 . extend ( graceful_shutdown_config_properties ( trino, trino_role) ) ;
705698
706- // The log format used by Trino
707- dynamic_resolved_config. insert ( LOG_FORMAT . to_string ( ) , Some ( "json" . to_string ( ) ) ) ;
708- // The path to the log file used by Trino
709- dynamic_resolved_config. insert (
710- LOG_PATH . to_string ( ) ,
711- Some ( format ! (
712- "{STACKABLE_LOG_DIR}/{container}/server.airlift.json" ,
713- container = Container :: Trino
714- ) ) ,
715- ) ;
716- // We do not compress. This will result in LOG_MAX_TOTAL_SIZE / LOG_MAX_SIZE files.
717- dynamic_resolved_config
718- . insert ( LOG_COMPRESSION . to_string ( ) , Some ( "none" . to_string ( ) ) ) ;
719- // The size of one log file
720- dynamic_resolved_config. insert (
721- LOG_MAX_SIZE . to_string ( ) ,
722- Some ( format ! (
723- // Trino uses the unit "MB" for MiB.
724- "{}MB" ,
725- MAX_TRINO_LOG_FILES_SIZE
726- . scale_to( BinaryMultiple :: Mebi )
727- . div( LOG_FILE_COUNT as f32 )
728- . ceil( )
729- . value,
730- ) ) ,
731- ) ;
732- // The maximum size of all logfiles combined
733- dynamic_resolved_config. insert (
734- LOG_MAX_TOTAL_SIZE . to_string ( ) ,
735- Some ( format ! (
736- // Trino uses the unit "MB" for MiB.
737- "{}MB" ,
738- MAX_TRINO_LOG_FILES_SIZE
739- . scale_to( BinaryMultiple :: Mebi )
740- . ceil( )
741- . value,
742- ) ) ,
743- ) ;
744-
745699 // Add static properties and overrides
746700 dynamic_resolved_config. extend ( transformed_config) ;
747701
@@ -784,19 +738,29 @@ fn build_rolegroup_config_map(
784738 ) ;
785739 }
786740 }
741+ PropertyNameKind :: File ( file_name) if file_name == ACCESS_CONTROL_PROPERTIES => {
742+ if let Some ( trino_opa_config) = trino_opa_config {
743+ dynamic_resolved_config. extend ( trino_opa_config. as_config ( ) ) ;
744+ }
745+
746+ // Add static properties and overrides
747+ dynamic_resolved_config. extend ( transformed_config) ;
748+
749+ if !dynamic_resolved_config. is_empty ( ) {
750+ let access_control_properties =
751+ product_config:: writer:: to_java_properties_string (
752+ dynamic_resolved_config. iter ( ) ,
753+ )
754+ . context ( FailedToWriteJavaPropertiesSnafu ) ?;
755+
756+ cm_conf_data. insert ( file_name. to_string ( ) , access_control_properties) ;
757+ }
758+ }
787759 PropertyNameKind :: File ( file_name) if file_name == JVM_CONFIG => { }
788760 _ => { }
789761 }
790762 }
791763
792- if let Some ( trino_opa_config) = trino_opa_config {
793- let config = trino_opa_config. as_config ( ) ;
794- let config_properties = product_config:: writer:: to_java_properties_string ( config. iter ( ) )
795- . context ( FailedToWriteJavaPropertiesSnafu ) ?;
796-
797- cm_conf_data. insert ( ACCESS_CONTROL_PROPERTIES . to_string ( ) , config_properties) ;
798- }
799-
800764 cm_conf_data. insert ( JVM_CONFIG . to_string ( ) , jvm_config. to_string ( ) ) ;
801765
802766 let jvm_sec_props: BTreeMap < String , Option < String > > = config
@@ -1333,6 +1297,7 @@ fn validated_product_config(
13331297 PropertyNameKind :: File ( JVM_CONFIG . to_string( ) ) ,
13341298 PropertyNameKind :: File ( LOG_PROPERTIES . to_string( ) ) ,
13351299 PropertyNameKind :: File ( JVM_SECURITY_PROPERTIES . to_string( ) ) ,
1300+ PropertyNameKind :: File ( ACCESS_CONTROL_PROPERTIES . to_string( ) ) ,
13361301 ] ;
13371302
13381303 roles. insert (
@@ -1740,6 +1705,7 @@ mod tests {
17401705 assert ! ( cm. contains_key( "security.properties" ) ) ;
17411706 assert ! ( cm. contains_key( "node.properties" ) ) ;
17421707 assert ! ( cm. contains_key( "log.properties" ) ) ;
1708+ assert ! ( cm. contains_key( "access-control.properties" ) ) ;
17431709 }
17441710
17451711 fn build_config_map ( trino_yaml : & str ) -> ConfigMap {
@@ -1761,6 +1727,7 @@ mod tests {
17611727 PropertyNameKind :: File ( JVM_CONFIG . to_string( ) ) ,
17621728 PropertyNameKind :: File ( LOG_PROPERTIES . to_string( ) ) ,
17631729 PropertyNameKind :: File ( JVM_SECURITY_PROPERTIES . to_string( ) ) ,
1730+ PropertyNameKind :: File ( ACCESS_CONTROL_PROPERTIES . to_string( ) ) ,
17641731 ] ;
17651732 let validated_config = validate_all_roles_and_groups_config (
17661733 // The Trino version is a single number like 396.
@@ -1807,6 +1774,23 @@ mod tests {
18071774 TrinoAuthenticationTypes :: try_from ( Vec :: new ( ) ) . unwrap ( ) ,
18081775 )
18091776 . unwrap ( ) ;
1777+ let trino_opa_config = Some ( TrinoOpaConfig {
1778+ non_batched_connection_string :
1779+ "http://simple-opa.default.svc.cluster.local:8081/v1/data/my-product/allow"
1780+ . to_string ( ) ,
1781+ batched_connection_string :
1782+ "http://simple-opa.default.svc.cluster.local:8081/v1/data/my-product/batch"
1783+ . to_string ( ) ,
1784+ row_filters_connection_string : Some (
1785+ "http://simple-opa.default.svc.cluster.local:8081/v1/data/my-product/rowFilters"
1786+ . to_string ( ) ,
1787+ ) ,
1788+ column_masking_connection_string : Some (
1789+ "http://simple-opa.default.svc.cluster.local:8081/v1/data/my-product/columnMask"
1790+ . to_string ( ) ,
1791+ ) ,
1792+ allow_permission_management_operations : true ,
1793+ } ) ;
18101794 let merged_config = trino
18111795 . merged_config ( & trino_role, & rolegroup_ref, & [ ] )
18121796 . unwrap ( ) ;
@@ -1824,13 +1808,65 @@ mod tests {
18241808 . unwrap ( ) ,
18251809 & merged_config,
18261810 & trino_authentication_config,
1827- & None ,
1811+ & trino_opa_config ,
18281812 None ,
18291813 & cluster_info,
18301814 )
18311815 . unwrap ( )
18321816 }
18331817
1818+ #[ test]
1819+ fn test_access_control_overrides ( ) {
1820+ let trino_yaml = r#"
1821+ apiVersion: trino.stackable.tech/v1alpha1
1822+ kind: TrinoCluster
1823+ metadata:
1824+ name: trino
1825+ spec:
1826+ image:
1827+ productVersion: "470"
1828+ clusterConfig:
1829+ catalogLabelSelector:
1830+ matchLabels:
1831+ trino: simple-trino
1832+ authorization:
1833+ opa:
1834+ configMapName: simple-opa
1835+ package: my-product
1836+ coordinators:
1837+ configOverrides:
1838+ access-control.properties:
1839+ hello-from-role: "true" # only defined here at role level
1840+ foo.bar: "false" # overriden by role group below
1841+ opa.allow-permission-management-operations: "false" # override value from config
1842+ roleGroups:
1843+ default:
1844+ configOverrides:
1845+ access-control.properties:
1846+ hello-from-role-group: "true" # only defined here at group level
1847+ foo.bar: "true" # overrides role value
1848+ opa.policy.batched-uri: "http://simple-opa.default.svc.cluster.local:8081/v1/data/my-product/batch-new" # override value from config
1849+ replicas: 1
1850+ workers:
1851+ roleGroups:
1852+ default:
1853+ replicas: 1
1854+ "# ;
1855+
1856+ let cm = build_config_map ( trino_yaml) . data . unwrap ( ) ;
1857+ let access_control_config = cm. get ( "access-control.properties" ) . unwrap ( ) ;
1858+
1859+ assert ! ( access_control_config. contains( "access-control.name=opa" ) ) ;
1860+ assert ! ( access_control_config. contains( "hello-from-role=true" ) ) ;
1861+ assert ! ( access_control_config. contains( "hello-from-role-group=true" ) ) ;
1862+ assert ! ( access_control_config. contains( "foo.bar=true" ) ) ;
1863+ assert ! ( access_control_config. contains( "opa.allow-permission-management-operations=false" ) ) ;
1864+ assert ! ( access_control_config. contains( r#"opa.policy.batched-uri=http\://simple-opa.default.svc.cluster.local\:8081/v1/data/my-product/batch-new"# ) ) ;
1865+ assert ! ( access_control_config. contains( r#"opa.policy.column-masking-uri=http\://simple-opa.default.svc.cluster.local\:8081/v1/data/my-product/columnMask"# ) ) ;
1866+ assert ! ( access_control_config. contains( r#"opa.policy.row-filters-uri=http\://simple-opa.default.svc.cluster.local\:8081/v1/data/my-product/rowFilters"# ) ) ;
1867+ assert ! ( access_control_config. contains( r#"opa.policy.uri=http\://simple-opa.default.svc.cluster.local\:8081/v1/data/my-product/allow"# ) ) ;
1868+ }
1869+
18341870 #[ test]
18351871 fn test_env_overrides ( ) {
18361872 let trino_yaml = r#"
0 commit comments