Skip to content

Commit

Permalink
Merge pull request #1063 from TheRealHaoLiu/receptor-ca-secret-altern…
Browse files Browse the repository at this point in the history
…ative
  • Loading branch information
TheRealHaoLiu authored Sep 29, 2022
2 parents a1e289e + 0611f3e commit 5b7589a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
44 changes: 44 additions & 0 deletions roles/installer/tasks/resources_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@
register: _receptor_ca
no_log: "{{ no_log }}"

- name: Migrate Receptor CA Secret
when:
- _receptor_ca['resources'] | default([]) | length
- _receptor_ca['resources'][0]['type'] != "kubernetes.io/tls"
block:
- name: Delete old Receptor CA Secret
k8s:
state: absent
kind: Secret
namespace: '{{ ansible_operator_meta.namespace }}'
name: '{{ ansible_operator_meta.name }}-receptor-ca'
- name: Create tempfile for receptor-ca.key
tempfile:
state: file
suffix: .key
register: _receptor_ca_key_file
- name: Copy Receptor CA key from old secret to tempfile
copy:
content: "{{ _receptor_ca['resources'][0]['data']['receptor-ca.key'] | b64decode }}"
dest: "{{ _receptor_ca_key_file.path }}"
no_log: "{{ no_log }}"
- name: Create tempfile for receptor-ca.crt
tempfile:
state: file
suffix: .crt
register: _receptor_ca_crt_file
- name: Copy Receptor CA cert from old secret to tempfile
copy:
content: "{{ _receptor_ca['resources'][0]['data']['receptor-ca.crt'] | b64decode }}"
dest: "{{ _receptor_ca_crt_file.path }}"
no_log: "{{ no_log }}"
- name: Create New Receptor CA secret
k8s:
apply: true
definition: "{{ lookup('template', 'secrets/receptor_ca_secret.yaml.j2') }}"
no_log: "{{ no_log }}"
- name: Remove tempfiles
file:
path: "{{ item }}"
state: absent
loop:
- "{{ _receptor_ca_key_file.path }}"
- "{{ _receptor_ca_crt_file.path }}"

- name: Create Receptor Mesh CA
block:
- name: Create tempfile for receptor-ca.key
Expand Down
16 changes: 13 additions & 3 deletions roles/installer/templates/deployments/deployment.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ spec:
fieldPath: metadata.name
volumeMounts:
- name: "{{ ansible_operator_meta.name }}-receptor-ca"
mountPath: "/etc/receptor/tls/ca"
mountPath: "/etc/receptor/tls/ca/receptor-ca.crt"
subPath: "tls.crt"
readOnly: true
- name: "{{ ansible_operator_meta.name }}-receptor-ca"
mountPath: "/etc/receptor/tls/ca/receptor-ca.key"
subPath: "tls.key"
readOnly: true
- name: "{{ ansible_operator_meta.name }}-receptor-tls"
mountPath: "/etc/receptor/tls/"
Expand Down Expand Up @@ -179,7 +184,12 @@ spec:
subPath: "work-public-key.pem"
readOnly: true
- name: "{{ ansible_operator_meta.name }}-receptor-ca"
mountPath: "/etc/receptor/tls/ca"
mountPath: "/etc/receptor/tls/ca/receptor-ca.crt"
subPath: "tls.crt"
readOnly: true
- name: "{{ ansible_operator_meta.name }}-receptor-ca"
mountPath: "/etc/receptor/tls/ca/receptor-ca.key"
subPath: "tls.key"
readOnly: true
{% if development_mode | bool %}
- name: awx-devel
Expand Down Expand Up @@ -324,7 +334,7 @@ spec:
mountPath: "/etc/receptor/"
- name: "{{ ansible_operator_meta.name }}-receptor-ca"
mountPath: "/etc/receptor/tls/ca/receptor-ca.crt"
subPath: "receptor-ca.crt"
subPath: "tls.crt"
readOnly: true
- name: "{{ ansible_operator_meta.name }}-receptor-work-signing"
mountPath: "/etc/receptor/signing/work-private-key.pem"
Expand Down
5 changes: 3 additions & 2 deletions roles/installer/templates/secrets/receptor_ca_secret.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
app.kubernetes.io/component: '{{ deployment_type }}'
app.kubernetes.io/operator-version: '{{ lookup("env", "OPERATOR_VERSION") }}'
type: kubernetes.io/tls
data:
receptor-ca.crt: '{{ lookup('file', '{{ _receptor_ca_crt_file.path }}') | b64encode }}'
receptor-ca.key: '{{ lookup('file', '{{ _receptor_ca_key_file.path }}') | b64encode }}'
tls.crt: '{{ lookup('file', '{{ _receptor_ca_crt_file.path }}') | b64encode }}'
tls.key: '{{ lookup('file', '{{ _receptor_ca_key_file.path }}') | b64encode }}'

0 comments on commit 5b7589a

Please sign in to comment.