Skip to content

Commit

Permalink
feat(portal-backstage): support custom claims
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Jun 12, 2024
1 parent 06b9a94 commit 3a777ff
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/portal-backstage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ This module deploys the [Humanitec Reference Architecture Backstage](https://git
| github | ~> 5.38 |
| humanitec | ~> 1.0 |
| random | ~> 3.5 |
| time | ~> 0.11 |

### Providers

| Name | Version |
|------|---------|
| github | ~> 5.38 |
| humanitec | ~> 1.0 |
| time | ~> 0.11 |

### Resources

| Name | Type |
|------|------|
| [github_actions_repository_oidc_subject_claim_customization_template.backstage](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_repository_oidc_subject_claim_customization_template) | resource |
| [github_repository.backstage](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource |
| [github_repository_file.re_deploy](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file) | resource |
| [humanitec_value.backstage_cloud_provider](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
| [humanitec_value.backstage_github_app_client_id](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
| [humanitec_value.backstage_github_app_client_secret](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
Expand All @@ -36,6 +40,7 @@ This module deploys the [Humanitec Reference Architecture Backstage](https://git
| [humanitec_value.backstage_github_org_id](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
| [humanitec_value.backstage_humanitec_org](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
| [humanitec_value.backstage_humanitec_token](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
| [time_sleep.wait_after_claims_change](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |

### Inputs

Expand All @@ -51,6 +56,7 @@ This module deploys the [Humanitec Reference Architecture Backstage](https://git
| humanitec\_app\_id | Humanitec Application ID | `string` | n/a | yes |
| humanitec\_ci\_service\_user\_token\_ref | Humanitec CI Service User Token (Secret Store reference) | <pre>object({<br> ref = optional(string)<br> store = optional(string)<br> value = optional(string)<br> version = optional(string)<br> })</pre> | n/a | yes |
| humanitec\_org\_id | Humanitec Organization ID | `string` | n/a | yes |
| backstage\_repo\_custom\_claim\_keys | Custom claim keys for the OIDC subject claim customization template | `list(string)` | `null` | no |
| backstage\_template\_owner | Backstage template owner | `string` | `"humanitec-architecture"` | no |
| backstage\_template\_repository | Backstage template repository | `string` | `"backstage"` | no |
<!-- END_TF_DOCS -->
35 changes: 35 additions & 0 deletions modules/portal-backstage/backstage-github.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,38 @@ resource "github_repository" "backstage" {
repository = var.backstage_template_repository
}
}

# Required as Azure doesn't support wildcards in scopes https://github.com/Azure/azure-workload-identity/issues/373
# More details in https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#customizing-the-token-claims
resource "github_actions_repository_oidc_subject_claim_customization_template" "backstage" {
count = var.backstage_repo_custom_claim_keys != null ? 1 : 0

repository = github_repository.backstage.name
use_default = false
include_claim_keys = var.backstage_repo_custom_claim_keys
}

# Wait for the initial post-repo create action run to start
resource "time_sleep" "wait_after_claims_change" {
count = var.backstage_repo_custom_claim_keys != null ? 1 : 0

create_duration = "30s"

depends_on = [github_actions_repository_oidc_subject_claim_customization_template.backstage]
}

# Redeploy after the custom claim keys change
resource "github_repository_file" "re_deploy" {
count = var.backstage_repo_custom_claim_keys != null ? 1 : 0

repository = github_repository.backstage.name
branch = "main"
file = ".github/redeploy"
content = "redeploy after claim keys change"
commit_message = "Redeploy after claim keys change"
commit_author = "github-actions[bot]"
commit_email = "41898282+github-actions[bot]@users.noreply.github.com"
overwrite_on_create = true

depends_on = [time_sleep.wait_after_claims_change]
}
4 changes: 4 additions & 0 deletions modules/portal-backstage/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ terraform {
source = "hashicorp/random"
version = "~> 3.5"
}
time = {
source = "hashicorp/time"
version = "~> 0.11"
}
}
required_version = ">= 1.3.0"
}
3 changes: 3 additions & 0 deletions modules/portal-backstage/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# Custom claim keys for the OIDC subject claim customization template
backstage_repo_custom_claim_keys = ""

# Backstage template owner
backstage_template_owner = "humanitec-architecture"

Expand Down
8 changes: 8 additions & 0 deletions modules/portal-backstage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ variable "backstage_template_repository" {
type = string
default = "backstage"
}

# Required as Azure doesn't support wildcards in scopes https://github.com/Azure/azure-workload-identity/issues/373
# More details in https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#customizing-the-token-claims
variable "backstage_repo_custom_claim_keys" {
description = "Custom claim keys for the OIDC subject claim customization template"
type = list(string)
default = null
}

0 comments on commit 3a777ff

Please sign in to comment.