diff --git a/config/auth_jwt_role/jwt/github/iuclabs/release.yaml b/config/auth_jwt_role/jwt/github/iuclabs/release.yaml new file mode 100644 index 0000000..9c2d24d --- /dev/null +++ b/config/auth_jwt_role/jwt/github/iuclabs/release.yaml @@ -0,0 +1,22 @@ +--- +bound_audiences: ["https://vault.service.consul:8200"] +bound_claims: + repository_owner: IUCLabs + event_name: push + ref: refs/tags/v* +claim_mappings: + repository: repository + repository_owner: repository_owner + ref: ref + ref_type: ref_type + event_name: event_name + workflow: workflow + job_workflow_ref: job_workflow_ref + run_id: run_id + run_attempt: run_attempt + sha: sha + actor: actor + environment: environment +user_claim: jti +token_ttl: 900 +token_max_ttl: 900 diff --git a/modules/vault_cluster/modules/auth_jwt_role/tests/bound_claims.tftest.hcl b/modules/vault_cluster/modules/auth_jwt_role/tests/bound_claims.tftest.hcl index b5fa9e1..9bfa969 100644 --- a/modules/vault_cluster/modules/auth_jwt_role/tests/bound_claims.tftest.hcl +++ b/modules/vault_cluster/modules/auth_jwt_role/tests/bound_claims.tftest.hcl @@ -59,6 +59,22 @@ run "accept_exact_refs" { } } +run "accept_release_tag_glob" { + command = plan + variables { bound_claims = { repository_owner = "IUCLabs", event_name = "push", ref = "refs/tags/v*" } } + + assert { + condition = vault_jwt_auth_backend_role.role.bound_claims.ref == "refs/tags/v*" + error_message = "release tag glob must pass through to bound_claims unchanged" + } +} + +run "reject_ref_tags_other_prefix_glob" { + command = plan + variables { bound_claims = { repository_owner = "IUCLabs", event_name = "push", ref = "refs/tags/x*" } } + expect_failures = [var.bound_claims] +} + run "accept_with_repository" { command = plan variables { bound_claims = { repository_owner = "IUCLabs", event_name = "push,release,schedule,pull_request", ref = "refs/heads/*,refs/tags/*,refs/pull/*/merge", repository = "IUCLabs/app" } } diff --git a/modules/vault_cluster/modules/auth_jwt_role/variables.tf b/modules/vault_cluster/modules/auth_jwt_role/variables.tf index 428fffc..e3b6a94 100644 --- a/modules/vault_cluster/modules/auth_jwt_role/variables.tf +++ b/modules/vault_cluster/modules/auth_jwt_role/variables.tf @@ -47,10 +47,10 @@ variable "bound_claims" { } validation { condition = alltrue([for v in split(",", lookup(var.bound_claims, "ref", "")) : - contains(["refs/heads/*", "refs/tags/*", "refs/pull/*/merge"], trimspace(v)) || + contains(["refs/heads/*", "refs/tags/*", "refs/tags/v*", "refs/pull/*/merge"], trimspace(v)) || can(regex("^(refs/(heads|tags)/[A-Za-z0-9._/-]+|refs/pull/[0-9]+/merge)$", trimspace(v))) ]) - error_message = "bound_claims.ref must be refs/heads/*, refs/tags/*, refs/pull/*/merge or exact refs of those shapes." + error_message = "bound_claims.ref must be refs/heads/*, refs/tags/*, refs/tags/v*, refs/pull/*/merge or exact refs of those shapes." } validation { condition = alltrue(flatten([for k, v in var.bound_claims : [ diff --git a/policies/identity/oidc/token/artifactapi-writer.yaml b/policies/identity/oidc/token/artifactapi-writer.yaml index 91f213f..74fcf5c 100644 --- a/policies/identity/oidc/token/artifactapi-writer.yaml +++ b/policies/identity/oidc/token/artifactapi-writer.yaml @@ -5,6 +5,8 @@ rules: - read auth: + jwt/github/iuclabs: + - release k8s/au/syd1: - woodpecker_artifactapi_writer ldap: