Skip to content

Commit

Permalink
add ability to configure ACE in downstream / #104
Browse files Browse the repository at this point in the history
  • Loading branch information
mddamato committed May 22, 2024
1 parent bfad4e5 commit 3619026
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions inventory/sample/group_vars/rke2_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ rke2_config: {}
# Add a pod security admission config file by specifying the file path on the control host
# 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"

# See https://ranchermanager.docs.rancher.com/v2.6/how-to-guides/new-user-guides/kubernetes-clusters-in-rancher-setup/register-existing-clusters#authorized-cluster-endpoint-support-for-rke2-and-k3s-clusters
# Authorized Cluster Endpoint Support for RKE2
# Warning: You must also set:
# # rke2_config:
# # kube-apiserver-arg:
# # - authentication-token-webhook-config-file=/var/lib/rancher/rke2/kube-api-authn-webhook.yaml
# kube_api_authn_webhook_file_path: "{{ playbook_dir }}/sample_files/kube-api-authn-webhook.yaml"
45 changes: 45 additions & 0 deletions roles/rke2_server/tasks/add-kube-api-authn-webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: Create the /var/lib/rancher/rke2 config dir
ansible.builtin.file:
path: /var/lib/rancher/rke2
state: directory
recurse: yes

- name: Add config file
vars:
file_contents: "{{ lookup('file', kube_api_authn_webhook_file_path) }}"
ansible.builtin.template:
src: ansible_header.j2
dest: "/var/lib/rancher/rke2/kube-api-authn-webhook.yaml"
mode: '0640'
owner: root
group: root
when:
- kube_api_authn_webhook_file_path is defined
- kube_api_authn_webhook_file_path|length != 0
notify: Restart rke2-server

- name: Remove config file
when:
- kube_api_authn_webhook_file_path is not defined or kube_api_authn_webhook_file_path|length == 0
block:
- name: Check that the config file exists
ansible.builtin.stat:
path: "/var/lib/rancher/rke2/kube-api-authn-webhook.yaml"
register: stat_result

- name: "Check that the config file has ansible managed comments"
ansible.builtin.lineinfile:
name: "/var/lib/rancher/rke2/kube-api-authn-webhook.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 config file if exists and has ansible managed comments
ansible.builtin.file:
path: "/var/lib/rancher/rke2/kube-api-authn-webhook.yaml"
state: absent
when:
- ansible_managed_check.changed | bool is false
18 changes: 18 additions & 0 deletions sample_files/kube-api-authn-webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: v1
kind: Config
clusters:
- name: Default
cluster:
insecure-skip-tls-verify: true
server: http://127.0.0.1:6440/v1/authenticate
users:
- name: Default
user:
insecure-skip-tls-verify: true
current-context: webhook
contexts:
- name: webhook
context:
user: Default
cluster: Default

1 comment on commit 3619026

@aleiner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the kube-api-authn-webhook.yaml file something a user will ever have to change? if it's a static file, why not bake it in as a content so that a user doesn't have to either reference the sample file or copy it to their config directory?

Please sign in to comment.