Skip to content

Commit 06ec4c0

Browse files
committed
fixing verbiage to replace metions of 'github' with 'gitlab'. fixes regex in var validation. updates description of example
1 parent 35176a4 commit 06ec4c0

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# AWS GitLab OIDC Provider Terraform Module
22

3-
This module allows you to create a GitHub OIDC provider and the associated IAM roles, that will help Github Actions to securely authenticate against the AWS API using an IAM role.
3+
This module allows you to create an AWS IAM OIDC provider that trusts GitLab and the associated IAM roles, that will help GitLab Pipelines to securely authenticate against the AWS API using an IAM role.
44

5-
We recommend using GitHub's OIDC provider to get short-lived credentials needed for your actions. Specifying role-to-assume without providing an aws-access-key-id or a web-identity-token-file will signal to the action that you wish to use the OIDC provider. The default session duration is 1 hour when using the OIDC provider to directly assume an IAM Role. The default session duration is 6 hours when using an IAM User to assume an IAM Role (by providing an aws-access-key-id, aws-secret-access-key, and a role-to-assume) . If you would like to adjust this you can pass a duration to role-duration-seconds, but the duration cannot exceed the maximum that was defined when the IAM Role was created. The default session name is GitHubActions, and you can modify it by specifying the desired name in role-session-name.
5+
We recommend using GitLab's OIDC issuer to get short-lived credentials needed for your pipelines. Specifying role-to-assume without providing an aws-access-key-id or a web-identity-token-file will signal to the pipeline that you wish to use the OIDC provider. The default session duration is 1 hour when using the OIDC provider to directly assume an IAM Role. The default session duration is 6 hours when using an IAM User to assume an IAM Role (by providing an aws-access-key-id, aws-secret-access-key, and a role-to-assume) . If you would like to adjust this you can pass a duration to role-duration-seconds, but the duration cannot exceed the maximum that was defined when the IAM Role was created. The default session name is `GitLabPipeline`, and you can modify it by specifying the desired name in role-session-name.
66

77
## Use-Cases
88

99
1. Retrieve temporary credentials from AWS to access cloud services
1010
1. Use credentials to retrieve secrets or deploy to an environment
1111
1. Scope role to branch or project
12-
1. Create an AWS OIDC provider for GitHub Actions
12+
1. Create an AWS OIDC provider for GitLab Pipelines
1313

1414
## Features
1515

16-
2. Create one or more IAM role that can be assumed by GitHub Actions
16+
2. Create one or more IAM role that can be assumed by GitLab Pipelines
1717
3. IAM roles can be scoped to :
18-
* One or more GitHub organisations
19-
* One or more GitHub repository
20-
* One or more branches in a repository
18+
* One or more GitLab namespaces
19+
* One or more GitLab project
20+
* One or more branches in a project
2121

2222
| Feature | Status |
2323
|--------------------------------------------------------------------------------------------------------|--------|
24-
| Create a role for all repositories in a specific Github organisation ||
25-
| Create a role specific to a repository for a specific organisation ||
26-
| Create a role specific to a branch in a repository ||
27-
| Create a role for multiple organisations/repositories/branches ||
28-
| Create a role for organisations/repositories/branches selected by wildcard (e.g. `feature/*` branches) ||
24+
| Create a role for all projects in a specific GitLab namespace ||
25+
| Create a role specific to a project for a specific namespace ||
26+
| Create a role specific to a branch in a project ||
27+
| Create a role for multiple namespaces/projects/branches ||
28+
| Create a role for namesapces/projectss/branches selected by wildcard (e.g. `feature/*` branches) ||
2929

3030
---
3131

examples/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example
22

3-
Configuration in this directory creates a MySQL Aurora cluster.
3+
Configuration in this directory creates an AWS IAM OpenID Connect Provider, IAM Role and IAM Role Policy for trusing the OIDC provider.
44

55
## Usage
66

examples/basic/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Resources
33
################################################################################
44

