Skip to content

Commit

Permalink
Add tests for kubelet-csr-approver
Browse files Browse the repository at this point in the history
Co-Authored-By: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
  • Loading branch information
j4m3s-s and MrFreezeex committed Apr 27, 2023
1 parent d1b013d commit 8f2e50d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitlab-ci/packet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ packet_debian11-custom-cni:
extends: .packet_pr
when: manual

packet_debian11-kubelet-csr-approver:
stage: deploy-part2
extends: .packet_pr
when: manual

# ### PR JOBS PART3
# Long jobs (45min+)

Expand Down
1 change: 1 addition & 0 deletions tests/files/packet_centos7-flannel-addons-ha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ metrics_server_kubelet_insecure_tls: true
kube_token_auth: true
enable_nodelocaldns: false
kubelet_rotate_server_certificates: true
kubelet_csr_approver_enabled: false

kube_oidc_url: https://accounts.google.com/.well-known/openid-configuration
kube_oidc_client_id: kubespray-example
Expand Down
11 changes: 11 additions & 0 deletions tests/files/packet_debian11-kubelet-csr-approver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Instance settings
cloud_image: debian-11
mode: default

# Kubespray settings
kubelet_rotate_server_certificates: true
kubelet_csr_approver_enabled: true
kubelet_csr_approver_values:
# Do not check DNS resolution in testing (not recommended in production)
bypassDnsResolution: true
1 change: 1 addition & 0 deletions tests/files/packet_ubuntu20-calico-aio-hardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ etcd_deployment_type: kubeadm
kubelet_authentication_token_webhook: true
kube_read_only_port: 0
kubelet_rotate_server_certificates: true
kubelet_csr_approver_enabled: false
kubelet_protect_kernel_defaults: true
kubelet_event_record_qps: 1
kubelet_rotate_certificates: true
Expand Down
33 changes: 32 additions & 1 deletion tests/testcases/030_check-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
bin_dir: "/usr/local/bin"
when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]

- name: Check kubelet serving certificates approved with kubelet_csr_approver
block:

- name: Get certificate signing requests
command: "{{ bin_dir }}/kubectl get csr"
register: get_csr
changed_when: false

- debug: # noqa unnamed-task
msg: "{{ get_csr.stdout.split('\n') }}"

- name: Check there are csrs
assert:
that: get_csr.stdout_lines | length > 0
fail_msg: kubelet_rotate_server_certificates is {{ kubelet_rotate_server_certificates }} but no csr's found

- name: Get Denied/Pending certificate signing requests
shell: "{{ bin_dir }}/kubectl get csr | grep -e Denied -e Pending || true"
register: get_csr_denied_pending
changed_when: false

- name: Check there are Denied/Pending csrs
assert:
that: get_csr_denied_pending.stdout_lines | length == 0
fail_msg: kubelet_csr_approver is enabled but CSRs are not approved
when:
- kubelet_rotate_server_certificates | default(false)
- kubelet_csr_approver_enabled | default(kubelet_rotate_server_certificates | default(false))

- name: Approve kubelet serving certificates
block:

Expand All @@ -37,7 +66,9 @@
- debug: # noqa unnamed-task
msg: "{{ certificate_approve.stdout.split('\n') }}"

when: kubelet_rotate_server_certificates | default(false)
when:
- kubelet_rotate_server_certificates | default(false)
- not (kubelet_csr_approver_enabled | default(kubelet_rotate_server_certificates | default(false)))

- name: Create test namespace
command: "{{ bin_dir }}/kubectl create namespace test"
Expand Down

0 comments on commit 8f2e50d

Please sign in to comment.