Skip to content

Commit b0a0dd0

Browse files
committed
OSDOCS-11383: GCP Workload ID webhook
1 parent 0cb8576 commit b0a0dd0

File tree

7 files changed

+483
-0
lines changed

7 files changed

+483
-0
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,8 @@ Topics:
25712571
File: nodes-pods-secrets
25722572
- Name: Providing sensitive data to pods by using an external secrets store
25732573
File: nodes-pods-secrets-store
2574+
- Name: Authenticating pods with short-term credentials
2575+
File: nodes-pods-short-term-auth
25742576
- Name: Creating and using config maps
25752577
File: nodes-pods-configmaps
25762578
- Name: Using Device Manager to make devices available to nodes

authentication/managing_cloud_provider_credentials/cco-short-term-creds.adoc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ include::modules/cco-short-term-creds-aws-olm.adoc[leveloffset=+2]
5757
.Additional resources
5858
* xref:../../operators/operator_sdk/token_auth/osdk-cco-aws-sts.adoc#osdk-cco-aws-sts[CCO-based workflow for OLM-managed Operators with {aws-short} {sts-short}]
5959

60+
// Content stub for later addition:
61+
////
62+
// Application support for AWS STS service account tokens
63+
// Extra context so module can be reused within assembly (unset in module)
64+
:context: aws
65+
// Attributes used in module with cloud-specific values (unset in module)
66+
:cloud-auth-first: {aws-short} {sts-first}
67+
:cloud-auth-short: {aws-short} {sts-short}
68+
include::modules/cco-short-term-creds-workloads.adoc[leveloffset=+2]
69+
70+
[role="_additional-resources"]
71+
.Additional resources
72+
* xr3f:../../nodes/pods/nodes-pods-short-term-auth.adoc#nodes-pods-short-term-auth-configuring-aws_nodes-pods-short-term-auth[Configuring {aws-short} {sts-short} authentication for pods on {aws-short}]
73+
74+
:context: cco-short-term-creds
75+
////
76+
6077
[id="cco-short-term-creds-gcp_{context}"]
6178
== {gcp-wid-short}
6279

@@ -82,6 +99,20 @@ include::modules/cco-short-term-creds-gcp-olm.adoc[leveloffset=+2]
8299
.Additional resources
83100
* xref:../../operators/operator_sdk/token_auth/osdk-cco-gcp.adoc#osdk-cco-gcp[CCO-based workflow for OLM-managed Operators with {gcp-wid-first}]
84101

102+
// Application support for GCP Workload Identity service account tokens
103+
// Extra context so module can be reused within assembly (unset in module)
104+
:context: gcp
105+
// Attributes used in module with cloud-specific values (unset in module)
106+
:cloud-auth-first: {gcp-wid-first}
107+
:cloud-auth-short: {gcp-wid-short}
108+
include::modules/cco-short-term-creds-workloads.adoc[leveloffset=+2]
109+
110+
[role="_additional-resources"]
111+
.Additional resources
112+
* xref:../../nodes/pods/nodes-pods-short-term-auth.adoc#nodes-pods-short-term-auth-configuring-gcp_nodes-pods-short-term-auth[Configuring {gcp-wid-short} authentication for applications on {gcp-short}]
113+
114+
:context: cco-short-term-creds
115+
85116
[id="cco-short-term-creds-azure_{context}"]
86117
== {entra-first}
87118

@@ -107,6 +138,23 @@ include::modules/cco-short-term-creds-azure-olm.adoc[leveloffset=+2]
107138
.Additional resources
108139
* xref:../../operators/operator_sdk/token_auth/osdk-cco-azure.adoc#osdk-cco-azure[CCO-based workflow for OLM-managed Operators with {entra-first}]
109140

