Skip to content

Commit 7f72a4c

Browse files
committed
feat: add install psa config
Signed-off-by: Ivan Sim <ivan.sim@suse.com>
1 parent 1aba1f1 commit 7f72a4c

6 files changed

Lines changed: 93 additions & 1 deletion

File tree

pkg/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ type Install struct {
181181
Harvester HarvesterChartValues `json:"harvester,omitempty"`
182182
RawDiskImagePath string `json:"rawDiskImagePath,omitempty"`
183183
PersistentPartitionSize string `json:"persistentPartitionSize,omitempty"`
184+
185+
// pod security admission config
186+
// see templates/rke2-99-harvester-psa.yaml
187+
PSA PSAConfig `json:"psaConfig,omitempty"`
184188
}
185189

186190
type File struct {
@@ -307,6 +311,11 @@ type SSHDConfig struct {
307311
SFTP bool `json:"sftp,omitempty"`
308312
}
309313

314+
type PSAConfig struct {
315+
Enabled bool `json:"enabled"`
316+
EnforceSecurityLevel string `json:"enforceSecurityLevel"`
317+
}
318+
310319
type HarvesterConfig struct {
311320
// Harvester will use scheme version to determine current version and migrate config to new scheme version
312321
SchemeVersion uint32 `json:"schemeVersion,omitempty"`

pkg/config/cos.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ func initRancherdStage(config *HarvesterConfig, stage *yipSchema.Stage) error {
420420
},
421421
)
422422

423+
rke2KubePSAConfig, err := render("rke2-99-harvester-psa.yaml", config)
424+
if err != nil {
425+
return err
426+
}
427+
stage.Files = append(stage.Files,
428+
yipSchema.File{
429+
Path: "/etc/rancher/rke2/config.yaml.d/99-harvester-psa.yaml",
430+
Content: rke2KubePSAConfig,
431+
Permissions: 0600,
432+
Owner: 0,
433+
Group: 0,
434+
},
435+
)
436+
423437
rke2AgentConfig, err := render("rke2-90-harvester-agent.yaml", config)
424438
if err != nil {
425439
return err

pkg/config/templates/rke2-90-harvester-server.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ kubelet-arg:
1616
{{- end }}
1717
{{- end }}
1818
audit-policy-file: /etc/rancher/rke2/config.yaml.d/92-harvester-kube-audit-policy.yaml
19+
pod-security-admission-config-file: /etc/rancher/rke2/config.yaml.d/99-harvester-psa.yaml

pkg/config/templates/rke2-92-harvester-kube-audit-policy.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ apiVersion: audit.k8s.io/v1
22
kind: Policy
33
omitStages:
44
- "ResponseStarted"
5-
- "ResponseComplete"
65
rules:
76
# Any include/exclude rules are added here
87

8+
# Log pod changes at RequestResponse level to audit PSA violation
9+
- level: RequestResponse
10+
resources:
11+
- group: ""
12+
resources: ["pods"]
13+
914
# A catch-all rule to log all other (create/delete/patch) requests at the Metadata level
1015
- level: Metadata
1116
verbs: ["create", "delete", "patch"]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: apiserver.config.k8s.io/v1
2+
kind: AdmissionConfiguration
3+
plugins:
4+
- name: PodSecurity
5+
configuration:
6+
apiVersion: pod-security.admission.config.k8s.io/v1
7+
kind: PodSecurityConfiguration
8+
defaults:
9+
enforce: "{{ .Install.PSA.EnforceSecurityLevel }}"
10+
enforce-version: "latest"
11+
audit: "baseline"
12+
audit-version: "latest"
13+
warn: "baseline"
14+
warn-version: "latest"
15+
exemptions:
16+
usernames: []
17+
runtimeClasses: []
18+
namespaces: [calico-apiserver,
19+
calico-system,
20+
cattle-alerting,
21+
cattle-csp-adapter-system,
22+
cattle-elemental-system,
23+
cattle-epinio-system,
24+
cattle-externalip-system,
25+
cattle-fleet-local-system,
26+
cattle-fleet-system,
27+
cattle-gatekeeper-system,
28+
cattle-global-data,
29+
cattle-global-nt,
30+
cattle-impersonation-system,
31+
cattle-istio,
32+
cattle-istio-system,
33+
cattle-logging,
34+
cattle-logging-system,
35+
cattle-monitoring-system,
36+
cattle-neuvector-system,
37+
cattle-prometheus,
38+
cattle-provisioning-capi-system,
39+
cattle-resources-system,
40+
cattle-sriov-system,
41+
cattle-system,
42+
cattle-ui-plugin-system,
43+
cattle-windows-gmsa-system,
44+
cert-manager,
45+
cis-operator-system,
46+
fleet-default,
47+
ingress-nginx,
48+
istio-system,
49+
kube-node-lease,
50+
kube-public,
51+
kube-system,
52+
longhorn-system,
53+
rancher-alerting-drivers,
54+
security-scan,
55+
tigera-operator,
56+
harvester-system,
57+
harvester-public,
58+
rancher-vcluster]

pkg/console/install_panels.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,11 @@ func addInstallPanel(c *Console) error {
26412641
c.config.ServerURL = formatted
26422642
}
26432643

2644+
c.config.Install.PSA = config.PSAConfig{
2645+
Enabled: true,
2646+
EnforceSecurityLevel: "privileged",
2647+
}
2648+
26442649
if !alreadyInstalled {
26452650
// Have to handle preflight warnings here because we can't check
26462651
// the NIC speed until we've got the correct set of interfaces.

0 commit comments

Comments
 (0)