Skip to content

Commit 6619c08

Browse files
committed
restrict access to github org
1 parent c6290e5 commit 6619c08

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ For more information about Workload Identity Federation and how to best authenti
1818
1919
## Example
2020

21+
> **Warning**
22+
> GitHub use a single issuer URL across all organizations and some of the claims embedded in OIDC tokens might not be unique to your organization.
23+
> To help protect against spoofing threats, you must use an attribute condition that restricts access to tokens issued by your GitHub organization.
24+
2125
Create Workload Identity Pool and Provider:
2226

2327
```hcl
24-
# Create Workload Identity Pool Provider for GitHub
28+
# Create Workload Identity Pool Provider for GitHub and restrict access to GitHub organization
2529
module "github-wif" {
2630
source = "Cyclenerd/wif-github/google"
2731
version = "~> 1.0.0"
28-
project_id = "your-project-id"
32+
project_id = var.project_id
33+
# Restrict access to username or the name of a GitHub organization
34+
attribute_condition = "assertion.repository_owner == '${var.github_organization}'"
2935
}
3036
3137
# Get the Workload Identity Pool Provider resource name for GitHub Actions configuration
@@ -42,15 +48,15 @@ Allow service account to login via Workload Identity Provider and limit login on
4248
```hcl
4349
# Get existing service account for GitHub Actions
4450
data "google_service_account" "github" {
45-
project = "your-project-id"
51+
project = var.project_id
4652
account_id = "existing-account-for-github-action"
4753
}
4854
4955
# Allow service account to login via WIF and only from GitHub repository
5056
module "github-service-account" {
5157
source = "Cyclenerd/wif-service-account/google"
5258
version = "~> 1.0.0"
53-
project_id = "your-project-id"
59+
project_id = var.project_id
5460
pool_name = module.github-wif.pool_name
5561
account_id = data.google_service_account.github.account_id
5662
repository = "octo-org/octo-repo"

examples/github-actions/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ With this example the following steps are executed and configured:
88

99
1. Create Workload Identity Pool Provider for GitHub
1010
1. Create new service account for GitHub Actions
11-
1. Allow login via Workload Identity Provider and limit login only from the GitHub repository
11+
1. Allow login via Workload Identity Provider and limit login only from the GitHub organization and repository
1212
1. Output the Workload Identity Pool Provider resource name for GitHub Actions configuration
1313

1414
> An example of a working GitHub Actions configuration can be found [here](https://github.com/Cyclenerd/google-workload-identity-federation/blob/master/.github/workflows/auth.yml).
1515
1616
<!-- BEGIN_TF_DOCS -->
1717

1818
```hcl
19-
# Create Workload Identity Pool Provider for GitHub
19+
# Create Workload Identity Pool Provider for GitHub and restrict access to GitHub organization
2020
module "github-wif" {
2121
source = "Cyclenerd/wif-github/google"
2222
version = "~> 1.0.0"
2323
project_id = var.project_id
24+
# Restrict access to username or the name of a GitHub organization
25+
attribute_condition = "assertion.repository_owner == '${var.github_organization}'"
2426
}
2527
2628
# Create new service account for GitHub Actions
@@ -54,6 +56,7 @@ output "github-workload-identity-provider" {
5456
| Name | Description | Type | Default | Required |
5557
|------|-------------|------|---------|:--------:|
5658
| <a name="input_github_account_id"></a> [github\_account\_id](#input\_github\_account\_id) | The account id of the service account for GitHub Actions | `string` | n/a | yes |
59+
| <a name="input_github_organization"></a> [github\_organization](#input\_github\_organization) | The username or the name of a GitHub organization | `string` | n/a | yes |
5760
| <a name="input_github_repository"></a> [github\_repository](#input\_github\_repository) | The GitHub repository | `string` | n/a | yes |
5861
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The ID of the project | `string` | n/a | yes |
5962

examples/github-actions/main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Create Workload Identity Pool Provider for GitHub
1+
# Create Workload Identity Pool Provider for GitHub and restrict access to GitHub organization
22
module "github-wif" {
33
source = "Cyclenerd/wif-github/google"
44
version = "~> 1.0.0"
55
project_id = var.project_id
6+
# Restrict access to username or the name of a GitHub organization
7+
attribute_condition = "assertion.repository_owner == '${var.github_organization}'"
68
}
79

810
# Create new service account for GitHub Actions

examples/github-actions/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ variable "github_account_id" {
88
description = "The account id of the service account for GitHub Actions"
99
}
1010

11+
variable "github_organization" {
12+
type = string
13+
description = "The username or the name of a GitHub organization"
14+
}
15+
1116
variable "github_repository" {
1217
type = string
1318
description = "The GitHub repository"

0 commit comments

Comments
 (0)