Skip to content

Commit a7a84c8

Browse files
committed
restrict access to gitlab group
1 parent b483d3a commit a7a84c8

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

README.md

Lines changed: 10 additions & 4 deletions
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+
> GitLab SaaS 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 GitLab group.
24+
2125
Create Workload Identity Pool and Provider:
2226

2327
```hcl
24-
# Create Workload Identity Pool Provider for GitLab
28+
# Create Workload Identity Pool Provider for GitLab and restrict access to GitLab group
2529
module "gitlab-wif" {
2630
source = "Cyclenerd/wif-gitlab/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 GitLab group
34+
attribute_condition = "assertion.namespace_path == '${var.gitlab_group}'"
2935
}
3036
3137
# Get the Workload Identity Pool Provider resource name for GitLab CI 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 GitLab CI
4450
data "google_service_account" "gitlab" {
45-
project = "your-project-id"
51+
project = var.project_id
4652
account_id = "existing-account-for-gitlab-ci"
4753
}
4854
4955
# Allow service account to login via WIF and only from GitLab repository (project path)
5056
module "gitlab-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.gitlab-wif.pool_name
5561
account_id = data.google_service_account.gitlab.account_id
5662
repository = "octo-org/octo-repo"

examples/gitlab-ci/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ With this example the following steps are executed and configured:
1616
<!-- BEGIN_TF_DOCS -->
1717

1818
```hcl
19-
# Create Workload Identity Pool Provider for GitLab
19+
# Create Workload Identity Pool Provider for GitLab and restrict access to GitLab group
2020
module "gitlab-wif" {
2121
source = "Cyclenerd/wif-gitlab/google"
2222
version = "~> 1.0.0"
2323
project_id = var.project_id
24+
# Restrict access to username or the name of a GitLab group
25+
attribute_condition = "assertion.namespace_path == '${var.gitlab_group}'"
2426
}
2527
2628
# Create new service account for GitLab CI
@@ -54,6 +56,7 @@ output "gitlab-workload-identity-provider" {
5456
| Name | Description | Type | Default | Required |
5557
|------|-------------|------|---------|:--------:|
5658
| <a name="input_gitlab_account_id"></a> [gitlab\_account\_id](#input\_gitlab\_account\_id) | The account id of the service account for GitLab CI | `string` | n/a | yes |
59+
| <a name="input_gitlab_group"></a> [gitlab\_group](#input\_gitlab\_group) | The GitLab group or user namespace (namespace path) | `string` | n/a | yes |
5760
| <a name="input_gitlab_repository"></a> [gitlab\_repository](#input\_gitlab\_repository) | The GitLab repository (project path) | `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/gitlab-ci/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Create Workload Identity Pool Provider for GitLab
1+
# Create Workload Identity Pool Provider for GitLab and restrict access to GitLab group
22
module "gitlab-wif" {
33
source = "Cyclenerd/wif-gitlab/google"
44
version = "~> 1.0.0"
55
project_id = var.project_id
6+
# Restrict access to username or the name of a GitLab group
7+
attribute_condition = "assertion.namespace_path == '${var.gitlab_group}'"
68
}
79

810
# Create new service account for GitLab CI
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
project_id = "your-project-id"
22
gitlab_account_id = "gitlab-ci"
3+
gitlab_group = "your-org-or-user"
34
gitlab_repository = "your-org-or-user/your-repo"

examples/gitlab-ci/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ variable "gitlab_account_id" {
88
description = "The account id of the service account for GitLab CI"
99
}
1010

11+
variable "gitlab_group" {
12+
type = string
13+
description = "The GitLab group or user namespace (namespace path)"
14+
}
15+
1116
variable "gitlab_repository" {
1217
type = string
1318
description = "The GitLab repository (project path)"

0 commit comments

Comments
 (0)