|
28 | 28 | command: vault auth enable jwt |
29 | 29 | when: not vault_auth_jwt |
30 | 30 |
|
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) }}" |
39 | 35 |
|
40 | | -- name: Copy router CA certificate to vault |
41 | | - kubernetes.core.k8s_cp: |
| 36 | +- name: Get OIDC discovery certificate |
| 37 | + kubernetes.core.k8s_exec: |
42 | 38 | namespace: "{{ vault_ns }}" |
43 | 39 | 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" |
46 | 44 | when: not vault_auth_jwt |
47 | 45 |
|
48 | 46 | - name: Write JWT configuration |
|
53 | 51 | vault write auth/jwt/config |
54 | 52 | oidc_discovery_url={{ oidc_discovery_url }} |
55 | 53 | 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 |
57 | 55 | when: not vault_auth_jwt |
58 | 56 |
|
59 | 57 | - name: Write JWT role |
|
67 | 65 | bound_audiences={{ spiffe_audience }} |
68 | 66 | bound_subject={{ spiffe_subject }} |
69 | 67 | token_ttl={{ token_ttl | default('24h') }} |
70 | | - token_policies={{ vault_global_policy }}-secret |
| 68 | + token_policies={{ role_policy | default('{}-secret'.format(vault_global_policy)) }} |
71 | 69 | when: not vault_auth_jwt |
72 | 70 |
|
73 | 71 | - name: Delete router CA certificate |
74 | 72 | kubernetes.core.k8s_exec: |
75 | 73 | namespace: "{{ vault_ns }}" |
76 | 74 | pod: "{{ vault_pod }}" |
77 | | - command: rm -f /tmp/router-ca.crt |
| 75 | + command: rm -f /tmp/oidc-discovery-certificate.pem |
78 | 76 | when: not vault_auth_jwt |
0 commit comments