Skip to content

Commit 0ba0711

Browse files
authored
Merge pull request #1 from ManagedKube/initial
Initial commit
2 parents 8ebca1e + fe9f25d commit 0ba0711

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Generate terraform docs
2+
on:
3+
- pull_request
4+
5+
jobs:
6+
docs:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
with:
11+
ref: ${{ github.event.pull_request.head.ref }}
12+
13+
- name: Render terraform docs and push changes back to PR
14+
uses: terraform-docs/gh-actions@main
15+
with:
16+
working-dir: .
17+
output-file: README.md
18+
output-method: inject
19+
git-push: "true"

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# terraform-aws-github-oidc-provider
1+
# Github OIDC Provider
2+
3+
This module setups an AWS OIDC Identity prodiver for Github Actions. This will allow you to use OIDC Federation to give your
4+
Github Actions access to your AWS account.
5+
6+
Main Doc: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
7+
8+
## Filtering on the `sub`
9+
Conditions to validate
10+
11+
Doc: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#examples
12+
13+
This controls can help you do things like:
14+
* Only allow a certain branch
15+
* Only allow a certain repo/org
16+
17+
## ARN to use in the Github Actions
18+
This module outputs an `arn` value. This is the `arn` you should use in the Github Actions.
19+
20+
<!-- BEGIN_TF_DOCS -->
21+
## Requirements
22+
23+
No requirements.
24+
25+
## Providers
26+
27+
| Name | Version |
28+
|------|---------|
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
30+
31+
## Modules
32+
33+
| Name | Source | Version |
34+
|------|--------|---------|
35+
| <a name="module_iam_assumable_role_admin"></a> [iam\_assumable\_role\_admin](#module\_iam\_assumable\_role\_admin) | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | 3.6.0 |
36+
37+
## Resources
38+
39+
| Name | Type |
40+
|------|------|
41+
| [aws_iam_openid_connect_provider.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_openid_connect_provider) | resource |
42+
| [aws_iam_policy.iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
43+
44+
## Inputs
45+
46+
| Name | Description | Type | Default | Required |
47+
|------|-------------|------|---------|:--------:|
48+
| <a name="input_aws_policy_json"></a> [aws\_policy\_json](#input\_aws\_policy\_json) | The AWS policy in a json format | `string` | `"{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": \"*\",\n \"Resource\": \"*\"\n }\n ]\n}\n"` | no |
49+
| <a name="input_client_id_list"></a> [client\_id\_list](#input\_client\_id\_list) | n/a | `list` | <pre>[<br> "sts.amazonaws.com"<br>]</pre> | no |
50+
| <a name="input_name"></a> [name](#input\_name) | The name for the various resources | `string` | `"github_oidc"` | no |
51+
| <a name="input_tags"></a> [tags](#input\_tags) | Tags | `map(any)` | `{}` | no |
52+
| <a name="input_thumbprint_list"></a> [thumbprint\_list](#input\_thumbprint\_list) | This is the thumbprint returned if you were to create an "identity provider" in AWS and gave it this url: https://token.actions.githubusercontent.com | `list` | <pre>[<br> "a031c46782e6e6c662c2c87c76da9aa62ccabd8e"<br>]</pre> | no |
53+
| <a name="input_url"></a> [url](#input\_url) | n/a | `string` | `"https://token.actions.githubusercontent.com"` | no |
54+
| <a name="input_validate_conditions"></a> [validate\_conditions](#input\_validate\_conditions) | Conditions to validate | `set(string)` | <pre>[<br> "repo:octo-org/octo-repo:ref:refs/heads/octo-branch"<br>]</pre> | no |
55+
56+
## Outputs
57+
58+
| Name | Description |
59+
|------|-------------|
60+
| <a name="output_arn"></a> [arn](#output\_arn) | n/a |
61+
<!-- END_TF_DOCS -->

main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_iam_openid_connect_provider" "this" {
2+
url = var.url
3+
4+
client_id_list = var.client_id_list
5+
6+
thumbprint_list = var.thumbprint_list
7+
8+
tags = var.tags
9+
}
10+
11+
module "iam_assumable_role_admin" {
12+
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
13+
version = "3.6.0"
14+
create_role = true
15+
role_name = var.name
16+
provider_url = var.url
17+
role_policy_arns = [aws_iam_policy.iam_policy.arn]
18+
oidc_fully_qualified_subjects = var.validate_conditions
19+
tags = var.tags
20+
}
21+
22+
resource "aws_iam_policy" "iam_policy" {
23+
name_prefix = var.name
24+
description = "IAM Policy for the Github OIDC Federation permissions"
25+
policy = var.aws_policy_json
26+
tags = var.tags
27+
}

output.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "arn" {
2+
value = module.iam_assumable_role_admin.this_iam_role_arn
3+
}

variables.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variable "name" {
2+
description = "The name for the various resources"
3+
default = "github_oidc"
4+
}
5+
6+
variable "url" {
7+
default = "https://token.actions.githubusercontent.com"
8+
}
9+
10+
variable "client_id_list" {
11+
default = [
12+
"sts.amazonaws.com"
13+
]
14+
}
15+
16+
# This is the thumbprint returned if you were to create an "identity provider" in AWS and gave
17+
# it this url: https://token.actions.githubusercontent.com
18+
variable "thumbprint_list" {
19+
default = [
20+
"a031c46782e6e6c662c2c87c76da9aa62ccabd8e"
21+
]
22+
}
23+
24+
variable "aws_policy_json" {
25+
description = "The AWS policy in a json format"
26+
default = <<-EOT
27+
{
28+
"Version": "2012-10-17",
29+
"Statement": [
30+
{
31+
"Effect": "Allow",
32+
"Action": "*",
33+
"Resource": "*"
34+
}
35+
]
36+
}
37+
EOT
38+
}
39+
40+
variable "validate_conditions" {
41+
description = "Conditions to validate"
42+
type = set(string)
43+
default = ["repo:octo-org/octo-repo:ref:refs/heads/octo-branch"]
44+
}
45+
46+
variable "tags" {
47+
type = map(any)
48+
default = {}
49+
description = "Tags"
50+
}

0 commit comments

Comments
 (0)