@@ -3,7 +3,6 @@ use std::{
3
3
collections:: { BTreeMap , HashMap } ,
4
4
convert:: Infallible ,
5
5
num:: ParseIntError ,
6
- ops:: Div ,
7
6
str:: FromStr ,
8
7
sync:: Arc ,
9
8
} ;
@@ -86,10 +85,9 @@ use crate::{
86
85
v1alpha1, Container , TrinoRole , ACCESS_CONTROL_PROPERTIES , APP_NAME , CONFIG_DIR_NAME ,
87
86
CONFIG_PROPERTIES , DATA_DIR_NAME , DISCOVERY_URI , ENV_INTERNAL_SECRET , HTTPS_PORT ,
88
87
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 ,
93
91
} ,
94
92
operations:: {
95
93
add_graceful_shutdown_config, graceful_shutdown_config_properties, pdb:: add_pdbs,
@@ -110,11 +108,6 @@ pub const TRINO_UID: i64 = 1000;
110
108
pub const STACKABLE_LOG_DIR : & str = "/stackable/log" ;
111
109
pub const STACKABLE_LOG_CONFIG_DIR : & str = "/stackable/log_config" ;
112
110
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
- } ;
118
111
pub const MAX_PREPARE_LOG_FILE_SIZE : MemoryQuantity = MemoryQuantity {
119
112
value : 1.0 ,
120
113
unit : BinaryMultiple :: Mebi ,
@@ -663,7 +656,7 @@ fn build_rolegroup_config_map(
663
656
. next ( )
664
657
. context ( MissingCoordinatorPodsSnafu ) ?;
665
658
666
- // Add additional config files fore authentication
659
+ // Add additional config files for authentication
667
660
cm_conf_data. extend ( trino_authentication_config. config_files ( trino_role) ) ;
668
661
669
662
for ( property_name_kind, config) in config {
@@ -703,45 +696,6 @@ fn build_rolegroup_config_map(
703
696
dynamic_resolved_config
704
697
. extend ( graceful_shutdown_config_properties ( trino, trino_role) ) ;
705
698
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
-
745
699
// Add static properties and overrides
746
700
dynamic_resolved_config. extend ( transformed_config) ;
747
701
@@ -784,19 +738,29 @@ fn build_rolegroup_config_map(
784
738
) ;
785
739
}
786
740
}
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
+ }
787
759
PropertyNameKind :: File ( file_name) if file_name == JVM_CONFIG => { }
788
760
_ => { }
789
761
}
790
762
}
791
763
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
-
800
764
cm_conf_data. insert ( JVM_CONFIG . to_string ( ) , jvm_config. to_string ( ) ) ;
801
765
802
766
let jvm_sec_props: BTreeMap < String , Option < String > > = config
@@ -1333,6 +1297,7 @@ fn validated_product_config(
1333
1297
PropertyNameKind :: File ( JVM_CONFIG . to_string( ) ) ,
1334
1298
PropertyNameKind :: File ( LOG_PROPERTIES . to_string( ) ) ,
1335
1299
PropertyNameKind :: File ( JVM_SECURITY_PROPERTIES . to_string( ) ) ,
1300
+ PropertyNameKind :: File ( ACCESS_CONTROL_PROPERTIES . to_string( ) ) ,
1336
1301
] ;
1337
1302
1338
1303
roles. insert (
@@ -1740,6 +1705,7 @@ mod tests {
1740
1705
assert ! ( cm. contains_key( "security.properties" ) ) ;
1741
1706
assert ! ( cm. contains_key( "node.properties" ) ) ;
1742
1707
assert ! ( cm. contains_key( "log.properties" ) ) ;
1708
+ assert ! ( cm. contains_key( "access-control.properties" ) ) ;
1743
1709
}
1744
1710
1745
1711
fn build_config_map ( trino_yaml : & str ) -> ConfigMap {
@@ -1761,6 +1727,7 @@ mod tests {
1761
1727
PropertyNameKind :: File ( JVM_CONFIG . to_string( ) ) ,
1762
1728
PropertyNameKind :: File ( LOG_PROPERTIES . to_string( ) ) ,
1763
1729
PropertyNameKind :: File ( JVM_SECURITY_PROPERTIES . to_string( ) ) ,
1730
+ PropertyNameKind :: File ( ACCESS_CONTROL_PROPERTIES . to_string( ) ) ,
1764
1731
] ;
1765
1732
let validated_config = validate_all_roles_and_groups_config (
1766
1733
// The Trino version is a single number like 396.
@@ -1807,6 +1774,23 @@ mod tests {
1807
1774
TrinoAuthenticationTypes :: try_from ( Vec :: new ( ) ) . unwrap ( ) ,
1808
1775
)
1809
1776
. 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
+ } ) ;
1810
1794
let merged_config = trino
1811
1795
. merged_config ( & trino_role, & rolegroup_ref, & [ ] )
1812
1796
. unwrap ( ) ;
@@ -1824,13 +1808,65 @@ mod tests {
1824
1808
. unwrap ( ) ,
1825
1809
& merged_config,
1826
1810
& trino_authentication_config,
1827
- & None ,
1811
+ & trino_opa_config ,
1828
1812
None ,
1829
1813
& cluster_info,
1830
1814
)
1831
1815
. unwrap ( )
1832
1816
}
1833
1817
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
+
1834
1870
#[ test]
1835
1871
fn test_env_overrides ( ) {
1836
1872
let trino_yaml = r#"
0 commit comments