Skip to content

Commit df20944

Browse files
committed
feat: add token_type variable. Support unique token URL iss
1 parent 0c8865a commit df20944

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

README.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
# Terraform Module: Hashicorp Vault GitHub OIDC <!-- omit in toc -->
22

3-
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/digitalocean/terraform-vault-github-oidc?style=flat-square)
4-
![GitHub](https://img.shields.io/github/license/digitalocean/terraform-vault-github-oidc?style=flat-square)
3+
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/digitalocean/terraform-vault-github-oidc)
4+
[![OIDC Tests](https://github.com/digitalocean/terraform-vault-github-oidc/actions/workflows/oidc_test.yaml/badge.svg)](https://github.com/digitalocean/terraform-vault-github-oidc/actions/workflows/oidc_test.yaml)
5+
![GitHub](https://img.shields.io/github/license/digitalocean/terraform-vault-github-oidc)
56
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6305/badge)](https://bestpractices.coreinfrastructure.org/projects/6305)
6-
![GitHub contributors](https://img.shields.io/github/contributors/digitalocean/terraform-vault-github-oidc?style=flat-square)
7-
![GitHub last commit](https://img.shields.io/github/last-commit/digitalocean/terraform-vault-github-oidc?style=flat-square)
7+
![GitHub contributors](https://img.shields.io/github/contributors/digitalocean/terraform-vault-github-oidc)
8+
![GitHub last commit](https://img.shields.io/github/last-commit/digitalocean/terraform-vault-github-oidc)
89

910
Terraform module to configure Vault for GitHub OIDC authentication from Action runners on GitHub.com or self-hosted GitHub Enterprise Server.
1011

1112
OIDC authentication allows us to bind GitHub repositories (and subcomponents of a repository, such as a branch, ref, or environment)
1213
to a Vault role without needing to manage actual credentials that require a lifecycle system, integration into repo-level
1314
GitHub Secrets, or other organizational glue.
1415

16+
Explore GitHub OIDC and HashiCorp Vault use cases with this hands-on workshop: <https://github.com/artis3n/course-vault-github-oidc>.
17+
1518
Reference documents that help with understanding the process:
1619
- <https://docs.github.com/en/enterprise-cloud@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault>
1720

1821
Once OIDC authentication is configured on a Vault server via this module, a GitHub repository can leverage
1922
[hashicorp/vault-action](https://github.com/hashicorp/vault-action) to retrieve secrets from Vault with GitHub OIDC authentication.
20-
No credential management needed!
23+
No secrets or credential management needed!
2124

2225
e.g.
2326

2427
```yml
2528
- name: Import Secrets
26-
uses: hashicorp/vault-action@v2.4.1
29+
uses: hashicorp/vault-action@v2
2730
id: secrets
2831
with:
2932
exportEnv: false
@@ -40,19 +43,21 @@ e.g.
4043
4144
- [Usage](#usage)
4245
- [Examples](#examples)
46+
- [Considerations for Enterprise Cloud organizations](#considerations-for-enterprise-cloud-organizations)
4347
- [Variables](#variables)
44-
- [oidc_bindings](#oidc_bindings)
45-
- [oidc_bindings.audience](#oidc_bindingsaudience)
46-
- [oidc_bindings.vault_role_name](#oidc_bindingsvault_role_name)
47-
- [oidc_bindings.bound_subject](#oidc_bindingsbound_subject)
48-
- [oidc_bindings.vault_policies](#oidc_bindingsvault_policies)
49-
- [oidc_bindings.user_claim](#oidc_bindingsuser_claim)
50-
- [oidc_bindings.additional_claims](#oidc_bindingsadditional_claims)
51-
- [oidc_bindings.ttl](#oidc_bindingsttl)
52-
- [default_ttl](#default_ttl)
53-
- [default_user_claim](#default_user_claim)
54-
- [oidc_auth_backend_path](#oidc_auth_backend_path)
55-
- [github_identity_provider](#github_identity_provider)
48+
- [oidc\_bindings](#oidc_bindings)
49+
- [oidc\_bindings.audience](#oidc_bindingsaudience)
50+
- [oidc\_bindings.vault\_role\_name](#oidc_bindingsvault_role_name)
51+
- [oidc\_bindings.bound\_subject](#oidc_bindingsbound_subject)
52+
- [oidc\_bindings.vault\_policies](#oidc_bindingsvault_policies)
53+
- [oidc\_bindings.user\_claim](#oidc_bindingsuser_claim)
54+
- [oidc\_bindings.additional\_claims](#oidc_bindingsadditional_claims)
55+
- [oidc\_bindings.ttl](#oidc_bindingsttl)
56+
- [default\_ttl](#default_ttl)
57+
- [default\_user\_claim](#default_user_claim)
58+
- [oidc\_auth\_backend\_path](#oidc_auth_backend_path)
59+
- [github\_identity\_provider](#github_identity_provider)
60+
- [token\_type](#token_type)
5661
- [Requirements](#requirements)
5762
- [Providers](#providers)
5863
- [Modules](#modules)
@@ -86,8 +91,6 @@ You can find several examples leveraging this module under `examples/`:
8691
- [Adding custom additional claims per OIDC binding](/examples/additional-claims)
8792
- [Leveraging this module on-prem with GitHub Enterprise Server](/examples/github-enterprise)
8893

89-
There is another example run in the CI suite at [`test/terratest/configure-oidc/main.tf`](test/terratest/configure-oidc/main.tf).
90-
9194
Basic example - one repo, separating secrets access by nonprod and prod pipelines.
9295

9396
```terraform
@@ -140,6 +143,12 @@ data "vault_policy_document" "deployment" {
140143
}
141144
```
142145

146+
## Considerations for Enterprise Cloud organizations
147+
148+
Enterprise Cloud organizations should strongly consider enabling the [Unique Token URL](https://docs.github.com/en/enterprise-cloud@latest/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#switching-to-a-unique-token-url) feature for their organization.
149+
150+
If they do so, they should set the `github_identity_provider` variable of this module to their enterprise's unique token URL.
151+
143152
## Variables
144153

145154
### oidc_bindings
@@ -297,13 +306,27 @@ You cannot pass in a Terraform reference to an existing backend.
297306
**Optional**
298307

299308
By default, this role will communicate with github.com for an OIDC JWT (`https://token.actions.githubusercontent.com`).
309+
310+
If you are an Enterprise Cloud customer, you should configure a [unique token URL](https://docs.github.com/en/enterprise-cloud@latest/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#switching-to-a-unique-token-url) and set this variable to your unique token URL.
311+
312+
`https://token.actions.githubusercontent.com/<enterpriseSlug>`
313+
300314
If you run GitHub Enterprise Server, you will need to configure your instance of GitHub as the identity provider and should modify this variable.
301315
This requires GitHub Enterprise Server version 3.5 or higher.
302316

303317
The format is: `https://HOSTNAME/_services/token`.
304318

305319
See <https://docs.github.com/en/enterprise-server@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#adding-the-identity-provider-to-hashicorp-vault>.
306320

321+
### token_type
322+
323+
**Optional**
324+
325+
The type of Vault token that should be generated.
326+
<https://developer.hashicorp.com/vault/api-docs/auth/jwt#token_type>
327+
328+
Because of the short TTLs and frequent use intended for authentication via this module, this module generates a [batch token](https://developer.hashicorp.com/vault/tutorials/tokens/batch-tokens) by default.
329+
307330
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
308331
## Requirements
309332

@@ -336,8 +359,9 @@ No modules.
336359
| <a name="input_oidc_bindings"></a> [oidc\_bindings](#input\_oidc\_bindings) | A list of OIDC JWT bindings between GitHub repos and Vault roles. For each entry, you must include:<br><br> `audience`: By default, this must be the URL of the repository owner (e.g. `https://github.com/digitalocean`). This can be customized with the `jwtGithubAudience` parameter in [hashicorp/vault-action](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#requesting-the-access-token) . This is the bound audience (`aud`) field from [GitHub's OIDC token](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token) .<br><br> `vault_role_name`: The name of the Vault role to generate under the OIDC auth backend.<br><br> `bound_subject`: This is what is set in the `sub` field from [GitHub's OIDC token](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token) . The bound subject can be constructed from various filters, such as a branch, tag, or specific [environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) . See [GitHub's documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#example-subject-claims) for examples.<br><br> `vault_policies`: A list of Vault policies you wish to grant to the generated token.<br><br> `user_claim`: **Optional**. This is how you want Vault to [uniquely identify](https://www.vaultproject.io/api/auth/jwt#user_claim) this client. This will be used as the name for the Identity entity alias created due to a successful login. This must be a field present in the [GitHub JWT token](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token) . Defaults to the `default_user_claim` variable if not provided. Consider the impact on [reusable workflows](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/using-openid-connect-with-reusable-workflows#how-the-token-works-with-reusable-workflows) if you are thinking of changing this value from the default.<br><br> `additional_claims`: **Optional**. Any additional `bound_claims` to configure for this role. Claim keys must match a value in [GitHub's OIDC token](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token) . Do not use this field for the `sub` claim. Use the `bound_subject` parameter instead.<br><br> `ttl`: **Optional**. The default incremental time-to-live for the generated token, in seconds. Defaults to the `default_ttl` value but can be individually specified per binding with this value. | <pre>list(object({<br> audience = string,<br> vault_role_name = string,<br> bound_subject = string,<br> vault_policies = set(string),<br> user_claim = optional(string),<br> additional_claims = optional(map(string)),<br> ttl = optional(number),<br> }))</pre> | n/a | yes |
337360
| <a name="input_default_ttl"></a> [default\_ttl](#input\_default\_ttl) | The default incremental time-to-live for generated tokens, in seconds. | `number` | `300` | no |
338361
| <a name="input_default_user_claim"></a> [default\_user\_claim](#input\_default\_user\_claim) | This is how you want Vault to [uniquely identify](https://www.vaultproject.io/api/auth/jwt#user_claim) this client. This will be used as the name for the Identity entity alias created due to a successful login. This must be a field present in the [GitHub OIDC token](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token) . Consider the impact on [reusable workflows](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/using-openid-connect-with-reusable-workflows#how-the-token-works-with-reusable-workflows) if you are thinking of changing this value from the default. | `string` | `"job_workflow_ref"` | no |
339-
| <a name="input_github_identity_provider"></a> [github\_identity\_provider](#input\_github\_identity\_provider) | The JWT authentication URL used for the GitHub OIDC trust configuration. This should not be modified unless you are running GitHub Enterprise Server, in which case you should provide a URL in the format: `https://HOSTNAME/_services/token`. This requires GitHub Enterprise Server version 3.5 or higher. See <https://docs.github.com/en/enterprise-server@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#adding-the-identity-provider-to-hashicorp-vault>. | `string` | `"https://token.actions.githubusercontent.com"` | no |
362+
| <a name="input_github_identity_provider"></a> [github\_identity\_provider](#input\_github\_identity\_provider) | The JWT authentication URL used for the GitHub OIDC trust configuration. If you are an Enteprise Cloud account, you should configure a [unique token URL](https://docs.github.com/en/enterprise-cloud@latest/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#switching-to-a-unique-token-url) and set the result on this variable. If you are an Enterprise Server organization, you should provide a URL in the format: `https://HOSTNAME/_services/token`. This requires GitHub Enterprise Server version 3.5 or higher. See <https://docs.github.com/en/enterprise-server@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#adding-the-identity-provider-to-hashicorp-vault>. | `string` | `"https://token.actions.githubusercontent.com"` | no |
340363
| <a name="input_oidc_auth_backend_path"></a> [oidc\_auth\_backend\_path](#input\_oidc\_auth\_backend\_path) | The path to mount the OIDC auth backend. | `string` | `"github-actions"` | no |
364+
| <a name="input_token_type"></a> [token\_type](#input\_token\_type) | The type of token to generate. This can be either `batch` or `service`. See <https://developer.hashicorp.com/vault/api-docs/auth/jwt#token_type> for more information. | `string` | `"batch"` | no |
341365

342366
## Outputs
343367

SECURITY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
| 1.x | :warning: |
88
| 2.x | :white_check_mark: |
99

10+
:x: : This version is no longer supported.
11+
1012
:warning: : Will patch critical security issues, but no longer actively developed.
1113

1214
:white_check_mark: : Actively supported
1315

1416
## Reporting a Vulnerability
1517

16-
Report any potential security issues via our Vulnerability Disclosure Program at: <https://hackerone.com/digitalocean>.
18+
This open source project is not eligible for bounty rewards, but we appreciate any disclosures that help us improve the security of our products.
19+
20+
To report a potential security issue, please [privately report a security vulnerability](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability).

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ resource "vault_jwt_auth_backend_role" "github_oidc_role" {
3737

3838
token_policies = each.value.vault_policies
3939
token_ttl = each.value.ttl != null ? each.value.ttl : var.default_ttl
40+
token_type = var.token_type
4041
}

test/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module "github_oidc" {
22
source = "../"
33

4+
github_identity_provider = "https://token.actions.githubusercontent.com/digitalocean"
5+
46
oidc_bindings = [
57
{
68
audience : "https://github.com/digitalocean",

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ variable "default_user_claim" {
1212

1313
variable "github_identity_provider" {
1414
type = string
15-
description = "The JWT authentication URL used for the GitHub OIDC trust configuration. This should not be modified unless you are running GitHub Enterprise Server, in which case you should provide a URL in the format: `https://HOSTNAME/_services/token`. This requires GitHub Enterprise Server version 3.5 or higher. See <https://docs.github.com/en/enterprise-server@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#adding-the-identity-provider-to-hashicorp-vault>."
15+
description = "The JWT authentication URL used for the GitHub OIDC trust configuration. If you are an Enteprise Cloud account, you should configure a [unique token URL](https://docs.github.com/en/enterprise-cloud@latest/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#switching-to-a-unique-token-url) and set the result on this variable. If you are an Enterprise Server organization, you should provide a URL in the format: `https://HOSTNAME/_services/token`. This requires GitHub Enterprise Server version 3.5 or higher. See <https://docs.github.com/en/enterprise-server@latest/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-hashicorp-vault#adding-the-identity-provider-to-hashicorp-vault>."
1616
default = "https://token.actions.githubusercontent.com"
1717
}
1818

@@ -52,3 +52,9 @@ variable "oidc_bindings" {
5252
5353
EOT
5454
}
55+
56+
variable "token_type" {
57+
type = string
58+
default = "batch"
59+
description = "The type of token to generate. This can be either `batch` or `service`. See <https://developer.hashicorp.com/vault/api-docs/auth/jwt#token_type> for more information."
60+
}

0 commit comments

Comments
 (0)