-
Notifications
You must be signed in to change notification settings - Fork 18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e838384
coco: initial integration with ztvp
beraldoleal cfc9bea
coco: add imperative job to configure x509pop
beraldoleal f162f96
coco: introducing the hello-coco app
beraldoleal 97c2e35
coco: update the values-secret template
beraldoleal 651fd68
coco: add get-pcr.sh script for attestation measurements
beraldoleal 6e1f10e
coco: add get-secrets-coco.sh
beraldoleal 157d5f7
coco: adding confidential documentation
beraldoleal c937b96
coco: automate pull-secret via ESO cross-namespace
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 # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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,144 @@ | ||
| --- | ||
| # 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: The operator must have CREATE_ONLY_MODE=true env var set (via subscription | ||
| # config) to prevent it from reverting our manual patches. Without this, the operator | ||
| # continuously reconciles and overwrites x509pop changes. | ||
| # Note: In v0.2.0 (tech-preview) this was done via a CR annotation | ||
| # (ztwim.openshift.io/create-only). In v1.0.0 (GA) it changed to the env var. | ||
|
|
||
| - 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 ZeroTrustWorkloadIdentityManager CR to determine expected cluster name # noqa: syntax-check[unknown-module] | ||
| kubernetes.core.k8s_info: | ||
| api_version: operator.openshift.io/v1alpha1 | ||
| kind: ZeroTrustWorkloadIdentityManager | ||
| name: cluster | ||
| register: ztwim_cr | ||
| retries: 30 | ||
|
beraldoleal marked this conversation as resolved.
|
||
| delay: 10 | ||
| until: ztwim_cr.resources | length > 0 | ||
|
|
||
| - name: Extract expected cluster name from ZTWIM CR | ||
| ansible.builtin.set_fact: | ||
| expected_cluster_name: "{{ ztwim_cr.resources[0].spec.clusterName }}" | ||
|
|
||
| - name: Display expected cluster name | ||
| ansible.builtin.debug: | ||
| msg: "Expected cluster name from ZTWIM CR: {{ expected_cluster_name }}" | ||
|
|
||
| - name: Wait for SPIRE Server ConfigMap with correct cluster name # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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 # noqa: syntax-check[unknown-module] | ||
| 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: Final status | ||
| ansible.builtin.debug: | ||
| msg: "x509pop configuration complete. CREATE_ONLY_MODE env var on the operator prevents reverts." | ||
Oops, something went wrong.
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.
Flag for future work - We should create an issue to add this playbook to the VP ansible collection. @mhjacks