Skip to content

Commit

Permalink
Merge branch 'add-psa-config' of https://github.com/jcox10/rke2-ansible
Browse files Browse the repository at this point in the history
… into jcox10-add-psa-config
  • Loading branch information
Adam Leiner committed May 21, 2024
2 parents 1ac92b0 + 252a204 commit 4ae0e59
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions inventory/sample/group_vars/rke2_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ rke2_config: {}
# See https://docs.rke2.io/helm/#automatically-deploying-manifests-and-helm-charts
# Add manifest files by specifying the directory path on the control host
# manifest_config_file_path: "{{ playbook_dir }}/sample_files/manifest/"

# See https://ranchermanager.docs.rancher.com/how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/psa-config-templates#exempting-required-rancher-namespaces
# Available in RKE2 1.25+
# Add a pod security admission config file by specifying the file path on the control host
# pod_security_admission_config_file_path: "{{ playbook_dir }}/sample_files/pod-security-admission-config.yaml"
1 change: 1 addition & 0 deletions roles/rke2_common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rke2_images_urls: []
rke2_channel: stable
audit_policy_config_file_path: ""
registry_config_file_path: ""
pod_security_admission_config_file_path: ""
add_iptables_rules: false
rke2_common_yum_repo:
name: rke2-common
Expand Down
16 changes: 16 additions & 0 deletions roles/rke2_common/tasks/add-pod-security-admission-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Create the /etc/rancher/rke2 config dir
ansible.builtin.file:
path: /etc/rancher/rke2
state: directory
recurse: yes

- name: Add pod security admission config file
ansible.builtin.copy:
src: "{{ pod_security_admission_config_file_path }}"
dest: "/etc/rancher/rke2/pod-security-admission-config.yaml"
mode: '0640'
owner: root
group: root
when: caller_role_name == "server"
notify: Restart rke2-server
4 changes: 4 additions & 0 deletions roles/rke2_common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
ansible.builtin.include_tasks: add-registry-config.yml
when: registry_config_file_path | length > 0

- name: Include task file add-pod-security-admission-config.yml
ansible.builtin.include_tasks: add-pod-security-admission-config.yml
when: pod_security_admission_config_file_path | length > 0

- name: Run CIS-Hardening Tasks
ansible.builtin.include_role:
name: rke2_common
Expand Down
57 changes: 57 additions & 0 deletions sample_files/pod-security-admission-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodSecurity
configuration:
apiVersion: pod-security.admission.config.k8s.io/v1
kind: PodSecurityConfiguration
defaults:
enforce: "restricted"
enforce-version: "latest"
audit: "restricted"
audit-version: "latest"
warn: "restricted"
warn-version: "latest"
exemptions:
usernames: []
runtimeClasses: []
namespaces: [calico-apiserver,
calico-system,
cattle-alerting,
cattle-csp-adapter-system,
cattle-elemental-system,
cattle-epinio-system,
cattle-externalip-system,
cattle-fleet-local-system,
cattle-fleet-system,
cattle-gatekeeper-system,
cattle-global-data,
cattle-global-nt,
cattle-impersonation-system,
cattle-istio,
cattle-istio-system,
cattle-logging,
cattle-logging-system,
cattle-monitoring-system,
cattle-neuvector-system,
cattle-prometheus,
cattle-provisioning-capi-system,
cattle-resources-system,
cattle-sriov-system,
cattle-system,
cattle-ui-plugin-system,
cattle-windows-gmsa-system,
cert-manager,
cis-operator-system,
fleet-default,
ingress-nginx,
istio-system,
kube-node-lease,
kube-public,
kube-system,
longhorn-system,
local-path-storage,
rancher-alerting-drivers,
security-scan,
tigera-operator]

0 comments on commit 4ae0e59

Please sign in to comment.