141+
// Content stub for later addition:
142+
////
143+
// Application support for Microsoft Entra Workload ID service account tokens
144+
// Extra context so module can be reused within assembly (unset in module)
145+
:context: azure
146+
// Attributes used in module with cloud-specific values (unset in module)
147+
:cloud-auth-first: {entra-first}
148+
:cloud-auth-short: {entra-short}
149+
include::modules/cco-short-term-creds-workloads.adoc[leveloffset=+2]
150+
151+
[role="_additional-resources"]
152+
.Additional resources
153+
* xr3f:../../nodes/pods/nodes-pods-short-term-auth.adoc#nodes-pods-short-term-auth-configuring-azure_nodes-pods-short-term-auth[Configuring {entra-first} authentication for pods on {azure-short}]
154+
155+
:context: cco-short-term-creds
156+
////
157+
110158
[role="_additional-resources"]
111159
[id="additional-resources_{context}"]
112160
== Additional resources
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * authentication/managing_cloud_provider_credentials/cco-short-term-creds.adoc
4+
5+
:_mod-docs-content-type: CONCEPT
6+
[id="cco-short-term-creds-workloads_{context}"]
7+
= Application support for {cloud-auth-short} service account tokens
8+
9+
Applications in customer workloads on {product-title} clusters that use {cloud-auth-first} can authenticate by using {cloud-auth-short}.
10+
To use this authentication method with your applications, you must complete configuration steps on the cloud provider console and your {product-title} cluster.
11+
12+
// Unsetting attributes defined in authentication/managing_cloud_provider_credentials/cco-short-term-creds.adoc above include:: line
13+
:!context:
14+
:!cloud-auth-first:
15+
:!cloud-auth-full:
16+
:!cloud-auth-short:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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-cloud-sa_{context}"]
8+
= Creating a federated {gcp-short} service account
9+
10+
You can use the Google Cloud console to create a workload identity pool and provider and allow an {product-title} service account to impersonate a {gcp-short} service account.
11+
12+
.Prerequisites
13+
14+
* Your {gcp-short} cluster is running {product-title} version 4.17.4 or later and uses {gcp-wid-short}.
15+
16+
* You have access to the Google Cloud console as a user with privileges to manage Identity and Access Management (IAM) and workload identity configurations.
17+
18+
* You have created a Google Cloud project to use with your application.
19+
20+
.Procedure
21+
22+
. In the IAM configuration for your Google Cloud project, identify the identity pool and provider that the cluster uses for {gcp-wid-short} authentication.
23+
24+
. Grant permission for external identities to impersonate a {gcp-short} service account.
25+
With these permissions, an {product-title} service account can work as a federated workload identity.
26+
+
27+
For more information, see {gcp-short} documentation about link:https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds#service-account-impersonation[allowing your external workload to access Google Cloud resources].
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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-cluster-sa_{context}"]
8+
= Creating an {product-title} service account for {gcp-short}
9+
10+
You create an {product-title} service account and annotate it to impersonate a {gcp-short} service account.
11+
12+
.Prerequisites
13+
14+
* Your {gcp-short} cluster is running {product-title} version 4.17.4 or later and uses {gcp-wid-short}.
15+
16+
* You have created a federated {gcp-short} service account.
17+
18+
* You have access to the {oc-first} as a user with the `cluster-admin` role.
19+
20+
* You have access to the Google Cloud CLI (`gcloud`) as a user with privileges to manage Identity and Access Management (IAM) and workload identity configurations.
21+
22+
.Procedure
23+
24+
. Create an {product-title} service account to use for {gcp-wid-short} pod authentication by running the following command:
25+
+
26+
[source,terminal]
27+
----
28+
$ oc create serviceaccount <service_account_name>
29+
----
30+
31+
. Annotate the service account with the identity provider and {gcp-short} service account to impersonate by running the following command:
32+
+
33+
[source,terminal]
34+
----
35+
$ oc patch serviceaccount <service_account_name> -p '{"metadata": {"annotations": {"cloud.google.com/workload-identity-provider": "projects/<project_number>/locations/global/workloadIdentityPools/<identity_pool>/providers/<identity_provider>"}}}'
36+
----
37+
+
38+
Replace `<project_number>`, `<identity_pool>`, and `<identity_provider>` with the values for your configuration.
39+
+
40+
[NOTE]
41+
====
42+
For `<project_number>`, specify the Google Cloud project number, not the project ID.
43+
====
44+
45+
. Annotate the service account with the email address for the {gcp-short} service account by running the following command:
46+
+
47+
[source,terminal]
48+
----
49+
$ oc patch serviceaccount <service_account_name> -p '{"metadata": {"annotations": {"cloud.google.com/service-account-email": "<service_account_email>"}}}'
50+
----
51+
+
52+
Replace `<service_account_email>` with the email address for the {gcp-short} service account.
53+
+
54+
[TIP]
55+
====
56+
{gcp-short} service account email addresses typically use the format `<service_account_name>@<project_id>.iam.gserviceaccount.com`
57+
====
58+
59+
. Annotate the service account to use the `direct` external credentials configuration injection mode by running the following command:
60+
+
61+
[source,terminal]
62+
----
63+
$ oc patch serviceaccount <service_account_name> -p '{"metadata": {"annotations": {"cloud.google.com/injection-mode": "direct"}}}'
64+
----
65+
+
66+
In this mode, the Workload Identity Federation webhook controller directly generates the {gcp-short} external credentials configuration and injects them into the pod.
67+
68+
. Use the Google Cloud CLI (`gcloud`) to specify the permissions for the workload by running the following command:
69+
+
70+
[source,terminal]
71+
----
72+
$ gcloud projects add-iam-policy-binding <project_id> --member "<service_account_email>" --role "projects/<project_id>/roles/<role_for_workload_permissions>"
73+
----
74+
+
75+
Replace `<role_for_workload_permissions>` with the role for the workload.
76+
Specify a role that grants the permissions that your workload requires.
77+
78+
.Verification
79+
80+
* To verify the service account configuration, inspect the `ServiceAccount` manifest by running the following command:
81+
+
82+
[source,terminal]
83+
----
84+
$ oc get serviceaccount <service_account_name>
85+
----
86+
+
87+
In the following example, the `service-a/app-x` {product-title} service account can impersonate a {gcp-short} service account called `app-x`:
88+
+
89+
.Example output
90+
--
91+
[source,yaml]
92+
----
93+
apiVersion: v1
94+
kind: ServiceAccount
95+
metadata:
96+
name: app-x
97+
namespace: service-a
98+
annotations:
99+
cloud.google.com/workload-identity-provider: "projects/<project_number>/locations/global/workloadIdentityPools/<identity_pool>/providers/<identity_provider>" <1>
100+
cloud.google.com/service-account-email: "app-x@project.iam.googleapis.com"
101+
cloud.google.com/audience: "sts.googleapis.com" <2>
102+
cloud.google.com/token-expiration: "86400" <3>
103+
cloud.google.com/gcloud-run-as-user: "1000"
104+
cloud.google.com/injection-mode: "direct" <4>
105+
----
106+
<1> The workload identity provider for the service account of the cluster.
107+
<2> The allowed audience for the workload identity provider.
108+
<3> The token expiration time period in seconds.
109+
<4> The `direct` external credentials configuration injection mode.
110+
--
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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/app-x@project.iam.gserviceaccount.com: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

Comments
 (0)