5-
module "gitlab-oidc" {
5+
module "gitlab_oidc" {
66
source = "../.."
77

88
create_oidc_provider = true
99
create_oidc_role = true
1010

11-
repositories = ["terraform-module/terraform-aws-github-oidc-provider"]
11+
repositories = ["terraform-module/terraform-aws-gitlab-oidc-provider"]
1212
oidc_role_attach_policies = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"]
1313
}
1414

gitlab/.gitlab-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ authenticate:
88
entrypoint: [""]
99
variables:
1010
ROLE_ARN: arn:aws:iam::XXXXXXXXXXX:role/gitlab-oidc-provider-aws
11+
id_tokens:
12+
GITLAB_OIDC_TOKEN:
13+
aud: https://gitlab.com
1114
script:
1215
- aws --version
1316
- >
1417
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s"
1518
$(aws sts assume-role-with-web-identity
1619
--role-arn ${ROLE_ARN}
1720
--role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}"
18-
--web-identity-token $CI_JOB_JWT_V2
21+
--web-identity-token $GITLAB_OIDC_TOKEN
1922
--duration-seconds 3600
2023
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
2124
--output text))

main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "aws_iam_role" "this" {
2525
assume_role_policy = join("", data.aws_iam_policy_document.this.*.json)
2626
tags = var.tags
2727

28-
depends_on = [ aws_iam_openid_connect_provider.this ]
28+
depends_on = [aws_iam_openid_connect_provider.this]
2929
}
3030

3131
resource "aws_iam_role_policy_attachment" "attach" {
@@ -34,7 +34,7 @@ resource "aws_iam_role_policy_attachment" "attach" {
3434
policy_arn = var.oidc_role_attach_policies[count.index]
3535
role = join("", aws_iam_role.this.*.name)
3636

37-
depends_on = [ aws_iam_role.this ]
37+
depends_on = [aws_iam_role.this]
3838
}
3939

4040
data "aws_iam_policy_document" "this" {
@@ -47,13 +47,13 @@ data "aws_iam_policy_document" "this" {
4747
effect = "Allow"
4848

4949
condition {
50-
test = "StringLike"
51-
values = var.repositories
50+
test = "StringLike"
51+
values = var.projects
5252
variable = "${join("", aws_iam_openid_connect_provider.this.*.url)}:${var.match_field}"
5353
}
5454

5555
principals {
56-
identifiers = [ statement.value.arn ]
56+
identifiers = [statement.value.arn]
5757
type = "Federated"
5858
}
5959
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ output "oidc_role" {
1010

1111
output "thumbprint" {
1212
description = "TLS endpoint certificate SHA1 Fingerprint"
13-
value = [data.tls_certificate.gitlab.certificates[0].sha1_fingerprint]
13+
value = [data.tls_certificate.gitlab.certificates[0].sha1_fingerprint]
1414
}
1515

1616
output "policy_document" {

variables.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ variable "role_description" {
3434
default = "Role assumed by the Gitlab OIDC provider."
3535
}
3636

37-
variable "repositories" {
38-
description = "List of GitLab organization/repository names authorized to assume the role."
37+
variable "projects" {
38+
description = "List of GitLab namesapce/project names authorized to assume the role."
3939
type = list(string)
4040
default = []
4141

4242
validation {
43-
# Ensures each element of github_repositories list matches the
44-
# organization/repository format used by GitHub.
43+
# Ensures each element of gitlab_projects list matches the
44+
# namespace/project format used by GitLab.
4545
condition = length([
46-
for repo in var.repositories : 1
47-
if length(regexall("^project_path:[A-Za-z0-9_.-]+?/([A-Za-z0-9_.:/-]+|\\*)$", repo)) > 0
48-
]) == length(var.repositories)
49-
error_message = "Repositories must be specified in the organization/repository format."
46+
for proj in var.projects : 1
47+
if length(regexall("[A-Za-z0-9_.-]+?/([A-Za-z0-9_.:/-]+|\\*)$", proj)) > 0
48+
]) == length(var.projects)
49+
error_message = "Projects must be specified in the namespace/project format."
5050
}
5151
}
5252

@@ -78,14 +78,14 @@ variable "gitlab_url" {
7878
}
7979

8080
variable "gitlab_tls_url" {
81-
type = string
81+
type = string
8282
# Avoid using https scheme because the Hashicorp TLS provider has started following redirects starting v4.
8383
# See https://github.com/hashicorp/terraform-provider-tls/issues/249
8484
default = "tls://gitlab.com:443"
8585
}
8686

8787
variable "aud_value" {
8888
description = "(Required) A list of client IDs (also known as audiences). When a mobile or web app registers with an OpenID Connect provider, they establish a value that identifies the application. (This is the value that's sent as the client_id parameter on OAuth requests.)"
89-
type = list(string)
90-
default = ["https://gitlab.com"]
89+
type = list(string)
90+
default = ["https://gitlab.com"]
9191
}

0 commit comments

Comments
 (0)