Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jcox10 add psa config #221

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible_header.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## This is an Ansible managed file, contents will be overwritten ##

{{ file_contents }}
6 changes: 6 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,9 @@ 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
aleiner marked this conversation as resolved.
Show resolved Hide resolved
# Requires config.yaml to include `- admission-control-config-file=/etc/rancher/rke2/pod-security-admission-config.yaml` in order for this to be honored
# 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
@@ -1,10 +1,11 @@
---
tarball_dir: "/usr/local"

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)
rke2_tarball_url: ""

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)
rke2_images_urls: []

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)
rke2_channel: stable

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)
audit_policy_config_file_path: ""

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)
registry_config_file_path: ""

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)
pod_security_admission_config_file_path: ""
add_iptables_rules: false
rke2_common_yum_repo:
name: rke2-common
Expand Down
4 changes: 2 additions & 2 deletions roles/rke2_common/tasks/images_tarball_install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Check for images tar.gz in {{ playbook_dir }}/tarball_install/rke2-images.linux-amd64.tar.gz" # noqa name[template] yaml[line-length]

Check warning on line 2 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for push

2:121 [line-length] line too long (143 > 120 characters)

Check warning on line 2 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

2:121 [line-length] line too long (143 > 120 characters)

Check warning on line 2 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

2:121 [line-length] line too long (143 > 120 characters)
ansible.builtin.stat:
path: "{{ playbook_dir }}/tarball_install/rke2-images.linux-amd64.tar.gz"
get_checksum: false
Expand All @@ -7,7 +7,7 @@
delegate_to: 127.0.0.1
become: false

- name: "Check for images tar.zst in {{ playbook_dir }}/tarball_install/rke2-images.linux-amd64.tar.zst" # noqa name[template] yaml[line-length]

Check warning on line 10 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for push

10:121 [line-length] line too long (145 > 120 characters)

Check warning on line 10 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

10:121 [line-length] line too long (145 > 120 characters)

Check warning on line 10 in roles/rke2_common/tasks/images_tarball_install.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

10:121 [line-length] line too long (145 > 120 characters)
ansible.builtin.stat:
path: "{{ playbook_dir }}/tarball_install/rke2-images.linux-amd64.tar.zst"
get_checksum: false
Expand All @@ -23,12 +23,12 @@

- name: Download images tar files url
ansible.builtin.get_url:
url: "{{item}}"
url: "{{ item }}"
dest: "/var/lib/rancher/rke2/agent/images"
mode: "0644"
when:
- rke2_images_urls != []
with_items: "{{rke2_images_urls}}"
with_items: "{{ rke2_images_urls }}"

- name: Add images tar.gz to needed directory if provided
ansible.builtin.copy:
Expand Down
45 changes: 45 additions & 0 deletions roles/rke2_server/tasks/add-pod-security-admission-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- 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
vars:
file_contents: "{{ lookup('file', pod_security_admission_config_file_path) }}"
ansible.builtin.template:
src: ansible_header.j2
dest: "/etc/rancher/rke2/pod-security-admission-config.yaml"
mode: '0640'
owner: root
group: root
when:
- pod_security_admission_config_file_path is defined
- pod_security_admission_config_file_path|length != 0
notify: Restart rke2-server

- name: Remove pod security admission config file
when:
- pod_security_admission_config_file_path is not defined or pod_security_admission_config_file_path|length == 0
block:
- name: Check that the PSA config file exists
ansible.builtin.stat:
path: "/etc/rancher/rke2/pod-security-admission-config.yaml"
register: stat_result

- name: "Check that the PSA config file has ansible managed comments"
ansible.builtin.lineinfile:
name: "/etc/rancher/rke2/pod-security-admission-config.yaml"
line: '## This is an Ansible managed file, contents will be overwritten ##'
state: present
check_mode: yes
register: ansible_managed_check
when: stat_result.stat.exists | bool is true

- name: Remove the PSA config file if exists and has ansible managed comments
ansible.builtin.file:
path: "/etc/rancher/rke2/pod-security-admission-config.yaml"
state: absent
when:
- ansible_managed_check.changed | bool is false
3 changes: 3 additions & 0 deletions roles/rke2_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
name: rke2_common
tasks_from: main

- name: Include task file add-pod-security-admission-config.yml
ansible.builtin.include_tasks: add-pod-security-admission-config.yml

- name: Setup initial server
ansible.builtin.include_tasks: first_server.yml
when: inventory_hostname in groups['rke2_servers'][0]
Expand Down
61 changes: 61 additions & 0 deletions sample_files/pod-security-admission-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#This sample list was generated from:

Check failure on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

yaml[comments]

Missing starting space in comment

Check warning on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

1:2 [comments] missing starting space in comment

Check failure on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

1:2 [comments] missing starting space in comment

Check failure on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 1 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

1:2 [comments] missing starting space in comment
#https://ranchermanager.docs.rancher.com/how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/psa-config-templates#exempting-required-rancher-namespaces

Check failure on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

yaml[comments]

Missing starting space in comment

Check warning on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

2:2 [comments] missing starting space in comment

Check failure on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

2:2 [comments] missing starting space in comment

Check failure on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 2 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

2:2 [comments] missing starting space in comment
#For security reasons, this list should be as concise as possible - only include active namespaces that need to be except from a restricted profile.

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

yaml[line-length]

Line too long (148 > 120 characters)

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

yaml[comments]

Missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

3:2 [comments] missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for push

3:121 [line-length] line too long (148 > 120 characters)

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[line-length]

Line too long (148 > 120 characters)

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

3:2 [comments] missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

3:121 [line-length] line too long (148 > 120 characters)

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[line-length]

Line too long (148 > 120 characters)

Check failure on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

yaml[comments]

Missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

3:2 [comments] missing starting space in comment

Check warning on line 3 in sample_files/pod-security-admission-config.yaml

View workflow job for this annotation

GitHub Actions / Lint for PR

3:121 [line-length] line too long (148 > 120 characters)

---
aleiner marked this conversation as resolved.
Show resolved Hide resolved
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]
Loading