generated from validatedpatterns/multicloud-gitops
-
Notifications
You must be signed in to change notification settings - Fork 14
coco: initial integration for Confidential Containers and Trustee operators #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beraldoleal
wants to merge
5
commits into
validatedpatterns:main
Choose a base branch
from
beraldoleal:integration-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca4ab0e
coco: initial integration with ztvp
beraldoleal ba7829a
coco: add imperative job to configure x509pop
beraldoleal aed9433
coco: introducing the hello-coco app
beraldoleal 0ceb1b6
drop: disabling keycloak and qtodo apps
beraldoleal 67509bc
coco: update the values-secret template
beraldoleal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
|
|
||
| - name: Configure Azure NAT Gateway | ||
| become: false | ||
| connection: local | ||
| hosts: localhost | ||
| gather_facts: false | ||
| vars: | ||
| kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" | ||
| resource_prefix: "coco" | ||
| tasks: | ||
| - name: Get Azure credentials | ||
| kubernetes.core.k8s_info: | ||
| kind: Secret | ||
| namespace: openshift-cloud-controller-manager | ||
| name: azure-cloud-credentials | ||
| register: azure_credentials | ||
| retries: 20 | ||
| delay: 5 | ||
|
|
||
| - name: Get Azure configuration | ||
| kubernetes.core.k8s_info: | ||
| kind: ConfigMap | ||
| namespace: openshift-cloud-controller-manager | ||
| name: cloud-conf | ||
| register: azure_cloud_conf | ||
| retries: 20 | ||
| delay: 5 | ||
|
|
||
| - name: Set facts | ||
| ansible.builtin.set_fact: | ||
| azure_subscription_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subscriptionId'] }}" | ||
| azure_tenant_id: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['tenantId'] }}" | ||
| azure_resource_group: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetResourceGroup'] }}" | ||
| azure_client_id: "{{ azure_credentials.resources[0]['data']['azure_client_id'] | b64decode }}" | ||
| azure_client_secret: "{{ azure_credentials.resources[0]['data']['azure_client_secret'] | b64decode }}" | ||
| azure_vnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['vnetName'] }}" | ||
| azure_subnet: "{{ (azure_cloud_conf.resources[0]['data']['cloud.conf'] | from_json)['subnetName'] }}" | ||
| coco_public_ip_name: "{{ resource_prefix }}-pip" | ||
| coco_nat_gateway_name: "{{ resource_prefix }}-nat-gateway" | ||
| no_log: true | ||
|
|
||
| - name: Create Public IP for NAT Gateway | ||
| azure.azcollection.azure_rm_publicipaddress: | ||
| subscription_id: "{{ azure_subscription_id }}" | ||
| tenant: "{{ azure_tenant_id }}" | ||
| client_id: "{{ azure_client_id }}" | ||
| secret: "{{ azure_client_secret }}" | ||
| resource_group: "{{ azure_resource_group }}" | ||
| name: "{{ coco_public_ip_name }}" | ||
| sku: "standard" | ||
| allocation_method: "static" | ||
|
|
||
| - name: Retrieve Public IP for NAT Gateway | ||
| azure.azcollection.azure_rm_publicipaddress_info: | ||
| subscription_id: "{{ azure_subscription_id }}" | ||
| tenant: "{{ azure_tenant_id }}" | ||
| client_id: "{{ azure_client_id }}" | ||
| secret: "{{ azure_client_secret }}" | ||
| resource_group: "{{ azure_resource_group }}" | ||
| name: "{{ coco_public_ip_name }}" | ||
| register: coco_gw_public_ip | ||
|
|
||
| - name: Create NAT Gateway | ||
| azure.azcollection.azure_rm_natgateway: | ||
| subscription_id: "{{ azure_subscription_id }}" | ||
| tenant: "{{ azure_tenant_id }}" | ||
| client_id: "{{ azure_client_id }}" | ||
| secret: "{{ azure_client_secret }}" | ||
| resource_group: "{{ azure_resource_group }}" | ||
| name: "{{ coco_nat_gateway_name }}" | ||
| idle_timeout_in_minutes: 10 | ||
| sku: | ||
| name: standard | ||
| public_ip_addresses: | ||
| - "{{ coco_gw_public_ip.publicipaddresses[0].id }}" | ||
| register: coco_natgw | ||
|
|
||
| - name: Update the worker subnet to associate NAT gateway | ||
| azure.azcollection.azure_rm_subnet: | ||
| subscription_id: "{{ azure_subscription_id }}" | ||
| tenant: "{{ azure_tenant_id }}" | ||
| client_id: "{{ azure_client_id }}" | ||
| secret: "{{ azure_client_secret }}" | ||
| resource_group: "{{ azure_resource_group }}" | ||
| name: "{{ azure_subnet }}" | ||
| virtual_network_name: "{{ azure_vnet }}" | ||
| nat_gateway: "{{ coco_nat_gateway_name }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| azure-identity>=1.19.0 | ||
| azure-mgmt-core>=1.4.0 | ||
| azure-mgmt-managementgroups>=1.0.0 | ||
| azure-mgmt-network>=25.0.0 | ||
| azure-mgmt-resource>=23.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| --- | ||
| # Configure SPIRE Server to support x509pop node attestation for CoCo pods | ||
| # The Red Hat SPIRE Operator's SpireServer CRD does not expose x509pop plugin configuration | ||
| # This job patches the operator-generated ConfigMap and StatefulSet to add x509pop support | ||
| # | ||
| # IMPORTANT: This playbook enables "create-only mode" on the SpireServer CR to prevent | ||
| # the operator from reverting our manual patches. This is done via the annotation: | ||
| # ztwim.openshift.io/create-only: "true" | ||
| # | ||
| # NOTE: The create-only mode is enabled AFTER verifying the ConfigMap has the correct | ||
| # cluster name. This prevents a race condition where the operator hasn't fully reconciled | ||
| # the ConfigMap before we lock it. | ||
|
|
||
| - name: Configure SPIRE Server for x509pop attestation | ||
| become: false | ||
| connection: local | ||
| hosts: localhost | ||
| gather_facts: false | ||
| vars: | ||
| spire_namespace: "zero-trust-workload-identity-manager" | ||
| configmap_name: "spire-server" | ||
| statefulset_name: "spire-server" | ||
| ca_configmap_name: "spire-x509pop-ca" | ||
| ca_mount_path: "/run/spire/x509pop-ca" | ||
| tasks: | ||
| - name: Get SpireServer CR to determine expected cluster name | ||
| kubernetes.core.k8s_info: | ||
| api_version: operator.openshift.io/v1alpha1 | ||
| kind: SpireServer | ||
| name: cluster | ||
| namespace: "{{ spire_namespace }}" | ||
| register: spire_server_cr | ||
| retries: 30 | ||
| delay: 10 | ||
| until: spire_server_cr.resources | length > 0 | ||
|
|
||
| - name: Extract expected cluster name from SpireServer CR | ||
| ansible.builtin.set_fact: | ||
| expected_cluster_name: "{{ spire_server_cr.resources[0].spec.clusterName }}" | ||
|
|
||
| - name: Display expected cluster name | ||
| ansible.builtin.debug: | ||
| msg: "Expected cluster name from SpireServer CR: {{ expected_cluster_name }}" | ||
|
|
||
| - name: Wait for SPIRE Server ConfigMap with correct cluster name | ||
| kubernetes.core.k8s_info: | ||
| kind: ConfigMap | ||
| namespace: "{{ spire_namespace }}" | ||
| name: "{{ configmap_name }}" | ||
| register: spire_configmap | ||
| retries: 60 | ||
| delay: 5 | ||
| until: > | ||
| spire_configmap.resources | length > 0 and | ||
| (spire_configmap.resources[0].data['server.conf'] | from_json).plugins.NodeAttestor[0].k8s_psat.plugin_data.clusters[0][expected_cluster_name] is defined | ||
|
|
||
| - name: ConfigMap has correct cluster name | ||
| ansible.builtin.debug: | ||
| msg: "ConfigMap verified with correct cluster name: {{ expected_cluster_name }}" | ||
|
|
||
| - name: Get current SPIRE Server configuration | ||
| kubernetes.core.k8s_info: | ||
| kind: ConfigMap | ||
| namespace: "{{ spire_namespace }}" | ||
| name: "{{ configmap_name }}" | ||
| register: spire_config | ||
|
|
||
| - name: Parse server configuration | ||
| ansible.builtin.set_fact: | ||
| server_conf: "{{ spire_config.resources[0].data['server.conf'] | from_json }}" | ||
|
|
||
| - name: Check if x509pop already configured | ||
| ansible.builtin.set_fact: | ||
| x509pop_exists: "{{ server_conf.plugins.NodeAttestor | selectattr('x509pop', 'defined') | list | length > 0 }}" | ||
|
|
||
| - name: Add x509pop NodeAttestor plugin | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| definition: | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: "{{ configmap_name }}" | ||
| namespace: "{{ spire_namespace }}" | ||
| data: | ||
| server.conf: "{{ server_conf | combine({'plugins': {'NodeAttestor': server_conf.plugins.NodeAttestor + [{'x509pop': {'plugin_data': {'ca_bundle_path': '/run/spire/x509pop-ca/ca-bundle.pem'}}}]}}, recursive=True) | to_json }}" | ||
| when: not x509pop_exists | ||
|
|
||
| - name: Wait for SPIRE Server StatefulSet to exist | ||
| kubernetes.core.k8s_info: | ||
| kind: StatefulSet | ||
| namespace: "{{ spire_namespace }}" | ||
| name: "{{ statefulset_name }}" | ||
| register: spire_statefulset | ||
| retries: 30 | ||
| delay: 10 | ||
| until: spire_statefulset.resources | length > 0 | ||
|
|
||
| - name: Check if CA volume already mounted | ||
| ansible.builtin.set_fact: | ||
| ca_volume_exists: "{{ spire_statefulset.resources[0].spec.template.spec.volumes | selectattr('name', 'equalto', 'x509pop-ca') | list | length > 0 }}" | ||
|
|
||
| - name: Add CA volume to SPIRE Server StatefulSet | ||
| kubernetes.core.k8s: | ||
| state: patched | ||
| kind: StatefulSet | ||
| namespace: "{{ spire_namespace }}" | ||
| name: "{{ statefulset_name }}" | ||
| definition: | ||
| spec: | ||
| template: | ||
| spec: | ||
| volumes: | ||
| - name: x509pop-ca | ||
| configMap: | ||
| name: "{{ ca_configmap_name }}" | ||
| containers: | ||
| - name: spire-server | ||
| volumeMounts: | ||
| - name: x509pop-ca | ||
| mountPath: "{{ ca_mount_path }}" | ||
| readOnly: true | ||
| when: not ca_volume_exists | ||
|
|
||
| - name: Restart SPIRE Server to apply configuration | ||
| kubernetes.core.k8s: | ||
| state: absent | ||
| kind: Pod | ||
| namespace: "{{ spire_namespace }}" | ||
| label_selectors: | ||
| - app.kubernetes.io/name=server | ||
| when: (not x509pop_exists) or (not ca_volume_exists) | ||
|
|
||
| - name: Configuration status | ||
| ansible.builtin.debug: | ||
| msg: "{{ 'x509pop already configured' if (x509pop_exists and ca_volume_exists) else 'x509pop NodeAttestor plugin and CA volume mount configured successfully' }}" | ||
|
|
||
| - name: Enable create-only mode on SpireServer CR | ||
| ansible.builtin.debug: | ||
| msg: "Enabling create-only mode to prevent operator from reverting x509pop configuration" | ||
|
|
||
| - name: Set create-only annotation on SpireServer CR | ||
| kubernetes.core.k8s: | ||
| state: patched | ||
| api_version: operator.openshift.io/v1alpha1 | ||
| kind: SpireServer | ||
| name: cluster | ||
| namespace: "{{ spire_namespace }}" | ||
| definition: | ||
| metadata: | ||
| annotations: | ||
| ztwim.openshift.io/create-only: "true" | ||
|
|
||
| - name: Final status | ||
| ansible.builtin.debug: | ||
| msg: "x509pop configuration complete. Create-only mode enabled to preserve manual patches." | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sabre1041 - Could you have a look this. Give your comfort level given coco will be an optional feature right now?