From a999f438ce16d738be5cd25fab53a0b510d5ac85 Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Tue, 3 Nov 2026 15:38:05 +0100 Subject: [PATCH 1/3] Complete Azure DNS integration for cert-manager workload --- .../defaults/main.yml | 65 ++++++- roles/ocp4_workload_cert_manager/readme.adoc | 99 ++++++++++- .../tasks/cert_manager_azure.yml | 2 + .../tasks/validate_azure.yml | 50 ++++++ .../tasks/workload.yml | 72 ++++++-- .../templates/clusterissuer-fallback.yaml.j2 | 20 ++- .../templates/clusterissuer.yaml.j2 | 20 ++- .../secret-azure-credentials.yaml.j2 | 2 +- tests/static/tox.ini | 11 +- tests/unit/test_cert_manager_azure.py | 163 ++++++++++++++++++ 10 files changed, 470 insertions(+), 34 deletions(-) create mode 100644 roles/ocp4_workload_cert_manager/tasks/validate_azure.yml create mode 100644 tests/unit/test_cert_manager_azure.py diff --git a/roles/ocp4_workload_cert_manager/defaults/main.yml b/roles/ocp4_workload_cert_manager/defaults/main.yml index a47cf3b8..7ab1214b 100644 --- a/roles/ocp4_workload_cert_manager/defaults/main.yml +++ b/roles/ocp4_workload_cert_manager/defaults/main.yml @@ -79,13 +79,32 @@ ocp4_workload_cert_manager_gcp_credentials: "{{ gcp_credentials }}" # --------------------------------------------------------------- # Settings for Azure # --------------------------------------------------------------- -# Set from AgnosticV to the actual azure credentials -ocp4_workload_cert_manager_azure_client_id: "{{ azure_service_principal }}" +# Azure DNS service principal application/client ID (string). Explicit role inputs +# override these defaults. Prefer canonical Azure names; retain legacy aliases. +ocp4_workload_cert_manager_azure_client_id: "{{ azure_service_principal_id | default(azure_service_principal | default('')) }}" + +# Azure DNS service principal password (secret string). Stored in a Kubernetes +# Secret in cert-manager for issuance AND renewal. Never log this value. +ocp4_workload_cert_manager_azure_client_secret: "{{ azure_service_principal_password | default(azure_password | default('')) }}" + +# Azure cloud environment recognized by cert-manager (string), used by both +# primary and fallback AzureDNS solvers. Public Azure is the default. ocp4_workload_cert_manager_azure_environment: AzurePublicCloud -ocp4_workload_cert_manager_azure_hostedzone_name: "{{ azure_user_domain }}" -ocp4_workload_cert_manager_azure_resource_group_name: "{{ az_dnszone_resource_group }}" -ocp4_workload_cert_manager_azure_subscription_id: "{{ azure_subscription_id }}" -ocp4_workload_cert_manager_azure_tenant_id: "{{ azure_tenant }}" + +# Existing publicly delegated Azure DNS zone (string, not a resource ID). +# Enabled certificate targets must equal this zone or be beneath it. +ocp4_workload_cert_manager_azure_hostedzone_name: "{{ azure_dns_zone | default(azure_user_domain | default('')) }}" + +# Resource group containing that DNS zone (string), NOT the cluster resource +# group. The service principal needs DNS record write/delete permission here. +ocp4_workload_cert_manager_azure_resource_group_name: "{{ azure_resource_group | default(az_dnszone_resource_group | default('')) }}" + +# Subscription containing the DNS zone (string). Canonical input then alias. +ocp4_workload_cert_manager_azure_subscription_id: "{{ azure_subscription | default(azure_subscription_id | default('')) }}" + +# Tenant of the DNS service principal (string). An explicit role override may +# supply a dedicated DNS identity independently of cluster provisioning. +ocp4_workload_cert_manager_azure_tenant_id: "{{ azure_tenant | default(azure_tenant_id | default('')) }}" # --------------------------------------------------------------- # Operator settings @@ -99,3 +118,37 @@ ocp4_workload_cert_manager_catalog_snapshot_image: quay.io/rhpds/olm_snapshot_re ocp4_workload_cert_manager_catalog_snapshot_image_tag: v4.19_2025_07_21 # ocp4_workload_cert_manager_starting_csv: cert-manager-operator.v1.15.0 ocp4_workload_cert_manager_automatic_install_plan_approval: true + +# Internal results of enabled Certificate creation tasks; never supply as inputs. +r_certificate_ingress_request: "{{ undef(hint='Internal ingress certificate request result') }}" +r_certificate_api_request: "{{ undef(hint='Internal API certificate request result') }}" +# Task-local normalized Azure DNS zone used for label-boundary validation. +_ocp4_workload_cert_manager_dns_zone: "{{ undef(hint='Internal normalized Azure DNS zone') }}" + +# External Azure inputs consumed by the standalone-role defaults above. These +# stay undefined until supplied, so legacy aliases remain usable. In the v2 +# Azure config, normalized localhost facts supply the role-specific inputs. +# azure_service_principal_id: canonical application/client UUID (string). +azure_service_principal_id: "{{ undef(hint='Optional canonical Azure client ID') }}" +# azure_service_principal: legacy application/client UUID alias (string). +azure_service_principal: "{{ undef(hint='Optional legacy Azure client ID') }}" +# azure_service_principal_password: canonical service principal password (secret). +azure_service_principal_password: "{{ undef(hint='Optional canonical Azure client secret') }}" +# azure_password: legacy service principal password alias (secret). +azure_password: "{{ undef(hint='Optional legacy Azure client secret') }}" +# azure_dns_zone: canonical existing public DNS zone name (string). +azure_dns_zone: "{{ undef(hint='Optional canonical Azure DNS zone') }}" +# azure_user_domain: legacy existing public DNS zone name alias (string). +azure_user_domain: "{{ undef(hint='Optional legacy Azure DNS zone') }}" +# azure_resource_group: canonical existing DNS/sandbox resource group (string). +azure_resource_group: "{{ undef(hint='Optional canonical Azure DNS resource group') }}" +# az_dnszone_resource_group: legacy DNS resource group alias (string). +az_dnszone_resource_group: "{{ undef(hint='Optional legacy Azure DNS resource group') }}" +# azure_subscription: canonical subscription UUID containing the DNS zone (string). +azure_subscription: "{{ undef(hint='Optional canonical Azure subscription') }}" +# azure_subscription_id: legacy subscription UUID alias (string). +azure_subscription_id: "{{ undef(hint='Optional legacy Azure subscription') }}" +# azure_tenant: canonical DNS identity tenant UUID or domain (string). +azure_tenant: "{{ undef(hint='Optional canonical Azure tenant') }}" +# azure_tenant_id: alternate DNS identity tenant UUID or domain (string). +azure_tenant_id: "{{ undef(hint='Optional alternate Azure tenant') }}" diff --git a/roles/ocp4_workload_cert_manager/readme.adoc b/roles/ocp4_workload_cert_manager/readme.adoc index 48c5d20d..dd53926b 100644 --- a/roles/ocp4_workload_cert_manager/readme.adoc +++ b/roles/ocp4_workload_cert_manager/readme.adoc @@ -1,3 +1,98 @@ -= ocp4_workload_cert_manager - Install Red Hat Cert Manager Operator and Request and install certificates from Let's Encrypt or ZeroSSL += ocp4_workload_cert_manager -See defaults/main.yml for variables to set. +Installs the Red Hat cert-manager Operator, configures an ACME ClusterIssuer, +requests certificates, and installs ready certificates on the default ingress +controller and optionally the API server. It runs on the bastion with cluster-admin +Kubernetes access. See `defaults/main.yml` for inputs and defaults. + +== Azure DNS with Azure IPI + +Use `cloud_provider: azure` and `host_ocp4_deploy_installation_method: openshift_install`. +Add `agnosticd.core_workloads.ocp4_workload_cert_manager` to the config's existing +`workloads` list. Ingress certificates are enabled by default; API certificates +are disabled. Enabling API replacement restarts API servers and uses the existing +rollout wait and kubeconfig adjustment flow. + +The Azure config maps normalized controller facts to these workload inputs, so +workloads running on the bastion use the same sandbox credentials and delegated +DNS zone: + +[cols="1,1"] +|=== +|Role input suffix (`ocp4_workload_cert_manager_azure_`) |Controller fact +|client_id |azure_auth.app_id +|client_secret |azure_auth.password +|subscription_id |azure_auth.subscription_id +|tenant_id |azure_auth.tenant +|hostedzone_name |azure_settings.dns_zone +|resource_group_name |azure_settings.sandbox_group +|=== + +Explicit role-specific inputs override these defaults, allowing a dedicated DNS +identity or a zone in another subscription. Standalone role use prefers canonical +Azure variables and falls back to legacy aliases; missing values fail before +operator installation. The default environment is `AzurePublicCloud`; both primary +and fallback issuers honor `ocp4_workload_cert_manager_azure_environment`. + +The public zone must already exist and be delegated. The service principal must +be able to read the zone and create/delete TXT records; `DNS Zone Contributor` +on that zone is the documented AzureDNS setup. This workload creates neither +identities nor role assignments. See +https://cert-manager.io/docs/configuration/acme/dns01/azuredns/[AzureDNS authentication]. +The resource group is the one containing the DNS zone, not the cluster's group. + +Enabled certificate names must equal the zone or be descendants at a DNS-label +boundary. Case and a final dot are ignored for this check. Azure IPI API/ingress +names beneath the workshop zone work. Microsoft's managed ARO domains do not +belong to that zone; ARO custom domains and HCP are outside this integration. +Disabled targets are not requested or checked. Disabling a flag does not delete +an already installed certificate or revert an existing endpoint. + +== Example + +[source,yaml] +---- +cloud_provider: azure +host_ocp4_deploy_installation_method: openshift_install +workloads: +- agnosticd.core_workloads.ocp4_workload_cert_manager + +# Ingress is the default; opt into API replacement only when needed. +ocp4_workload_cert_manager_install_ingress_certificates: true +ocp4_workload_cert_manager_install_api_certificates: false + +# First validate issuance with the staging CA (certificates are untrusted). +# Omit this override for production Let's Encrypt certificates. +ocp4_workload_cert_manager_acme_url: https://acme-staging-v02.api.letsencrypt.org/directory + +# Optional dedicated DNS identity. Supply its password through Vault/secrets. +# ocp4_workload_cert_manager_azure_client_id: +# ocp4_workload_cert_manager_azure_client_secret: +# ocp4_workload_cert_manager_azure_tenant_id: +# ocp4_workload_cert_manager_azure_subscription_id: +# ocp4_workload_cert_manager_azure_resource_group_name: +# ocp4_workload_cert_manager_azure_hostedzone_name: .azure.redhatworkshops.io +---- + +== Secrets, renewal and troubleshooting + +The client password is stored as `client-secret` in `cert-manager-azure-creds` in +namespace `cert-manager`. Rendering and applying that Secret uses `no_log`. +Protect access to the Secret and keep credentials valid for renewals. Both issuers +reference the same Secret. Updating its credentials and rerunning the workload +does not require creating a new service principal. Do not remove the credentials +or DNS permissions after initial issuance. + +Certificates retain the existing 90-day duration and 15-day renewal window; +cert-manager updates the same TLS Secrets referenced by ingress/API configuration. +After issuance, verify the served certificate. Test renewal with `cmctl renew` +and confirm the Certificate revision and served serial change. Operator installation, +retries and optional fallback CA behavior otherwise follow the existing role. +Removal of this workload is currently not implemented. + +For failures inspect `Certificate`, `CertificateRequest`, `Order` and `Challenge` +conditions, and controller logs. Verify zone delegation, DNS permissions, tenant, +subscription and the DNS resource group. A boundary failure is a configuration +error; changing ACME providers will not fix it. Avoid dumping Secrets or credential +variables while debugging. Live issuance and renewal create temporary Azure TXT +records and require explicit approval in this project. diff --git a/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml b/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml index 8b648810..2a782ea2 100644 --- a/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml +++ b/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml @@ -1,5 +1,7 @@ --- + - name: Create Azure credentials secret for cert manager kubernetes.core.k8s: state: present template: secret-azure-credentials.yaml.j2 + no_log: true diff --git a/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml b/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml new file mode 100644 index 00000000..5482c363 --- /dev/null +++ b/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml @@ -0,0 +1,50 @@ +--- + +- name: Validate public Azure DNS settings + ansible.builtin.assert: + that: + - lookup('vars', item) is string + - lookup('vars', item) | trim | length > 0 + fail_msg: "Required Azure DNS input {{ item }} is missing or empty" + loop: + - ocp4_workload_cert_manager_azure_client_id + - ocp4_workload_cert_manager_azure_environment + - ocp4_workload_cert_manager_azure_hostedzone_name + - ocp4_workload_cert_manager_azure_resource_group_name + - ocp4_workload_cert_manager_azure_subscription_id + - ocp4_workload_cert_manager_azure_tenant_id + +- name: Validate protected Azure DNS client secret + ansible.builtin.assert: + that: + - ocp4_workload_cert_manager_azure_client_secret is string + - ocp4_workload_cert_manager_azure_client_secret | length > 0 + fail_msg: Supply ocp4_workload_cert_manager_azure_client_secret or the Azure service principal password + no_log: true + +- name: Validate enabled certificate targets are nonempty hostnames + ansible.builtin.assert: + that: + - >- + not ocp4_workload_cert_manager_install_api_certificates | bool or + (_ocp4_workload_cert_manager_api_hostname is string and _ocp4_workload_cert_manager_api_hostname | length > 0) + - >- + not ocp4_workload_cert_manager_install_ingress_certificates | bool or + (_ocp4_workload_cert_manager_wildcard_domain is string and _ocp4_workload_cert_manager_wildcard_domain | length > 0) + fail_msg: Enabled certificates require openshift_api_url and/or openshift_cluster_ingress_domain + +- name: Validate enabled certificate targets belong to the Azure DNS zone + when: item | length > 0 + vars: + _ocp4_workload_cert_manager_dns_zone: "{{ ocp4_workload_cert_manager_azure_hostedzone_name | lower | regex_replace('[.]$', '') }}" + ansible.builtin.assert: + that: + - >- + (item | lower | regex_replace('[.]$', '')) == _ocp4_workload_cert_manager_dns_zone or + (item | lower | regex_replace('[.]$', '')).endswith('.' ~ _ocp4_workload_cert_manager_dns_zone) + fail_msg: >- + Certificate target {{ item }} is outside Azure DNS zone {{ ocp4_workload_cert_manager_azure_hostedzone_name }}. + Microsoft-managed ARO domains require separate custom-domain configuration; this integration targets Azure IPI. + loop: + - "{{ _ocp4_workload_cert_manager_api_hostname }}" + - "{{ _ocp4_workload_cert_manager_wildcard_domain }}" diff --git a/roles/ocp4_workload_cert_manager/tasks/workload.yml b/roles/ocp4_workload_cert_manager/tasks/workload.yml index 72848619..f64c799f 100644 --- a/roles/ocp4_workload_cert_manager/tasks/workload.yml +++ b/roles/ocp4_workload_cert_manager/tasks/workload.yml @@ -1,4 +1,19 @@ --- + + +- name: Set DNS facts for enabled certificate targets + ansible.builtin.set_fact: + _ocp4_workload_cert_manager_api_hostname: >- + {{ (openshift_api_url | urlsplit('hostname')) if ocp4_workload_cert_manager_install_api_certificates | bool else '' }} + _ocp4_workload_cert_manager_wildcard_domain: >- + {{ openshift_cluster_ingress_domain if ocp4_workload_cert_manager_install_ingress_certificates | bool else '' }} + + +- name: Validate Azure DNS inputs before installing the operator + when: ocp4_workload_cert_manager_cloud_provider == 'azure' + ansible.builtin.include_tasks: validate_azure.yml + + - name: Install Red Hat Cert Manager operator ansible.builtin.include_role: name: install_operator @@ -19,6 +34,7 @@ install_operator_catalogsource_image: "{{ ocp4_workload_cert_manager_catalog_snapshot_image | default('') }}" install_operator_catalogsource_image_tag: "{{ ocp4_workload_cert_manager_catalog_snapshot_image_tag | default('') }}" + - name: Update CertManager for AWS/GCP/Azure to use external DNS when: > ocp4_workload_cert_manager_cloud_provider in ["aws", "gcp", "azure", "acme-bifrost"] @@ -26,12 +42,6 @@ state: present template: certmanager.yaml.j2 -- name: Set DNS facts - ansible.builtin.set_fact: - _ocp4_workload_cert_manager_api_hostname: >- - {{ openshift_api_url | urlsplit('hostname') }} - _ocp4_workload_cert_manager_wildcard_domain: >- - {{ openshift_cluster_ingress_domain }} - name: Print API and wildcard domain ansible.builtin.debug: @@ -39,6 +49,7 @@ API: {{ _ocp4_workload_cert_manager_api_hostname }}, Wildcard Domain: *.{{ _ocp4_workload_cert_manager_wildcard_domain }} + - name: Wait until CertManager is ready kubernetes.core.k8s_info: api_version: operator.openshift.io/v1alpha1 @@ -52,18 +63,22 @@ status: "True" register: r_cert_manager + - name: Create ZeroSSL credentials secret for cert manager when: ocp4_workload_cert_manager_provider == "zerossl" or ocp4_workload_cert_manager_provider_fallback | default("") == "zerossl" kubernetes.core.k8s: state: present template: secret-zerossl-credentials.yaml.j2 + - name: Set up cloud provider specific prerequisites for cert manager ansible.builtin.include_tasks: "cert_manager_{{ ocp4_workload_cert_manager_cloud_provider }}.yml" + - name: Setup ACME Bifrost when: ocp4_workload_cert_manager_provider == "acme-bifrost" or ocp4_workload_cert_manager_provider_fallback == "acme-bifrost" block: + - name: Deploy ACME Bifrost webhook kubernetes.core.k8s: state: present @@ -73,6 +88,7 @@ delay: 30 until: r_webhook_acme_bifrost is success + - name: Wait for acme-bifrost-webhook deployment to be ready kubernetes.core.k8s_info: api_version: apps/v1 @@ -87,6 +103,7 @@ retries: 30 delay: 10 + - name: Wait for webhook APIService to be available kubernetes.core.k8s_info: api_version: apiregistration.k8s.io/v1 @@ -103,48 +120,75 @@ retries: 30 delay: 10 -- name: Set up ClusterIssuer and request certificates + +- name: Set up ClusterIssuer kubernetes.core.k8s: state: present - template: "{{ item }}" - loop: - - clusterissuer.yaml.j2 - - certificate-ingress.yaml.j2 - - certificate-api.yaml.j2 + template: clusterissuer.yaml.j2 register: r_clusterissuer retries: 10 delay: 30 until: r_clusterissuer is success + - name: Set up ClusterIssuer fallback when: ocp4_workload_cert_manager_provider_fallback | default("") != "" kubernetes.core.k8s: state: present template: "clusterissuer-fallback.yaml.j2" + +- name: Request ingress certificate + when: ocp4_workload_cert_manager_install_ingress_certificates | bool + kubernetes.core.k8s: + state: present + template: certificate-ingress.yaml.j2 + register: r_certificate_ingress_request + retries: 10 + delay: 30 + until: r_certificate_ingress_request is success + + +- name: Request API certificate + when: ocp4_workload_cert_manager_install_api_certificates | bool + kubernetes.core.k8s: + state: present + template: certificate-api.yaml.j2 + register: r_certificate_api_request + retries: 10 + delay: 30 + until: r_certificate_api_request is success + + - name: Install Ingress controller certificate when: ocp4_workload_cert_manager_install_ingress_certificates | bool block: + - name: Run ingress controller certificate check task ansible.builtin.include_tasks: cert_manager_ingress_cert_check.yml with_sequence: start=0 end={{ ocp4_workload_cert_manager_ingress_cert_max_retries }} + - name: Update Ingress controller to use certificate when: _ocp4_workload_cert_manager_ingress_cert_ready | default(false) | bool kubernetes.core.k8s: state: present template: default-ingress-controller.yaml.j2 + - name: Install API Server certificate when: ocp4_workload_cert_manager_install_api_certificates | bool block: + - name: Run API certificate check task ansible.builtin.include_tasks: cert_manager_api_cert_check.yml with_sequence: start=0 end={{ ocp4_workload_cert_manager_api_cert_max_retries }} + - name: API Certificate successfull when: _ocp4_workload_cert_manager_api_cert_ready | default(false) | bool block: + - name: Update API server to use certificate kubernetes.core.k8s: state: present @@ -154,10 +198,12 @@ # restart with certificates (due to AWS # Load Balancer). Can't really check the cluster operator because once the updates have rolled out # subsequent checks will fail. :-(. Need to just sleep. + - name: Wait for Cluster Operator kube-apiserver to finish rolling out ansible.builtin.pause: minutes: "{{ ocp4_workload_cert_manager_wait_after_api_cert_setup | int }}" + - name: Find all Kube configs become: true ansible.builtin.find: @@ -171,6 +217,7 @@ recurse: true register: r_config_files + - name: Fix Kube configs become: true ansible.builtin.replace: @@ -178,6 +225,7 @@ regexp: "^ +certificate-authority-data:.*" loop: "{{ r_config_files.files }}" + - name: Make sure API calls succeed kubernetes.core.k8s_info: api_version: config.openshift.io/v1 diff --git a/roles/ocp4_workload_cert_manager/templates/clusterissuer-fallback.yaml.j2 b/roles/ocp4_workload_cert_manager/templates/clusterissuer-fallback.yaml.j2 index 8cd289c3..b84b8210 100644 --- a/roles/ocp4_workload_cert_manager/templates/clusterissuer-fallback.yaml.j2 +++ b/roles/ocp4_workload_cert_manager/templates/clusterissuer-fallback.yaml.j2 @@ -20,9 +20,17 @@ spec: {% endif %} solvers: - selector: +{% if not (ocp4_workload_cert_manager_install_api_certificates | bool or ocp4_workload_cert_manager_install_ingress_certificates | bool) %} + {} +{% else %} dnsZones: +{% if ocp4_workload_cert_manager_install_api_certificates | bool %} - {{ _ocp4_workload_cert_manager_api_hostname }} +{% endif %} +{% if ocp4_workload_cert_manager_install_ingress_certificates | bool %} - {{ _ocp4_workload_cert_manager_wildcard_domain }} +{% endif %} +{% endif %} dns01: {% if ocp4_workload_cert_manager_cloud_provider == "aws" and ocp4_workload_cert_manager_provider != "acme-bifrost" %} route53: @@ -43,15 +51,15 @@ spec: {% endif %} {% if ocp4_workload_cert_manager_cloud_provider == "azure" %} azureDNS: - clientID: {{ ocp4_workload_cert_manager_azure_client_id }} + clientID: {{ ocp4_workload_cert_manager_azure_client_id | to_json }} clientSecretSecretRef: name: cert-manager-azure-creds key: client-secret - environment: AzurePublicCloud - hostedZoneName: {{ ocp4_workload_cert_manager_azure_hostedzone_name }} - resourceGroupName: {{ ocp4_workload_cert_manager_azure_resource_group_name }} - subscriptionID: {{ ocp4_workload_cert_manager_azure_subscription_id }} - tenantID: {{ ocp4_workload_cert_manager_azure_tenant_id }} + environment: {{ ocp4_workload_cert_manager_azure_environment | to_json }} + hostedZoneName: {{ ocp4_workload_cert_manager_azure_hostedzone_name | to_json }} + resourceGroupName: {{ ocp4_workload_cert_manager_azure_resource_group_name | to_json }} + subscriptionID: {{ ocp4_workload_cert_manager_azure_subscription_id | to_json }} + tenantID: {{ ocp4_workload_cert_manager_azure_tenant_id | to_json }} {% endif %} {% if ocp4_workload_cert_manager_provider == "acme-bifrost" %} webhook: diff --git a/roles/ocp4_workload_cert_manager/templates/clusterissuer.yaml.j2 b/roles/ocp4_workload_cert_manager/templates/clusterissuer.yaml.j2 index c72329b6..f852ecc0 100644 --- a/roles/ocp4_workload_cert_manager/templates/clusterissuer.yaml.j2 +++ b/roles/ocp4_workload_cert_manager/templates/clusterissuer.yaml.j2 @@ -20,9 +20,17 @@ spec: {% endif %} solvers: - selector: +{% if not (ocp4_workload_cert_manager_install_api_certificates | bool or ocp4_workload_cert_manager_install_ingress_certificates | bool) %} + {} +{% else %} dnsZones: +{% if ocp4_workload_cert_manager_install_api_certificates | bool %} - {{ _ocp4_workload_cert_manager_api_hostname }} +{% endif %} +{% if ocp4_workload_cert_manager_install_ingress_certificates | bool %} - {{ _ocp4_workload_cert_manager_wildcard_domain }} +{% endif %} +{% endif %} dns01: {% if ocp4_workload_cert_manager_cloud_provider == "aws" and ocp4_workload_cert_manager_provider != "acme-bifrost" %} route53: @@ -43,15 +51,15 @@ spec: {% endif %} {% if ocp4_workload_cert_manager_cloud_provider == "azure" %} azureDNS: - clientID: {{ ocp4_workload_cert_manager_azure_client_id }} + clientID: {{ ocp4_workload_cert_manager_azure_client_id | to_json }} clientSecretSecretRef: name: cert-manager-azure-creds key: client-secret - environment: AzurePublicCloud - hostedZoneName: {{ ocp4_workload_cert_manager_azure_hostedzone_name }} - resourceGroupName: {{ ocp4_workload_cert_manager_azure_resource_group_name }} - subscriptionID: {{ ocp4_workload_cert_manager_azure_subscription_id }} - tenantID: {{ ocp4_workload_cert_manager_azure_tenant_id }} + environment: {{ ocp4_workload_cert_manager_azure_environment | to_json }} + hostedZoneName: {{ ocp4_workload_cert_manager_azure_hostedzone_name | to_json }} + resourceGroupName: {{ ocp4_workload_cert_manager_azure_resource_group_name | to_json }} + subscriptionID: {{ ocp4_workload_cert_manager_azure_subscription_id | to_json }} + tenantID: {{ ocp4_workload_cert_manager_azure_tenant_id | to_json }} {% endif %} {% if ocp4_workload_cert_manager_provider == "acme-bifrost" %} webhook: diff --git a/roles/ocp4_workload_cert_manager/templates/secret-azure-credentials.yaml.j2 b/roles/ocp4_workload_cert_manager/templates/secret-azure-credentials.yaml.j2 index 081d3517..dcc6258a 100644 --- a/roles/ocp4_workload_cert_manager/templates/secret-azure-credentials.yaml.j2 +++ b/roles/ocp4_workload_cert_manager/templates/secret-azure-credentials.yaml.j2 @@ -6,4 +6,4 @@ metadata: namespace: cert-manager type: Opaque stringData: - client-secret: {{ azure_password }} + client-secret: {{ ocp4_workload_cert_manager_azure_client_secret | to_json }} diff --git a/tests/static/tox.ini b/tests/static/tox.ini index 608a2fdb..0908da48 100644 --- a/tests/static/tox.ini +++ b/tests/static/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = yamllint, ansible-lint +envlist = yamllint, ansible-lint, cert-manager skipsdist = True skip_missing_interpreters = True @@ -16,3 +16,12 @@ changedir = {toxinidir}/../.. commands = ansible-galaxy collection install -r {toxinidir}/collections-requirements.yml --force ansible-lint + +# Offline regression checks: writes synthetic manifests only, no cloud/cluster IO. +[testenv:cert-manager] +deps = + ansible-core + PyYAML + Jinja2 +changedir = {toxinidir}/../.. +commands = python -m unittest discover -s tests/unit -p test_cert_manager_azure.py -v diff --git a/tests/unit/test_cert_manager_azure.py b/tests/unit/test_cert_manager_azure.py new file mode 100644 index 00000000..1ac2cd53 --- /dev/null +++ b/tests/unit/test_cert_manager_azure.py @@ -0,0 +1,163 @@ +"""Offline Ansible/template behavior; no Kubernetes or Azure operations.""" +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +import jinja2 +import yaml + +ROOT = Path(__file__).resolve().parents[2] +ROLE = ROOT / 'roles/ocp4_workload_cert_manager' +PREFIX = 'ocp4_workload_cert_manager_' +AZ = PREFIX + 'azure_' +SECRET = 'synthetic: "quoted" # secret\nsecond line' + + +class AzureCertManagerTests(unittest.TestCase): + def test_issuer_templates_preserve_other_solvers(self): + defaults = yaml.safe_load((ROLE / 'defaults/main.yml').read_text()) + env = jinja2.Environment(loader=jinja2.FileSystemLoader(ROLE / 'templates'), + undefined=jinja2.StrictUndefined) + env.filters.update(bool=bool, to_json=json.dumps) + for provider, solver in [('aws', 'route53'), ('gcp', 'cloudDNS'), ('azure', 'azureDNS')]: + for fallback in (False, True): + with self.subTest(provider=provider, fallback=fallback): + values = dict(defaults) + values.update({PREFIX + 'cloud_provider': provider, + PREFIX + 'provider_fallback': 'letsencrypt', + PREFIX + 'acme_url_fallback': 'https://example.test/acme', + PREFIX + 'aws_region': 'us-east-1', PREFIX + 'aws_access_key_id': 'fake', + PREFIX + 'gcp_project_id': 'fake-project', 'guid': 'test', + '_ocp4_workload_cert_manager_hostedzoneid': 'fake-zone', + '_ocp4_workload_cert_manager_api_hostname': 'api.test.example.com', + '_ocp4_workload_cert_manager_wildcard_domain': 'apps.test.example.com'}) + values.update({AZ + key: value for key, value in dict( + client_id='fake-app', environment='AzureUSGovernmentCloud', + hostedzone_name='example.com', resource_group_name='dns', + subscription_id='fake-sub', tenant_id='fake-tenant').items()}) + filename = 'clusterissuer-fallback.yaml.j2' if fallback else 'clusterissuer.yaml.j2' + document = yaml.safe_load(env.get_template(filename).render(values)) + dns = document['spec']['acme']['solvers'][0]['dns01'] + self.assertEqual(list(dns), [solver]) + if provider == 'azure': + self.assertEqual(dns[solver]['environment'], 'AzureUSGovernmentCloud') + self.assertEqual(dns[solver]['clientSecretSecretRef']['key'], 'client-secret') + + def test_real_ansible_defaults_validation_and_certificate_selection(self): + """Execute production task conditions, replacing external writes with local files.""" + with tempfile.TemporaryDirectory(prefix='cert-manager-test-') as directory: + tmp = Path(directory) + target = tmp / 'collections/ansible_collections/agnosticd/core_workloads/roles/ocp4_workload_cert_manager' + shutil.copytree(ROLE, target) + tasks = yaml.safe_load((ROLE / 'tasks/workload.yml').read_text()) + selected = [] + for task in tasks: + if task['name'] == 'Install Ingress controller certificate': + break + if task['name'] == 'Install Red Hat Cert Manager operator': + selected.append({'name': task['name'], 'ansible.builtin.copy': { + 'dest': '{{ test_output }}/operator', 'content': 'installed', 'mode': 'u=rw,go='}}) + elif 'kubernetes.core.k8s' in task: + template = task['kubernetes.core.k8s']['template'] + replacement = {k: v for k, v in task.items() if k != 'kubernetes.core.k8s'} + replacement['ansible.builtin.copy'] = { + 'dest': '{{ test_output }}/' + template.replace('.j2', ''), + 'content': "{{ lookup('ansible.builtin.template', '" + template + "') }}", + 'mode': 'u=rw,go='} + replacement.update(retries=1, delay=0) + selected.append(replacement) + elif 'ansible.builtin.include_tasks' in task: + selected.append(task) + elif 'ansible.builtin.set_fact' in task: + selected.append(task) + (target / 'tasks/workload.yml').write_text(yaml.safe_dump(selected, sort_keys=False)) + secret = yaml.safe_load((ROLE / 'tasks/cert_manager_azure.yml').read_text())[0] + self.assertTrue(secret['no_log']) + secret.pop('kubernetes.core.k8s') + secret['ansible.builtin.copy'] = { + 'dest': '{{ test_output }}/secret.yaml', + 'content': "{{ lookup('ansible.builtin.template', 'secret-azure-credentials.yaml.j2') }}", + 'mode': 'u=rw,go='} + (target / 'tasks/cert_manager_azure.yml').write_text(yaml.safe_dump([secret], sort_keys=False)) + playbook = tmp / 'playbook.yml' + playbook.write_text(yaml.safe_dump([dict(hosts='bastion', connection='local', gather_facts=False, + roles=['agnosticd.core_workloads.ocp4_workload_cert_manager'])], sort_keys=False)) + canonical = dict(azure_service_principal_id='app', azure_service_principal_password=SECRET, + azure_subscription='subscription', azure_tenant='tenant', + azure_resource_group='dns', azure_dns_zone='example.com') + legacy = dict(azure_service_principal='app', azure_password=SECRET, + azure_subscription_id='subscription', azure_tenant='tenant', + az_dnszone_resource_group='dns', azure_user_domain='example.com') + explicit = {AZ + key: value for key, value in dict(client_id='app', client_secret=SECRET, + subscription_id='subscription', tenant_id='tenant', resource_group_name='dns', + hostedzone_name='example.com').items()} + normalized = dict(azure_auth=dict(app_id='app', password=SECRET, subscription_id='subscription', tenant='tenant'), + azure_settings=dict(dns_zone='example.com', sandbox_group='dns')) + v2_config = ROOT.parents[2] / 'agnosticd-v2/ansible/configs/openshift-cluster/azure/default_vars.yml' + config_mapping = {key: value for key, value in yaml.safe_load(v2_config.read_text()).items() + if key.startswith(AZ)} if v2_config.exists() else {} + if v2_config.exists(): + self.assertEqual(len(config_mapping), 6) + cases = [('canonical', canonical, True), ('legacy', legacy, True), + ('canonical-before-alias', dict(legacy, **canonical, azure_user_domain='wrong.test'), True), + ('explicit-overrides', dict(canonical, **explicit, azure_dns_zone='wrong.test'), True), + ('missing-secret', dict(canonical, azure_service_principal_password=''), False), + ('missing-client', dict(canonical, azure_service_principal_id=''), False), + ('outside-zone', dict(canonical, openshift_cluster_ingress_domain='apps.aroapp.io'), False), + ('suffix-boundary', dict(canonical, openshift_cluster_ingress_domain='notexample.com'), False), + ('case-trailing-dot', dict(canonical, azure_dns_zone='EXAMPLE.COM.'), True)] + if config_mapping: + cases.append(('controller-to-bastion', config_mapping, True)) + for ingress, api in ((True, False), (False, True), (True, True), (False, False)): + cases.append(('selection-' + str(ingress) + '-' + str(api), dict(canonical, **{ + PREFIX + 'install_ingress_certificates': ingress, PREFIX + 'install_api_certificates': api}), True)) + for label, overrides, success in cases: + with self.subTest(case=label): + output = tmp / label + output.mkdir() + variables = dict(ACTION='provision', cloud_provider='azure', test_output=str(output), + openshift_api_url='https://api.test.example.com:6443', + openshift_cluster_ingress_domain='apps.test.example.com', + ansible_python_interpreter=sys.executable) + variables.update({PREFIX + 'provider_fallback': 'letsencrypt', + PREFIX + 'acme_url_fallback': 'https://example.test/acme'}) + variables.update(overrides) + # Disabled endpoints need no hostname input, even if outside the zone. + if variables.get(PREFIX + 'install_api_certificates') is False: + variables.pop('openshift_api_url') + if variables.get(PREFIX + 'install_ingress_certificates') is False: + variables.pop('openshift_cluster_ingress_domain') + inventory = tmp / 'inventory.json' + inventory.write_text(json.dumps({'all': {'hosts': { + 'localhost': normalized, 'bastion': variables}}})) + environment = dict(os.environ, ANSIBLE_COLLECTIONS_PATH=str(tmp / 'collections'), + ANSIBLE_LOCAL_TEMP=str(tmp / 'local'), ANSIBLE_REMOTE_TEMP=str(tmp / 'remote')) + result = subprocess.run([sys.executable, '-m', 'ansible.cli.playbook', + '-i', str(inventory), str(playbook)], env=environment, text=True, + capture_output=True, timeout=60, check=False) + self.assertEqual(result.returncode == 0, success, result.stdout + result.stderr) + self.assertNotIn('synthetic:', result.stdout + result.stderr) + self.assertEqual((output / 'operator').exists(), success) + if not success: + self.assertFalse((output / 'secret.yaml').exists()) + continue + credentials = yaml.safe_load((output / 'secret.yaml').read_text()) + self.assertEqual(credentials['stringData']['client-secret'], SECRET) + for kind, enabled in [('ingress', variables.get(PREFIX + 'install_ingress_certificates', True)), + ('api', variables.get(PREFIX + 'install_api_certificates', False))]: + self.assertEqual((output / ('certificate-' + kind + '.yaml')).exists(), enabled) + for name in ['clusterissuer.yaml', 'clusterissuer-fallback.yaml']: + issuer = yaml.safe_load((output / name).read_text()) + solver = issuer['spec']['acme']['solvers'][0]['dns01']['azureDNS'] + self.assertEqual(solver['clientID'], 'app') + self.assertEqual(solver['subscriptionID'], 'subscription') + self.assertEqual(solver['clientSecretSecretRef']['name'], 'cert-manager-azure-creds') + + +if __name__ == '__main__': + unittest.main() From e0bf42d86b7180d82e6f26a245a1fd14e64d51ea Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Tue, 3 Nov 2026 17:09:43 +0100 Subject: [PATCH 2/3] Clean up --- .../defaults/main.yml | 46 +++---------------- .../tasks/cert_manager_azure.yml | 1 - .../tasks/validate_azure.yml | 1 - .../tasks/workload.yml | 27 ----------- 4 files changed, 6 insertions(+), 69 deletions(-) diff --git a/roles/ocp4_workload_cert_manager/defaults/main.yml b/roles/ocp4_workload_cert_manager/defaults/main.yml index 7ab1214b..6e93609a 100644 --- a/roles/ocp4_workload_cert_manager/defaults/main.yml +++ b/roles/ocp4_workload_cert_manager/defaults/main.yml @@ -81,11 +81,11 @@ ocp4_workload_cert_manager_gcp_credentials: "{{ gcp_credentials }}" # --------------------------------------------------------------- # Azure DNS service principal application/client ID (string). Explicit role inputs # override these defaults. Prefer canonical Azure names; retain legacy aliases. -ocp4_workload_cert_manager_azure_client_id: "{{ azure_service_principal_id | default(azure_service_principal | default('')) }}" +ocp4_workload_cert_manager_azure_client_id: "{{ azure_service_principal_id }}" # Azure DNS service principal password (secret string). Stored in a Kubernetes # Secret in cert-manager for issuance AND renewal. Never log this value. -ocp4_workload_cert_manager_azure_client_secret: "{{ azure_service_principal_password | default(azure_password | default('')) }}" +ocp4_workload_cert_manager_azure_client_secret: "{{ azure_service_principal_password }}" # Azure cloud environment recognized by cert-manager (string), used by both # primary and fallback AzureDNS solvers. Public Azure is the default. @@ -93,18 +93,18 @@ ocp4_workload_cert_manager_azure_environment: AzurePublicCloud # Existing publicly delegated Azure DNS zone (string, not a resource ID). # Enabled certificate targets must equal this zone or be beneath it. -ocp4_workload_cert_manager_azure_hostedzone_name: "{{ azure_dns_zone | default(azure_user_domain | default('')) }}" +ocp4_workload_cert_manager_azure_hostedzone_name: "{{ azure_dns_zone }}" # Resource group containing that DNS zone (string), NOT the cluster resource # group. The service principal needs DNS record write/delete permission here. -ocp4_workload_cert_manager_azure_resource_group_name: "{{ azure_resource_group | default(az_dnszone_resource_group | default('')) }}" +ocp4_workload_cert_manager_azure_resource_group_name: "{{ azure_resource_group }}" # Subscription containing the DNS zone (string). Canonical input then alias. -ocp4_workload_cert_manager_azure_subscription_id: "{{ azure_subscription | default(azure_subscription_id | default('')) }}" +ocp4_workload_cert_manager_azure_subscription_id: "{{ azure_subscription }}" # Tenant of the DNS service principal (string). An explicit role override may # supply a dedicated DNS identity independently of cluster provisioning. -ocp4_workload_cert_manager_azure_tenant_id: "{{ azure_tenant | default(azure_tenant_id | default('')) }}" +ocp4_workload_cert_manager_azure_tenant_id: "{{ azure_tenant }}" # --------------------------------------------------------------- # Operator settings @@ -118,37 +118,3 @@ ocp4_workload_cert_manager_catalog_snapshot_image: quay.io/rhpds/olm_snapshot_re ocp4_workload_cert_manager_catalog_snapshot_image_tag: v4.19_2025_07_21 # ocp4_workload_cert_manager_starting_csv: cert-manager-operator.v1.15.0 ocp4_workload_cert_manager_automatic_install_plan_approval: true - -# Internal results of enabled Certificate creation tasks; never supply as inputs. -r_certificate_ingress_request: "{{ undef(hint='Internal ingress certificate request result') }}" -r_certificate_api_request: "{{ undef(hint='Internal API certificate request result') }}" -# Task-local normalized Azure DNS zone used for label-boundary validation. -_ocp4_workload_cert_manager_dns_zone: "{{ undef(hint='Internal normalized Azure DNS zone') }}" - -# External Azure inputs consumed by the standalone-role defaults above. These -# stay undefined until supplied, so legacy aliases remain usable. In the v2 -# Azure config, normalized localhost facts supply the role-specific inputs. -# azure_service_principal_id: canonical application/client UUID (string). -azure_service_principal_id: "{{ undef(hint='Optional canonical Azure client ID') }}" -# azure_service_principal: legacy application/client UUID alias (string). -azure_service_principal: "{{ undef(hint='Optional legacy Azure client ID') }}" -# azure_service_principal_password: canonical service principal password (secret). -azure_service_principal_password: "{{ undef(hint='Optional canonical Azure client secret') }}" -# azure_password: legacy service principal password alias (secret). -azure_password: "{{ undef(hint='Optional legacy Azure client secret') }}" -# azure_dns_zone: canonical existing public DNS zone name (string). -azure_dns_zone: "{{ undef(hint='Optional canonical Azure DNS zone') }}" -# azure_user_domain: legacy existing public DNS zone name alias (string). -azure_user_domain: "{{ undef(hint='Optional legacy Azure DNS zone') }}" -# azure_resource_group: canonical existing DNS/sandbox resource group (string). -azure_resource_group: "{{ undef(hint='Optional canonical Azure DNS resource group') }}" -# az_dnszone_resource_group: legacy DNS resource group alias (string). -az_dnszone_resource_group: "{{ undef(hint='Optional legacy Azure DNS resource group') }}" -# azure_subscription: canonical subscription UUID containing the DNS zone (string). -azure_subscription: "{{ undef(hint='Optional canonical Azure subscription') }}" -# azure_subscription_id: legacy subscription UUID alias (string). -azure_subscription_id: "{{ undef(hint='Optional legacy Azure subscription') }}" -# azure_tenant: canonical DNS identity tenant UUID or domain (string). -azure_tenant: "{{ undef(hint='Optional canonical Azure tenant') }}" -# azure_tenant_id: alternate DNS identity tenant UUID or domain (string). -azure_tenant_id: "{{ undef(hint='Optional alternate Azure tenant') }}" diff --git a/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml b/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml index 2a782ea2..239e2fa2 100644 --- a/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml +++ b/roles/ocp4_workload_cert_manager/tasks/cert_manager_azure.yml @@ -1,5 +1,4 @@ --- - - name: Create Azure credentials secret for cert manager kubernetes.core.k8s: state: present diff --git a/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml b/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml index 5482c363..9e821701 100644 --- a/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml +++ b/roles/ocp4_workload_cert_manager/tasks/validate_azure.yml @@ -1,5 +1,4 @@ --- - - name: Validate public Azure DNS settings ansible.builtin.assert: that: diff --git a/roles/ocp4_workload_cert_manager/tasks/workload.yml b/roles/ocp4_workload_cert_manager/tasks/workload.yml index f64c799f..85c12263 100644 --- a/roles/ocp4_workload_cert_manager/tasks/workload.yml +++ b/roles/ocp4_workload_cert_manager/tasks/workload.yml @@ -1,6 +1,4 @@ --- - - - name: Set DNS facts for enabled certificate targets ansible.builtin.set_fact: _ocp4_workload_cert_manager_api_hostname: >- @@ -8,12 +6,10 @@ _ocp4_workload_cert_manager_wildcard_domain: >- {{ openshift_cluster_ingress_domain if ocp4_workload_cert_manager_install_ingress_certificates | bool else '' }} - - name: Validate Azure DNS inputs before installing the operator when: ocp4_workload_cert_manager_cloud_provider == 'azure' ansible.builtin.include_tasks: validate_azure.yml - - name: Install Red Hat Cert Manager operator ansible.builtin.include_role: name: install_operator @@ -34,7 +30,6 @@ install_operator_catalogsource_image: "{{ ocp4_workload_cert_manager_catalog_snapshot_image | default('') }}" install_operator_catalogsource_image_tag: "{{ ocp4_workload_cert_manager_catalog_snapshot_image_tag | default('') }}" - - name: Update CertManager for AWS/GCP/Azure to use external DNS when: > ocp4_workload_cert_manager_cloud_provider in ["aws", "gcp", "azure", "acme-bifrost"] @@ -42,14 +37,12 @@ state: present template: certmanager.yaml.j2 - - name: Print API and wildcard domain ansible.builtin.debug: msg: >- API: {{ _ocp4_workload_cert_manager_api_hostname }}, Wildcard Domain: *.{{ _ocp4_workload_cert_manager_wildcard_domain }} - - name: Wait until CertManager is ready kubernetes.core.k8s_info: api_version: operator.openshift.io/v1alpha1 @@ -63,18 +56,15 @@ status: "True" register: r_cert_manager - - name: Create ZeroSSL credentials secret for cert manager when: ocp4_workload_cert_manager_provider == "zerossl" or ocp4_workload_cert_manager_provider_fallback | default("") == "zerossl" kubernetes.core.k8s: state: present template: secret-zerossl-credentials.yaml.j2 - - name: Set up cloud provider specific prerequisites for cert manager ansible.builtin.include_tasks: "cert_manager_{{ ocp4_workload_cert_manager_cloud_provider }}.yml" - - name: Setup ACME Bifrost when: ocp4_workload_cert_manager_provider == "acme-bifrost" or ocp4_workload_cert_manager_provider_fallback == "acme-bifrost" block: @@ -88,7 +78,6 @@ delay: 30 until: r_webhook_acme_bifrost is success - - name: Wait for acme-bifrost-webhook deployment to be ready kubernetes.core.k8s_info: api_version: apps/v1 @@ -103,7 +92,6 @@ retries: 30 delay: 10 - - name: Wait for webhook APIService to be available kubernetes.core.k8s_info: api_version: apiregistration.k8s.io/v1 @@ -120,7 +108,6 @@ retries: 30 delay: 10 - - name: Set up ClusterIssuer kubernetes.core.k8s: state: present @@ -130,14 +117,12 @@ delay: 30 until: r_clusterissuer is success - - name: Set up ClusterIssuer fallback when: ocp4_workload_cert_manager_provider_fallback | default("") != "" kubernetes.core.k8s: state: present template: "clusterissuer-fallback.yaml.j2" - - name: Request ingress certificate when: ocp4_workload_cert_manager_install_ingress_certificates | bool kubernetes.core.k8s: @@ -148,7 +133,6 @@ delay: 30 until: r_certificate_ingress_request is success - - name: Request API certificate when: ocp4_workload_cert_manager_install_api_certificates | bool kubernetes.core.k8s: @@ -159,36 +143,29 @@ delay: 30 until: r_certificate_api_request is success - - name: Install Ingress controller certificate when: ocp4_workload_cert_manager_install_ingress_certificates | bool block: - - name: Run ingress controller certificate check task ansible.builtin.include_tasks: cert_manager_ingress_cert_check.yml with_sequence: start=0 end={{ ocp4_workload_cert_manager_ingress_cert_max_retries }} - - name: Update Ingress controller to use certificate when: _ocp4_workload_cert_manager_ingress_cert_ready | default(false) | bool kubernetes.core.k8s: state: present template: default-ingress-controller.yaml.j2 - - name: Install API Server certificate when: ocp4_workload_cert_manager_install_api_certificates | bool block: - - name: Run API certificate check task ansible.builtin.include_tasks: cert_manager_api_cert_check.yml with_sequence: start=0 end={{ ocp4_workload_cert_manager_api_cert_max_retries }} - - name: API Certificate successfull when: _ocp4_workload_cert_manager_api_cert_ready | default(false) | bool block: - - name: Update API server to use certificate kubernetes.core.k8s: state: present @@ -198,12 +175,10 @@ # restart with certificates (due to AWS # Load Balancer). Can't really check the cluster operator because once the updates have rolled out # subsequent checks will fail. :-(. Need to just sleep. - - name: Wait for Cluster Operator kube-apiserver to finish rolling out ansible.builtin.pause: minutes: "{{ ocp4_workload_cert_manager_wait_after_api_cert_setup | int }}" - - name: Find all Kube configs become: true ansible.builtin.find: @@ -217,7 +192,6 @@ recurse: true register: r_config_files - - name: Fix Kube configs become: true ansible.builtin.replace: @@ -225,7 +199,6 @@ regexp: "^ +certificate-authority-data:.*" loop: "{{ r_config_files.files }}" - - name: Make sure API calls succeed kubernetes.core.k8s_info: api_version: config.openshift.io/v1 From b4650347313b2ad334b35433db8ea5e55aebcdec Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Thu, 5 Nov 2026 16:27:01 +0100 Subject: [PATCH 3/3] Align cert-manager Azure tests with canonical inputs --- roles/ocp4_workload_cert_manager/defaults/main.yml | 4 ++-- tests/unit/test_cert_manager_azure.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/roles/ocp4_workload_cert_manager/defaults/main.yml b/roles/ocp4_workload_cert_manager/defaults/main.yml index 6e93609a..78c75722 100644 --- a/roles/ocp4_workload_cert_manager/defaults/main.yml +++ b/roles/ocp4_workload_cert_manager/defaults/main.yml @@ -80,7 +80,7 @@ ocp4_workload_cert_manager_gcp_credentials: "{{ gcp_credentials }}" # Settings for Azure # --------------------------------------------------------------- # Azure DNS service principal application/client ID (string). Explicit role inputs -# override these defaults. Prefer canonical Azure names; retain legacy aliases. +# override these defaults, which use the canonical Azure names. ocp4_workload_cert_manager_azure_client_id: "{{ azure_service_principal_id }}" # Azure DNS service principal password (secret string). Stored in a Kubernetes @@ -99,7 +99,7 @@ ocp4_workload_cert_manager_azure_hostedzone_name: "{{ azure_dns_zone }}" # group. The service principal needs DNS record write/delete permission here. ocp4_workload_cert_manager_azure_resource_group_name: "{{ azure_resource_group }}" -# Subscription containing the DNS zone (string). Canonical input then alias. +# Subscription containing the DNS zone (string). ocp4_workload_cert_manager_azure_subscription_id: "{{ azure_subscription }}" # Tenant of the DNS service principal (string). An explicit role override may diff --git a/tests/unit/test_cert_manager_azure.py b/tests/unit/test_cert_manager_azure.py index 1ac2cd53..d0b71d39 100644 --- a/tests/unit/test_cert_manager_azure.py +++ b/tests/unit/test_cert_manager_azure.py @@ -90,9 +90,6 @@ def test_real_ansible_defaults_validation_and_certificate_selection(self): canonical = dict(azure_service_principal_id='app', azure_service_principal_password=SECRET, azure_subscription='subscription', azure_tenant='tenant', azure_resource_group='dns', azure_dns_zone='example.com') - legacy = dict(azure_service_principal='app', azure_password=SECRET, - azure_subscription_id='subscription', azure_tenant='tenant', - az_dnszone_resource_group='dns', azure_user_domain='example.com') explicit = {AZ + key: value for key, value in dict(client_id='app', client_secret=SECRET, subscription_id='subscription', tenant_id='tenant', resource_group_name='dns', hostedzone_name='example.com').items()} @@ -103,8 +100,7 @@ def test_real_ansible_defaults_validation_and_certificate_selection(self): if key.startswith(AZ)} if v2_config.exists() else {} if v2_config.exists(): self.assertEqual(len(config_mapping), 6) - cases = [('canonical', canonical, True), ('legacy', legacy, True), - ('canonical-before-alias', dict(legacy, **canonical, azure_user_domain='wrong.test'), True), + cases = [('canonical', canonical, True), ('explicit-overrides', dict(canonical, **explicit, azure_dns_zone='wrong.test'), True), ('missing-secret', dict(canonical, azure_service_principal_password=''), False), ('missing-client', dict(canonical, azure_service_principal_id=''), False),