|
1 | 1 | # terraform-aws-github-oidc
|
2 |
| -Module to create github oidc integration. |
| 2 | +Module to create github oidc integration with AWS. |
| 3 | + |
| 4 | +## Usage |
| 5 | + |
| 6 | +### Install the module |
| 7 | + |
| 8 | +Initialize the module and get the Role ARN from the outputs. |
| 9 | + |
| 10 | +```hcl |
| 11 | +provider "aws" { |
| 12 | + region = var.region |
| 13 | +} |
| 14 | +
|
| 15 | +module "github_oidc" { |
| 16 | + source = "bryan-rhm/github-oidc/aws" |
| 17 | + version = "1.0.0" |
| 18 | +
|
| 19 | + github_organization = "YOUR ORGANIZATION/GITHUB ACCOUNT" |
| 20 | + managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"] # Policies you want to attach to the github role. |
| 21 | +
|
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +Once you have installed the module you will be able authenticate from your github organization using the role created from the module. |
| 26 | + |
| 27 | +The job or workflow run requires a permissions setting with id-token: write. You won't be able to request the OIDC JWT ID token if the permissions setting for id-token is set to read or none. |
| 28 | + |
| 29 | +```yaml |
| 30 | +permissions: |
| 31 | + id-token: write |
| 32 | +``` |
| 33 | +
|
| 34 | +The aws-actions/configure-aws-credentials action receives a JWT from the GitHub OIDC provider, and then requests an access token from AWS. For more information, see the [AWS documentation](https://github.com/aws-actions/configure-aws-credentials). |
| 35 | +
|
| 36 | +```yaml |
| 37 | +# Sample workflow to access AWS resources when workflow is tied to branch |
| 38 | +# The workflow Creates static website using aws s3 |
| 39 | +name: AWS example workflow |
| 40 | +on: |
| 41 | + push |
| 42 | +env: |
| 43 | + BUCKET_NAME : "<example-bucket-name>" |
| 44 | + AWS_REGION : "<example-aws-region>" |
| 45 | +# permission can be added at job level or workflow level |
| 46 | +permissions: |
| 47 | + id-token: write |
| 48 | + contents: read # This is required for actions/checkout |
| 49 | +jobs: |
| 50 | + S3PackageUpload: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - name: Git clone the repository |
| 54 | + uses: actions/checkout@v3 |
| 55 | + - name: configure aws credentials |
| 56 | + uses: aws-actions/configure-aws-credentials@v1 |
| 57 | + with: |
| 58 | + role-to-assume: arn:aws:iam::1234567890:role/example-role |
| 59 | + role-session-name: samplerolesession |
| 60 | + aws-region: ${{ env.AWS_REGION }} |
| 61 | + # Upload a file to AWS s3 |
| 62 | + - name: Copy index.html to s3 |
| 63 | + run: | |
| 64 | + aws s3 cp ./index.html s3://${{ env.BUCKET_NAME }}/ |
| 65 | +``` |
| 66 | +
|
| 67 | +
|
| 68 | +### References |
| 69 | +[Configuring OpenID Connect in Amazon Web Services](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) |
| 70 | +
|
| 71 | +## Requirements |
| 72 | +
|
| 73 | +| Name | Version | |
| 74 | +|------|---------| |
| 75 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.4 | |
| 76 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.43.0 | |
| 77 | +| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 3.4.0 | |
| 78 | +
|
| 79 | +## Providers |
| 80 | +
|
| 81 | +| Name | Version | |
| 82 | +|------|---------| |
| 83 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.19.0 | |
| 84 | +| <a name="provider_tls"></a> [tls](#provider\_tls) | 3.4.0 | |
| 85 | +
|
| 86 | +## Modules |
| 87 | +
|
| 88 | +No modules. |
| 89 | +
|
| 90 | +## Resources |
| 91 | +
|
| 92 | +| Name | Type | |
| 93 | +|------|------| |
| 94 | +| [aws_iam_openid_connect_provider.oidc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_openid_connect_provider) | resource | |
| 95 | +| [aws_iam_role.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | |
| 96 | +| [aws_iam_policy_document.asume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | |
| 97 | +| [tls_certificate.certificate](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/data-sources/certificate) | data source | |
| 98 | +
|
| 99 | +## Inputs |
| 100 | +
|
| 101 | +| Name | Description | Type | Default | Required | |
| 102 | +|------|-------------|------|---------|:--------:| |
| 103 | +| <a name="input_github_organization"></a> [github\_organization](#input\_github\_organization) | The GitHub organization to allow access to | `string` | n/a | yes | |
| 104 | +| <a name="input_github_repositories"></a> [github\_repositories](#input\_github\_repositories) | The GitHub repositories inside the organization you want to allow access to | `list(string)` | <pre>[<br> "*"<br>]</pre> | no | |
| 105 | +| <a name="input_github_url"></a> [github\_url](#input\_github\_url) | The URL of the GitHub OAuth2 provider | `string` | `"https://token.actions.githubusercontent.com"` | no | |
| 106 | +| <a name="input_managed_policy_arns"></a> [managed\_policy\_arns](#input\_managed\_policy\_arns) | The ARNs of the managed policies to attach to the role | `list(string)` | `[]` | no | |
| 107 | +| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | Name of the IAM role | `string` | `"GithubActionsRole"` | no | |
| 108 | +| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all resources | `map(string)` | `{}` | no | |
| 109 | + |
| 110 | +## Outputs |
| 111 | + |
| 112 | +| Name | Description | |
| 113 | +|------|-------------| |
| 114 | +| <a name="output_assume_role_policy"></a> [assume\_role\_policy](#output\_assume\_role\_policy) | Assume role policy, this value can be used to create another role outside this module | |
| 115 | +| <a name="output_oidc"></a> [oidc](#output\_oidc) | Github openid connect provider | |
| 116 | +| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | Arn of the IAM role allowed to authenticate to AWS from Github actions | |
0 commit comments