@@ -345,6 +345,8 @@ These instructions use the [gcloud][gcloud] command-line tool.
345
345
1. Create a Workload Identity Pool:
346
346
347
347
```sh
348
+ # TODO: replace ${PROJECT_ID} with your value below.
349
+
348
350
gcloud iam workload-identity-pools create "github" \
349
351
--project="${PROJECT_ID}" \
350
352
--location="global" \
@@ -354,6 +356,8 @@ These instructions use the [gcloud][gcloud] command-line tool.
354
356
1. Get the full ID of the Workload Identity **Pool**:
355
357
356
358
```sh
359
+ # TODO: replace ${PROJECT_ID} with your value below.
360
+
357
361
gcloud iam workload-identity-pools describe "github" \
358
362
--project="${PROJECT_ID}" \
359
363
--location="global" \
@@ -368,29 +372,35 @@ These instructions use the [gcloud][gcloud] command-line tool.
368
372
369
373
1. Create a Workload Identity **Provider** in that pool:
370
374
375
+ **🛑 CAUTION!** Always add an Attribute Condition to restrict entry into the
376
+ Workload Identity Pool. You can further restrict access in IAM Bindings, but
377
+ always add a basic condition that restricts admission into the pool. A good
378
+ default option is to restrict admission based on your GitHub organization as
379
+ demonstrated below. Please see the [security
380
+ considerations][security-considerations] for more details.
381
+
371
382
```sh
383
+ # TODO: replace ${PROJECT_ID} and ${GITHUB_ORG} with your values below.
384
+
372
385
gcloud iam workload-identity-pools providers create-oidc "my-repo" \
373
386
--project="${PROJECT_ID}" \
374
387
--location="global" \
375
388
--workload-identity-pool="github" \
376
389
--display-name="My GitHub repo Provider" \
377
- --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
390
+ --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \
391
+ --attribute-condition="assertion.repository_owner == '${GITHUB_ORG}'" \
378
392
--issuer-uri="https://token.actions.githubusercontent.com"
379
393
```
380
394
381
- The attribute mappings map claims in the GitHub Actions JWT to assertions
382
- you can make about the request (like the repository or GitHub username of
383
- the principal invoking the GitHub Action). These can be used to further
384
- restrict the authentication using `--attribute-condition` flags.
385
-
386
- > [!IMPORTANT]
387
- >
388
- > You must map any claims in the incoming token to attributes before you can
389
- > assert on those attributes in a CEL expression or IAM policy!
395
+ > **❗️ IMPORTANT** You must map any claims in the incoming token to
396
+ > attributes before you can assert on those attributes in a CEL expression
397
+ > or IAM policy!
390
398
391
399
1. Extract the Workload Identity **Provider** resource name:
392
400
393
401
```sh
402
+ # TODO: replace ${PROJECT_ID} with your value below.
403
+
394
404
gcloud iam workload-identity-pools providers describe "my-repo" \
395
405
--project="${PROJECT_ID}" \
396
406
--location="global" \
@@ -408,12 +418,10 @@ These instructions use the [gcloud][gcloud] command-line tool.
408
418
workload_identity_provider: '...' # "projects/123456789/locations/global/workloadIdentityPools/github/providers/my-repo"
409
419
```
410
420
411
- > [!IMPORTANT]
412
- >
413
- > The `project_id` input is optional, but may be required by downstream
414
- > authentication systems such as the `gcloud` CLI. Unfortunately we cannot
415
- > extract the project ID from the Workload Identity Provider, since it
416
- > requires the project _number_.
421
+ > **❗️ IMPORTANT** The `project_id` input is optional, but may be required
422
+ > by downstream authentication systems such as the `gcloud` CLI.
423
+ > Unfortunately we cannot extract the project ID from the Workload Identity
424
+ > Provider, since it requires the project _number_.
417
425
>
418
426
> It is technically possible to convert a project _number_ into a project
419
427
> _ID_, but it requires permissions to call Cloud Resource Manager, and we
@@ -428,9 +436,14 @@ These instructions use the [gcloud][gcloud] command-line tool.
428
436
specific repository a secret in Google Secret Manager.
429
437
430
438
```sh
431
- # TODO(developer): Update this value to your GitHub repository.
432
- export REPO="username/name" # e.g. "google/chrome"
433
- export WORKLOAD_IDENTITY_POOL_ID="value/from/above" # e.g. "projects/123456789/locations/global/workloadIdentityPools/github"
439
+ # TODO: replace ${PROJECT_ID}, ${WORKLOAD_IDENTITY_POOL_ID}, and ${REPO}
440
+ # with your values below.
441
+ #
442
+ # ${REPO} is the full repo name including the parent GitHub organization,
443
+ # such as "my-org/my-repo".
444
+ #
445
+ # ${WORKLOAD_IDENTITY_POOL_ID} is the full pool id, such as
446
+ # "projects/123456789/locations/global/workloadIdentityPools/github".
434
447
435
448
gcloud secrets add-iam-policy-binding "my-secret" \
436
449
--project="${PROJECT_ID}" \
@@ -464,13 +477,17 @@ These instructions use the [gcloud][gcloud] command-line tool.
464
477
Service Account, take note of the email address and skip this step.
465
478
466
479
```sh
480
+ # TODO: replace ${PROJECT_ID} with your value below.
481
+
467
482
gcloud iam service-accounts create "my-service-account" \
468
483
--project "${PROJECT_ID}"
469
484
```
470
485
471
486
1. Create a Workload Identity Pool:
472
487
473
488
```sh
489
+ # TODO: replace ${PROJECT_ID} with your value below.
490
+
474
491
gcloud iam workload-identity-pools create "github" \
475
492
--project="${PROJECT_ID}" \
476
493
--location="global" \
@@ -480,6 +497,8 @@ These instructions use the [gcloud][gcloud] command-line tool.
480
497
1. Get the full ID of the Workload Identity **Pool**:
481
498
482
499
```sh
500
+ # TODO: replace ${PROJECT_ID} with your value below.
501
+
483
502
gcloud iam workload-identity-pools describe "github" \
484
503
--project="${PROJECT_ID}" \
485
504
--location="global" \
@@ -494,33 +513,42 @@ These instructions use the [gcloud][gcloud] command-line tool.
494
513
495
514
1. Create a Workload Identity **Provider** in that pool:
496
515
516
+ **🛑 CAUTION!** Always add an Attribute Condition to restrict entry into the
517
+ Workload Identity Pool. You can further restrict access in IAM Bindings, but
518
+ always add a basic condition that restricts admission into the pool. A good
519
+ default option is to restrict admission based on your GitHub organization as
520
+ demonstrated below. Please see the [security
521
+ considerations][security-considerations] for more details.
522
+
497
523
```sh
524
+ # TODO: replace ${PROJECT_ID} and ${GITHUB_ORG} with your values below.
525
+
498
526
gcloud iam workload-identity-pools providers create-oidc "my-repo" \
499
527
--project="${PROJECT_ID}" \
500
528
--location="global" \
501
529
--workload-identity-pool="github" \
502
530
--display-name="My GitHub repo Provider" \
503
- --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
531
+ --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \
532
+ --attribute-condition="assertion.repository_owner == '${GITHUB_ORG}'" \
504
533
--issuer-uri="https://token.actions.githubusercontent.com"
505
534
```
506
535
507
- The attribute mappings map claims in the GitHub Actions JWT to assertions
508
- you can make about the request (like the repository or GitHub username of
509
- the principal invoking the GitHub Action). These can be used to further
510
- restrict the authentication using `--attribute-condition` flags.
511
-
512
- > [!IMPORTANT]
513
- >
514
- > You must map any claims in the incoming token to attributes before you can
515
- > assert on those attributes in a CEL expression or IAM policy!**
536
+ > **❗️ IMPORTANT** You must map any claims in the incoming token to
537
+ > attributes before you can assert on those attributes in a CEL expression
538
+ > or IAM policy!
516
539
517
540
1. Allow authentications from the Workload Identity Pool to your Google Cloud
518
541
Service Account.
519
542
520
543
```sh
521
- # TODO(developer): Update this value to your GitHub repository.
522
- export REPO="username/name" # e.g. "google/chrome"
523
- export WORKLOAD_IDENTITY_POOL_ID="value/from/above" # e.g. "projects/123456789/locations/global/workloadIdentityPools/github"
544
+ # TODO: replace ${PROJECT_ID}, ${WORKLOAD_IDENTITY_POOL_ID}, and ${REPO}
545
+ # with your values below.
546
+ #
547
+ # ${REPO} is the full repo name including the parent GitHub organization,
548
+ # such as "my-org/my-repo".
549
+ #
550
+ # ${WORKLOAD_IDENTITY_POOL_ID} is the full pool id, such as
551
+ # "projects/123456789/locations/global/workloadIdentityPools/github".
524
552
525
553
gcloud iam service-accounts add-iam-policy-binding "my-service-account@${PROJECT_ID}.iam.gserviceaccount.com" \
526
554
--project="${PROJECT_ID}" \
@@ -535,6 +563,8 @@ These instructions use the [gcloud][gcloud] command-line tool.
535
563
1. Extract the Workload Identity **Provider** resource name:
536
564
537
565
```sh
566
+ # TODO: replace ${PROJECT_ID} with your value below.
567
+
538
568
gcloud iam workload-identity-pools providers describe "my-repo" \
539
569
--project="${PROJECT_ID}" \
540
570
--location="global" \
@@ -557,6 +587,8 @@ These instructions use the [gcloud][gcloud] command-line tool.
557
587
shows granting access to a secret in Google Secret Manager.
558
588
559
589
```sh
590
+ # TODO: replace ${PROJECT_ID} with your value below.
591
+
560
592
gcloud secrets add-iam-policy-binding "my-secret" \
561
593
--project="${PROJECT_ID}" \
562
594
--role="roles/secretmanager.secretAccessor" \
@@ -591,13 +623,17 @@ These instructions use the [gcloud][gcloud] command-line tool.
591
623
Service Account, take note of the email address and skip this step.
592
624
593
625
```sh
626
+ # TODO: replace ${PROJECT_ID} with your value below.
627
+
594
628
gcloud iam service-accounts create "my-service-account" \
595
629
--project "${PROJECT_ID}"
596
630
```
597
631
598
632
1. Create a Service Account Key JSON for the Service Account.
599
633
600
634
```sh
635
+ # TODO: replace ${PROJECT_ID} with your value below.
636
+
601
637
gcloud iam service-accounts keys create "key.json" \
602
638
--iam-account "my-service-account@${PROJECT_ID}.iam.gserviceaccount.com"
603
639
```
@@ -621,3 +657,4 @@ These instructions use the [gcloud][gcloud] command-line tool.
621
657
[github-perms]: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions
622
658
[map-external]: https://cloud.google.com/iam/docs/access-resources-oidc#impersonate
623
659
[wif]: https://cloud.google.com/iam/docs/workload-identity-federation
660
+ [security-considerations]: docs/SECURITY_CONSIDERATIONS.md
0 commit comments