|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/pods/nodes-pods-short-term-auth.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[discrete] |
| 7 | +[id="pod-short-term-auth-gcp-deploy-pod_{context}"] |
| 8 | += Deploying customer workloads that authenticate with {gcp-wid-short} |
| 9 | + |
| 10 | +To use short-term authentication in your application, you must configure its related pods to use the {product-title} service account. |
| 11 | +Use of the {product-title} service account triggers the webhook to mutate the pods so they can impersonate the {gcp-short} service account. |
| 12 | + |
| 13 | +The following example demonstrates how to deploy a pod that uses the {product-title} service account and verify the configuration. |
| 14 | + |
| 15 | +.Prerequisites |
| 16 | + |
| 17 | +* Your {gcp-short} cluster is running {product-title} version 4.17.4 or later and uses {gcp-wid-short}. |
| 18 | +
|
| 19 | +* You have created a federated {gcp-short} service account. |
| 20 | +
|
| 21 | +* You have created an {product-title} service account for {gcp-short}. |
| 22 | +
|
| 23 | +.Procedure |
| 24 | + |
| 25 | +. To create a pod that authenticates with {gcp-wid-short}, create a deployment YAML file similar to the following example: |
| 26 | ++ |
| 27 | +.Sample deployment |
| 28 | +[source,yaml] |
| 29 | +---- |
| 30 | +apiVersion: apps/v1 |
| 31 | +kind: Deployment |
| 32 | +metadata: |
| 33 | + name: ubi9 |
| 34 | +spec: |
| 35 | + replicas: 1 |
| 36 | + selector: |
| 37 | + matchLabels: |
| 38 | + app: ubi9 |
| 39 | + template: |
| 40 | + metadata: |
| 41 | + labels: |
| 42 | + app: ubi9 |
| 43 | + spec: |
| 44 | + serviceAccountName: "<service_account_name>" <1> |
| 45 | + containers: |
| 46 | + - name: ubi |
| 47 | + image: 'registry.access.redhat.com/ubi9/ubi-micro:latest' |
| 48 | + command: |
| 49 | + - /bin/sh |
| 50 | + - '-c' |
| 51 | + - | |
| 52 | + sleep infinity |
| 53 | +---- |
| 54 | +<1> Specify the name of the {product-title} service account. |
| 55 | + |
| 56 | +. Apply the deployment file by running the following command: |
| 57 | ++ |
| 58 | +[source,terminal] |
| 59 | +---- |
| 60 | +$ oc apply -f deployment.yaml |
| 61 | +---- |
| 62 | + |
| 63 | +.Verification |
| 64 | + |
| 65 | +* To verify that a pod is using short-term authentication, run the following command: |
| 66 | ++ |
| 67 | +[source,terminal] |
| 68 | +---- |
| 69 | +$ oc get pods -o json | jq -r '.items[0].spec.containers[0].env[] | select(.name=="GOOGLE_APPLICATION_CREDENTIALS")' |
| 70 | +---- |
| 71 | ++ |
| 72 | +.Example output |
| 73 | +[source,terminal] |
| 74 | +---- |
| 75 | +{ "name": "GOOGLE_APPLICATION_CREDENTIALS", "value": "/var/run/secrets/workload-identity/federation.json" } |
| 76 | +---- |
| 77 | ++ |
| 78 | +The presence of the `GOOGLE_APPLICATION_CREDENTIALS` environment variable indicates a pod that authenticates with {gcp-wid-short}. |
| 79 | +
|
| 80 | +* To verify additional configuration details, examine the pod specification. |
| 81 | +The following example pod specifications show the environment variables and volume fields that the webhook mutates. |
| 82 | ++ |
| 83 | +-- |
| 84 | +.Example pod specification with the `direct` injection mode: |
| 85 | +[source,yaml] |
| 86 | +---- |
| 87 | +apiVersion: v1 |
| 88 | +kind: Pod |
| 89 | +metadata: |
| 90 | + name: app-x-pod |
| 91 | + namespace: service-a |
| 92 | +annotations: |
| 93 | + cloud.google.com/skip-containers: "init-first,sidecar" |
| 94 | + cloud.google.com/external-credentials-json: |- <1> |
| 95 | + { |
| 96 | + "type": "external_account", |
| 97 | + "audience": "//iam.googleapis.com/projects/<project_number>/locations/global/workloadIdentityPools/on-prem-kubernetes/providers/<identity_provider>", |
| 98 | + "subject_token_type": "urn:ietf:params:oauth:token-type:jwt", |
| 99 | + "token_url": "https://sts.googleapis.com/v1/token", |
| 100 | + "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/[email protected]:generateAccessToken", |
| 101 | + "credential_source": { |
| 102 | + "file": "/var/run/secrets/sts.googleapis.com/serviceaccount/token", |
| 103 | + "format": { |
| 104 | + "type": "text" |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +spec: |
| 109 | + serviceAccountName: app-x |
| 110 | + initContainers: |
| 111 | + - name: init-first |
| 112 | + image: container-image:version |
| 113 | + containers: |
| 114 | + - name: sidecar |
| 115 | + image: container-image:version |
| 116 | + - name: container-name |
| 117 | + image: container-image:version |
| 118 | + env: <2> |
| 119 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 120 | + value: /var/run/secrets/gcloud/config/federation.json |
| 121 | + - name: CLOUDSDK_COMPUTE_REGION |
| 122 | + value: asia-northeast1 |
| 123 | + volumeMounts: |
| 124 | + - name: gcp-iam-token |
| 125 | + readOnly: true |
| 126 | + mountPath: /var/run/secrets/sts.googleapis.com/serviceaccount |
| 127 | + - mountPath: /var/run/secrets/gcloud/config |
| 128 | + name: external-credential-config |
| 129 | + readOnly: true |
| 130 | + volumes: |
| 131 | + - name: gcp-iam-token |
| 132 | + projected: |
| 133 | + sources: |
| 134 | + - serviceAccountToken: |
| 135 | + audience: sts.googleapis.com |
| 136 | + expirationSeconds: 86400 |
| 137 | + path: token |
| 138 | + - downwardAPI: |
| 139 | + defaultMode: 288 |
| 140 | + items: |
| 141 | + - fieldRef: |
| 142 | + apiVersion: v1 |
| 143 | + fieldPath: metadata.annotations['cloud.google.com/external-credentials-json'] |
| 144 | + path: federation.json |
| 145 | + name: external-credential-config |
| 146 | +---- |
| 147 | +<1> The external credentials configuration generated by the webhook controller. |
| 148 | +The Kubernetes `downwardAPI` volume mounts the configuration into the container filesystem. |
| 149 | +<2> The webhook-injected environment variables for token-based authentication. |
| 150 | +-- |
0 commit comments