|
1 | | -# My Template |
| 1 | +# Google Cloud Workload Identity Pool and Provider for GitLab |
2 | 2 |
|
3 | | -This is my template repository to generate new repositories with the same directory structure and files. |
| 3 | +[](https://github.com/Cyclenerd/terraform-google-wif-gitlab#readme) |
| 4 | +[](https://github.com/Cyclenerd/terraform-google-wif-gitlab#readme) |
| 5 | +[](https://github.com/Cyclenerd/terraform-google-wif-gitlab/actions/workflows/ci.yml) |
| 6 | +[](https://github.com/Cyclenerd/google-cloud-pricing-cost-calculator/blob/master/LICENSE) |
4 | 7 |
|
5 | | -1. Replace `template` with new repo name (<kbd>Crtl</kbd>+<kbd>Shift</kbd>+<kbd>H</kbd>) |
| 8 | +This Terraform module creates a Workload Identity Pool and Provider for GitLab. |
6 | 9 |
|
7 | | -[](https://github.com/Cyclenerd/template/actions/workflows/ci.yml) |
8 | | -[](https://github.com/Cyclenerd/template/blob/master/LICENSE) |
9 | | -[](https://www.reddit.com/r/googlecloud/comments/va0cc0/automating_cost_control_by_capping_google_cloud/) |
| 10 | +Service account keys are a security risk if compromised. |
| 11 | +Avoid service account keys and instead use the [Workload Identity Federation](https://cloud.google.com/iam/docs/configuring-workload-identity-federation). |
| 12 | +For more information about Workload Identity Federation and how to best authenticate service accounts on Google Cloud, please see my GitHub repo [Cyclenerd/google-workload-identity-federation](https://github.com/Cyclenerd/google-workload-identity-federation#readme). |
10 | 13 |
|
11 | | -## 🧑💻 Development |
| 14 | +> There is also a ready-to-use Terraform module for [GitHub](https://github.com/Cyclenerd/terraform-google-wif-github#readme). |
12 | 15 |
|
13 | | -[](https://gitpod.io/#https://github.com/Cyclenerd/template) |
| 16 | +## Example |
14 | 17 |
|
15 | | -### Requirements |
| 18 | +Create Workload Identity Pool and Provider: |
16 | 19 |
|
17 | | -* A |
18 | | -* B |
19 | | -* C |
| 20 | +```hcl |
| 21 | +# Create Workload Identity Pool Provider for GitLab |
| 22 | +module "gitlab-wif" { |
| 23 | + source = "Cyclenerd/wif-gitlab/google" |
| 24 | + version = "1.0.0" |
| 25 | + project_id = "your-project-id" |
| 26 | +} |
20 | 27 |
|
21 | | -## ❤️ Contributing |
| 28 | +# Get the Workload Identity Pool Provider resource name for GitLab CI configuration |
| 29 | +output "gitlab-workload-identity-provider" { |
| 30 | + description = "The Workload Identity Provider resource name" |
| 31 | + value = module.gitlab-wif.provider_name |
| 32 | +} |
| 33 | +``` |
22 | 34 |
|
23 | | -Have a patch that will benefit this project? |
24 | | -Awesome! Follow these steps to have it accepted. |
| 35 | +> An example of a working GitLab CI configuration (`.gitlab-ci.yml`) can be found [here](https://gitlab.com/Cyclenerd/google-workload-identity-federation-for-gitlab/-/blob/master/.gitlab-ci.yml). |
25 | 36 |
|
26 | | -1. Please read [how to contribute](CONTRIBUTING.md). |
27 | | -1. Fork this Git repository and make your changes. |
28 | | -1. Create a Pull Request. |
29 | | -1. Incorporate review feedback to your changes. |
30 | | -1. Accepted! |
| 37 | +Allow service account to login via Workload Identity Provider and limit login only from the GitLab repository (project path) `octo-org/octo-repo`: |
31 | 38 |
|
| 39 | +```hcl |
| 40 | +# Get existing service account for GitLab CI |
| 41 | +data "google_service_account" "gitlab" { |
| 42 | + project = "your-project-id" |
| 43 | + account_id = "existing-account-for-gitlab-ci" |
| 44 | +} |
32 | 45 |
|
33 | | -## 📜 License |
| 46 | +# Allow service account to login via WIF and only from GitLab repository (project path) |
| 47 | +module "gitlab-service-account" { |
| 48 | + source = "Cyclenerd/wif-service-account/google" |
| 49 | + version = "1.0.0" |
| 50 | + project_id = "your-project-id" |
| 51 | + pool_name = module.gitlab-wif.pool_name |
| 52 | + account_id = data.google_service_account.gitlab.account_id |
| 53 | + repository = "octo-org/octo-repo" |
| 54 | +} |
| 55 | +``` |
34 | 56 |
|
35 | | -All files in this repository are under the [Apache License, Version 2.0](LICENSE) unless noted otherwise. |
| 57 | +> Terraform module [`Cyclenerd/wif-service-account/google`](https://github.com/Cyclenerd/terraform-google-wif-service-account) is used. |
| 58 | +
|
| 59 | +👉 [**More examples**](https://github.com/Cyclenerd/terraform-google-wif-gitlab/tree/master/examples) |
| 60 | + |
| 61 | +## OIDC Token Attribute Mapping |
| 62 | + |
| 63 | +Attribute mapping: |
| 64 | + |
| 65 | +| Attribute | Claim | |
| 66 | +|------------------------|-------------------------------------------------------| |
| 67 | +| `google.subject` | `assertion.sub` | |
| 68 | +| `attribute.sub` | `assertion.sub` | |
| 69 | +| `attribute.actor` | `assertion.actor` | |
| 70 | +| `attribute.repository` | `assertion.project_path` (not `assertion.repository`) | |
| 71 | + |
| 72 | +<!-- BEGIN_TF_DOCS --> |
| 73 | +## Providers |
| 74 | + |
| 75 | +| Name | Version | |
| 76 | +|------|---------| |
| 77 | +| <a name="provider_google"></a> [google](#provider\_google) | >= 4.61.0 | |
36 | 78 |
|
37 | | -Please note: No warranty |
| 79 | +## Inputs |
| 80 | + |
| 81 | +| Name | Description | Type | Default | Required | |
| 82 | +|------|-------------|------|---------|:--------:| |
| 83 | +| <a name="input_allowed_audiences"></a> [allowed\_audiences](#input\_allowed\_audiences) | Workload Identity Pool Provider allowed audiences | `string` | `"https://gitlab.com"` | no | |
| 84 | +| <a name="input_issuer_uri"></a> [issuer\_uri](#input\_issuer\_uri) | Workload Identity Pool Provider issuer URI | `string` | `"https://gitlab.com"` | no | |
| 85 | +| <a name="input_pool_description"></a> [pool\_description](#input\_pool\_description) | Workload Identity Pool description | `string` | `"Workload Identity Pool for GitLab (Terraform managed)"` | no | |
| 86 | +| <a name="input_pool_disabled"></a> [pool\_disabled](#input\_pool\_disabled) | Workload Identity Pool disabled | `bool` | `false` | no | |
| 87 | +| <a name="input_pool_display_name"></a> [pool\_display\_name](#input\_pool\_display\_name) | Workload Identity Pool display name | `string` | `"gitlab.com"` | no | |
| 88 | +| <a name="input_pool_id"></a> [pool\_id](#input\_pool\_id) | Workload Identity Pool ID | `string` | `"gitlab-com"` | no | |
| 89 | +| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The ID of the project | `string` | n/a | yes | |
| 90 | +| <a name="input_provider_description"></a> [provider\_description](#input\_provider\_description) | Workload Identity Pool Provider description | `string` | `"Workload Identity Pool Provider for GitLab (Terraform managed)"` | no | |
| 91 | +| <a name="input_provider_disabled"></a> [provider\_disabled](#input\_provider\_disabled) | Workload Identity Pool Provider disabled | `bool` | `false` | no | |
| 92 | +| <a name="input_provider_display_name"></a> [provider\_display\_name](#input\_provider\_display\_name) | Workload Identity Pool Provider display name | `string` | `"gitlab.com OIDC"` | no | |
| 93 | +| <a name="input_provider_id"></a> [provider\_id](#input\_provider\_id) | Workload Identity Pool Provider ID | `string` | `"gitlab-com-oidc"` | no | |
| 94 | + |
| 95 | +## Outputs |
| 96 | + |
| 97 | +| Name | Description | |
| 98 | +|------|-------------| |
| 99 | +| <a name="output_pool_id"></a> [pool\_id](#output\_pool\_id) | Identifier for the pool | |
| 100 | +| <a name="output_pool_name"></a> [pool\_name](#output\_pool\_name) | The resource name for the pool | |
| 101 | +| <a name="output_pool_state"></a> [pool\_state](#output\_pool\_state) | State of the pool | |
| 102 | +| <a name="output_provider_id"></a> [provider\_id](#output\_provider\_id) | Identifier for the provider | |
| 103 | +| <a name="output_provider_name"></a> [provider\_name](#output\_provider\_name) | The resource name of the provider | |
| 104 | +| <a name="output_provider_state"></a> [provider\_state](#output\_provider\_state) | State of the provider | |
| 105 | +<!-- END_TF_DOCS --> |
| 106 | + |
| 107 | +## License |
| 108 | + |
| 109 | +All files in this repository are under the [Apache License, Version 2.0](LICENSE) unless noted otherwise. |
0 commit comments