mirror of
				https://github.com/siderolabs/talos.git
				synced 2025-11-04 10:21:13 +01:00 
			
		
		
		
	fix: always override APIServer audit policy
Fixes #7537 Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
		
							parent
							
								
									355681ddab
								
							
						
					
					
						commit
						f863498ff6
					
				@ -130,3 +130,43 @@ func TestApplyMultiDoc(t *testing.T) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//go:embed testdata/auditpolicy/config.yaml
 | 
				
			||||||
 | 
					var configAudit []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//go:embed testdata/auditpolicy/expected.yaml
 | 
				
			||||||
 | 
					var expectedAudit []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestApplyAuditPolicy(t *testing.T) {
 | 
				
			||||||
 | 
						patches, err := configpatcher.LoadPatches([]string{
 | 
				
			||||||
 | 
							"@testdata/auditpolicy/patch1.yaml",
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						require.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cfg, err := configloader.NewFromBytes(configAudit)
 | 
				
			||||||
 | 
						require.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tt := range []struct {
 | 
				
			||||||
 | 
							name  string
 | 
				
			||||||
 | 
							input configpatcher.Input
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name:  "WithConfig",
 | 
				
			||||||
 | 
								input: configpatcher.WithConfig(cfg),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name:  "WithBytes",
 | 
				
			||||||
 | 
								input: configpatcher.WithBytes(configAudit),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						} {
 | 
				
			||||||
 | 
							t.Run(tt.name, func(t *testing.T) {
 | 
				
			||||||
 | 
								out, err := configpatcher.Apply(tt.input, patches)
 | 
				
			||||||
 | 
								require.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								bytes, err := out.Bytes()
 | 
				
			||||||
 | 
								require.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								assert.Equal(t, string(expectedAudit), string(bytes))
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/config.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/config.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					version: v1alpha1
 | 
				
			||||||
 | 
					machine:
 | 
				
			||||||
 | 
					  network:
 | 
				
			||||||
 | 
					    hostname: hostname-foo
 | 
				
			||||||
 | 
					cluster:
 | 
				
			||||||
 | 
					  apiServer:
 | 
				
			||||||
 | 
					    auditPolicy:
 | 
				
			||||||
 | 
					      apiVersion: audit.k8s.io/v1
 | 
				
			||||||
 | 
					      kind: Policy
 | 
				
			||||||
 | 
					      rules:
 | 
				
			||||||
 | 
					        - level: Metadata
 | 
				
			||||||
 | 
					  controlPlane:
 | 
				
			||||||
 | 
					    endpoint: https://localhost:6443
 | 
				
			||||||
							
								
								
									
										16
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/expected.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/expected.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					version: v1alpha1
 | 
				
			||||||
 | 
					machine:
 | 
				
			||||||
 | 
					    type: ""
 | 
				
			||||||
 | 
					    token: ""
 | 
				
			||||||
 | 
					    certSANs: []
 | 
				
			||||||
 | 
					    network:
 | 
				
			||||||
 | 
					        hostname: hostname-foo
 | 
				
			||||||
 | 
					cluster:
 | 
				
			||||||
 | 
					    controlPlane:
 | 
				
			||||||
 | 
					        endpoint: https://localhost:6443
 | 
				
			||||||
 | 
					    apiServer:
 | 
				
			||||||
 | 
					        auditPolicy:
 | 
				
			||||||
 | 
					            apiVersion: audit.k8s.io/v1
 | 
				
			||||||
 | 
					            kind: Policy
 | 
				
			||||||
 | 
					            rules:
 | 
				
			||||||
 | 
					                - level: None
 | 
				
			||||||
							
								
								
									
										7
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/patch1.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								pkg/machinery/config/configpatcher/testdata/auditpolicy/patch1.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					cluster:
 | 
				
			||||||
 | 
					  apiServer:
 | 
				
			||||||
 | 
					    auditPolicy:
 | 
				
			||||||
 | 
					      apiVersion: audit.k8s.io/v1
 | 
				
			||||||
 | 
					      kind: Policy
 | 
				
			||||||
 | 
					      rules:
 | 
				
			||||||
 | 
					        - level: None
 | 
				
			||||||
@ -1693,7 +1693,7 @@ type APIServerConfig struct {
 | 
				
			|||||||
	//     - value: APIServerDefaultAuditPolicy
 | 
						//     - value: APIServerDefaultAuditPolicy
 | 
				
			||||||
	//   schema:
 | 
						//   schema:
 | 
				
			||||||
	//     type: object
 | 
						//     type: object
 | 
				
			||||||
	AuditPolicyConfig Unstructured `yaml:"auditPolicy,omitempty"`
 | 
						AuditPolicyConfig Unstructured `yaml:"auditPolicy,omitempty" merge:"replace"`
 | 
				
			||||||
	//   description: |
 | 
						//   description: |
 | 
				
			||||||
	//     Configure the API server resources.
 | 
						//     Configure the API server resources.
 | 
				
			||||||
	//   schema:
 | 
						//   schema:
 | 
				
			||||||
 | 
				
			|||||||
@ -49,6 +49,7 @@ There are some special rules:
 | 
				
			|||||||
  - values of the fields `cluster.network.podSubnets` and `cluster.network.serviceSubnets` are overwritten on merge
 | 
					  - values of the fields `cluster.network.podSubnets` and `cluster.network.serviceSubnets` are overwritten on merge
 | 
				
			||||||
  - `network.interfaces` section is merged with the value in the machine config if there is a match on `interface:` or `deviceSelector:` keys
 | 
					  - `network.interfaces` section is merged with the value in the machine config if there is a match on `interface:` or `deviceSelector:` keys
 | 
				
			||||||
  - `network.interfaces.vlans` section is merged with the value in the machine config if there is a match on the `vlanId:` key
 | 
					  - `network.interfaces.vlans` section is merged with the value in the machine config if there is a match on the `vlanId:` key
 | 
				
			||||||
 | 
					  - `cluster.apiServer.auditPolicy` value is replaced on merge
 | 
				
			||||||
 | 
					
 | 
				
			||||||
When patching a multi-document machine configuration, following rules apply:
 | 
					When patching a multi-document machine configuration, following rules apply:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user