Skip to content

Commit 3bc86cd

Browse files
committed
mbp-935: Replace the OpenShift Ingress CA with the endpoint certificate in the Vault JWT configuration
Signed-off-by: Manuel Lorenzo <[email protected]>
1 parent f6e7968 commit 3bc86cd

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

roles/vault_utils/tasks/vault_jwt.yaml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@
2828
command: vault auth enable jwt
2929
when: not vault_auth_jwt
3030

31-
- name: Get router CA certificate
32-
kubernetes.core.k8s_info:
33-
kind: Secret
34-
namespace: openshift-ingress-operator
35-
name: router-ca
36-
api_version: v1
37-
register: router_ca_cert
38-
when: not vault_auth_jwt
31+
- name: Split url into host and port
32+
ansible.builtin.set_fact:
33+
oidc_discovery_host: "{{ oidc_discovery_url | urlsplit('hostname') }}"
34+
oidc_discovery_port: "{{ oidc_discovery_url | urlsplit('port') | default('443', true) }}"
3935

40-
- name: Copy router CA certificate to vault
41-
kubernetes.core.k8s_cp:
36+
- name: Get OIDC discovery certificate
37+
kubernetes.core.k8s_exec:
4238
namespace: "{{ vault_ns }}"
4339
pod: "{{ vault_pod }}"
44-
content: "{{ router_ca_cert.resources[0].data['tls.crt'] | b64decode }}"
45-
remote_path: /tmp/router-ca.crt
40+
command: >
41+
bash -e -c
42+
"echo -n | openssl s_client -connect {{ oidc_discovery_host }}:{{ oidc_discovery_port }} -servername {{ oidc_discovery_host }}
43+
| openssl x509 -outform PEM > /tmp/oidc-discovery-certificate.pem"
4644
when: not vault_auth_jwt
4745

4846
- name: Write JWT configuration
@@ -53,7 +51,7 @@
5351
vault write auth/jwt/config
5452
oidc_discovery_url={{ oidc_discovery_url }}
5553
default_role={{ default_role | default('default') }}
56-
oidc_discovery_ca_pem=@/tmp/router-ca.crt
54+
oidc_discovery_ca_pem=@/tmp/oidc-discovery-certificate.pem
5755
when: not vault_auth_jwt
5856

5957
- name: Write JWT role
@@ -67,12 +65,12 @@
6765
bound_audiences={{ spiffe_audience }}
6866
bound_subject={{ spiffe_subject }}
6967
token_ttl={{ token_ttl | default('24h') }}
70-
token_policies={{ vault_global_policy }}-secret
68+
token_policies={{ role_policy | default('{}-secret'.format(vault_global_policy)) }}
7169
when: not vault_auth_jwt
7270

7371
- name: Delete router CA certificate
7472
kubernetes.core.k8s_exec:
7573
namespace: "{{ vault_ns }}"
7674
pod: "{{ vault_pod }}"
77-
command: rm -f /tmp/router-ca.crt
75+
command: rm -f /tmp/oidc-discovery-certificate.pem
7876
when: not vault_auth_jwt

0 commit comments

Comments
 (0)