Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philips-labs/terraform-aws-github-oidc
Terraform module to setup OIDC with AWS and GH Actions
https://github.com/philips-labs/terraform-aws-github-oidc
aws github-actions hacktoberfest iac oidc terraform
Last synced: 3 months ago
JSON representation
Terraform module to setup OIDC with AWS and GH Actions
- Host: GitHub
- URL: https://github.com/philips-labs/terraform-aws-github-oidc
- Owner: philips-labs
- License: mit
- Created: 2022-02-22T14:08:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-12T14:24:30.000Z (4 months ago)
- Last Synced: 2024-07-12T16:27:33.589Z (4 months ago)
- Topics: aws, github-actions, hacktoberfest, iac, oidc, terraform
- Language: HCL
- Homepage: https://registry.terraform.io/modules/philips-labs/github-oidc/aws/latest
- Size: 83 KB
- Stars: 66
- Watchers: 6
- Forks: 28
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-repositories - philips-labs/terraform-aws-github-oidc - Terraform module to setup OIDC with AWS and GH Actions (HCL)
README
# Terraform module AWS OIDC integration GitHub Actions
This [Terraform](https://www.terraform.io/) module manages OpenID Connect (OIDC) integration between [GitHub Actions and AWS](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services).
## Description
The module is strict on the claim checks to avoid that creating an OpenID connect integration opens your AWS account to any GitHub repo. However this strictness is not taking all the risk away. Ensure you familiarize yourself with OpenID Connect and the docs provided by GitHub and AWS. As always think about minimizing the privileges.
The module can manage the following:
- The OpenID Connect identity provider for GitHub in your AWS account (via a submodule).
- A role and assume role policy to check to check OIDC claims.### Manage the OIDC identity provider
The module provides an option for creating an OpenID connect provider. Using the internal `provider` module to create the OpenID Connect provider. This configuration will create the provider and output the ARN. This output can be passed to other instances of the module to setup roles for repositories on the same provider. Alternative you can create the OpenID connect provider via the resource [aws_iam_openid_connect_provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_openid_connect_provider) or in case you have an existing one look-up via the data source [aws_iam_openid_connect_provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_openid_connect_provider).
### Manage roles for a repo
The module creates a role with an assume role policy to check the OIDC claims for the given repo. Be default the policy is set to only allow actions running on the main branch and deny pull request actions. You can choose based on your need one (or more) of the default conditions to check. Additionally, a list of conditions can be provided. The role can only be assumed when all conditions evaluate to true. The following default conditions can be set.
- `allow_main` : Allow GitHub Actions only running on the main branch.
- `allow_environment`: Allow GitHub Actions only for environments, by setting `github_environments` you can limit to a dedicated environment.
- `deny_pull_request`: Denies assuming the role for a pull request.
- `allow_all` : Allow GitHub Actions for any claim for the repository. Be careful, this allows forks as well to assume the role!## Usages
In case there is not OpenID Connect provider already created in the AWS account, create one via the submodule.
```hcl
module "oidc_provider" {
source = "github.com/philips-labs/terraform-aws-github-oidc?ref=//modules/provider"
}
```Nest you ca pass the output the one or multiple instances of the module.
```hcl
module "oidc_repo_s3" {
source = "github.com/philips-labs/terraform-aws-github-oidc?ref="openid_connect_provider_arn = module.oidc_provider.openid_connect_provider.arn
repo = var.repo_s3
role_name = "repo-s3"# optional
# override default conditions
default_conditions = ["allow_main"]# add extra conditions, will be merged with the default_conditions
conditions = [{
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:my-org/my-repo:pull_request"]
}]
}
```## Examples
Check out the [example](examples/default/README.md) for a full example of using the module.
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1 |
| [aws](#requirement\_aws) | >= 3 |## Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 3 |
| [random](#provider\_random) | n/a |## Modules
No modules.
## Resources
| Name | Type |
|------|------|
| [aws_iam_role.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.custom](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [random_string.random](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_iam_policy_document.github_actions_assume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [account\_ids](#input\_account\_ids) | Root users of these Accounts (id) would be given the permissions to assume the role created by this module. | `list(string)` | `[]` | no |
| [conditions](#input\_conditions) | (Optional) Additonal conditions for checking the OIDC claim. |list(object({| `[]` | no |
test = string
variable = string
values = list(string)
}))
| [custom\_principal\_arns](#input\_custom\_principal\_arns) | List of IAM principals ARNs able to assume the role created by this module. | `list(string)` | `[]` | no |
| [default\_conditions](#input\_default\_conditions) | (Optional) Default condtions to apply, at least one of the following is madatory: 'allow\_main', 'allow\_environment', 'deny\_pull\_request' and 'allow\_all'. | `list(string)` |[| no |
"allow_main",
"deny_pull_request"
]
| [github\_environments](#input\_github\_environments) | (Optional) Allow GitHub action to deploy to all (default) or to one of the environments in the list. | `list(string)` |[| no |
"*"
]
| [github\_oidc\_issuer](#input\_github\_oidc\_issuer) | OIDC issuer for GitHub Actions | `string` | `"token.actions.githubusercontent.com"` | no |
| [openid\_connect\_provider\_arn](#input\_openid\_connect\_provider\_arn) | Set the openid connect provider ARN when the provider is not managed by the module. | `string` | n/a | yes |
| [repo](#input\_repo) | (Optional) GitHub repository to grant access to assume a role via OIDC. When the repo is set, a role will be created. | `string` | `null` | no |
| [role\_max\_session\_duration](#input\_role\_max\_session\_duration) | Maximum session duration (in seconds) that you want to set for the specified role. | `number` | `null` | no |
| [role\_name](#input\_role\_name) | (Optional) role name of the created role, if not provided the `namespace` will be used. | `string` | `null` | no |
| [role\_path](#input\_role\_path) | (Optional) Path for the created role, requires `repo` is set. | `string` | `"/github-actions/"` | no |
| [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | (Optional) Boundary for the created role, requires `repo` is set. | `string` | `null` | no |
| [role\_policy\_arns](#input\_role\_policy\_arns) | List of ARNs of IAM policies to attach to IAM role | `list(string)` | `[]` | no |## Outputs
| Name | Description |
|------|-------------|
| [conditions](#output\_conditions) | The assume conditions added to the role. |
| [role](#output\_role) | The crated role that can be assumed for the configured repository. |## Contribution
We welcome contribution, please checkout the [contribution guide](CONTRIBUTING.md). Be-aware we use [pre commit hooks](https://pre-commit.com/) to update the docs.
## Release
Releases are create automated from the main branch using conventional commit messages.
## Contact
For question you can reach out to one of the [maintainers](./MAINTAINERS.md).