Mohammed Naser | b7b97d6 | 2022-03-12 16:30:00 -0500 | [diff] [blame] | 1 | # Copyright (c) 2022 VEXXHOST, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Mohammed Naser | c8e1a45 | 2022-08-11 16:16:13 -0400 | [diff] [blame] | 15 | - name: Create Issuer |
Mohammed Naser | b7b97d6 | 2022-03-12 16:30:00 -0500 | [diff] [blame] | 16 | kubernetes.core.k8s: |
| 17 | state: present |
| 18 | definition: |
| 19 | apiVersion: cert-manager.io/v1 |
| 20 | kind: Issuer |
| 21 | metadata: |
| 22 | name: openstack |
| 23 | namespace: openstack |
| 24 | spec: "{{ cert_manager_issuer }}" |
Mohammed Naser | c8e1a45 | 2022-08-11 16:16:13 -0400 | [diff] [blame] | 25 | # NOTE(mnaser): Since we haven't moved to the operator pattern yet, we need to |
| 26 | # keep retrying a few times as the CRDs might not be installed |
| 27 | # yet. |
| 28 | retries: 60 |
| 29 | delay: 5 |
| 30 | register: _result |
| 31 | until: _result is not failed |
okozachenko | 05a72ed | 2022-04-12 23:01:43 +1000 | [diff] [blame] | 32 | |
okozachenko | 674f9b7 | 2022-04-19 01:28:33 +1000 | [diff] [blame] | 33 | - name: Bootstrap self-signed PKI |
| 34 | block: |
| 35 | - name: Create self-signed issuer |
| 36 | kubernetes.core.k8s: |
| 37 | state: present |
| 38 | definition: |
| 39 | apiVersion: cert-manager.io/v1 |
okozachenko | 05a72ed | 2022-04-12 23:01:43 +1000 | [diff] [blame] | 40 | kind: ClusterIssuer |
okozachenko | 674f9b7 | 2022-04-19 01:28:33 +1000 | [diff] [blame] | 41 | metadata: |
| 42 | name: selfsigned-issuer |
| 43 | spec: |
| 44 | selfSigned: {} |
| 45 | |
| 46 | - name: Bootstrap a custom root certificate for a private PKI |
| 47 | kubernetes.core.k8s: |
| 48 | state: present |
| 49 | definition: |
| 50 | apiVersion: cert-manager.io/v1 |
| 51 | kind: Certificate |
| 52 | metadata: |
| 53 | name: selfsigned-ca |
| 54 | namespace: openstack |
| 55 | spec: |
| 56 | isCA: true |
| 57 | commonName: selfsigned-ca |
| 58 | secretName: root-secret |
| 59 | duration: 86400h # 3600d |
| 60 | renewBefore: 360h # 15d |
| 61 | privateKey: |
| 62 | algorithm: ECDSA |
| 63 | size: 256 |
| 64 | issuerRef: |
| 65 | name: selfsigned-issuer |
| 66 | kind: ClusterIssuer |
| 67 | group: cert-manager.io |
| 68 | |
| 69 | - name: Wait till the root secret is created |
| 70 | kubernetes.core.k8s_info: |
| 71 | api_version: v1 |
| 72 | kind: Secret |
| 73 | wait: true |
| 74 | name: root-secret |
| 75 | namespace: openstack |
| 76 | wait_sleep: 10 |
| 77 | wait_timeout: 300 |
| 78 | register: _openstack_helm_root_secret |
| 79 | |
| 80 | - name: Copy CA certificate on host |
| 81 | ansible.builtin.copy: |
| 82 | content: "{{ _openstack_helm_root_secret.resources[0].data['tls.crt'] | b64decode }}" |
| 83 | dest: "/usr/local/share/ca-certificates/self-signed-osh-ca.crt" |
| 84 | mode: "0644" |
| 85 | |
| 86 | - name: Update ca certificates on host |
| 87 | ansible.builtin.command: |
| 88 | cmd: update-ca-certificates |
| 89 | changed_when: false |
| 90 | when: |
| 91 | - cert_manager_issuer.ca.secretName is defined |
| 92 | - cert_manager_issuer.ca.secretName == "root-secret" |