Onboard OpenBao as an Authentik OIDC client
Adds config/providers_oauth2/vault.yaml so human logins to OpenBao go
through Authentik SSO (bao CLI and the web UI). Machine auth (approle,
kubernetes, CI) and break-glass are unchanged and stay on the OpenBao side.
Extends the oauth2 provider module so a config may generate its own client
secret instead of reading a pre-seeded one: client_secret_vault.generate
creates a random_password and writes {client_id, client_secret} to the given
kv-v2 path. Providers without the flag keep the existing read-only data source
behaviour. This is what lets the provider land with no manual Vault seed.
Gates the new application with akP-vault-admin and nests it in
akR-global-admin, matching how every other app in this repo is bound.
This commit is contained in:
Generated
+23
@@ -22,6 +22,29 @@ provider "registry.opentofu.org/goauthentik/authentik" {
|
||||
]
|
||||
}
|
||||
|
||||
provider "registry.opentofu.org/hashicorp/random" {
|
||||
version = "3.9.0"
|
||||
constraints = ">= 3.6.0"
|
||||
hashes = [
|
||||
"h1:8EQU5KSxezcjo/phRSe69rDOI0lk4pSaggj7FsskYp8=",
|
||||
"zh:03f1114cc20b8913523735ab76e0f0a2b16ce13c92923a53304bf85f07fc0dbc",
|
||||
"zh:105b678ee72322a3067f105d7e05e940f6143238f377f6e87ff4ec909246ac2a",
|
||||
"zh:55f3bbf13ea18cbace61a706566a80f25f33fe2b1780b6f3d7b582af2a05b6d2",
|
||||
"zh:63adf996db48f082f7a6351eb485e219cd88795fc71e6ec60a837263ab0d2cb1",
|
||||
"zh:7e99550738a4e3cc68b8a467714b0d69371025fe95e3326d5323d026d55653e9",
|
||||
"zh:8342b54af3a18a37e075eeae61be57f4de2ba71b35d95c5075d402dd2c1f289d",
|
||||
"zh:83ee18e32ac9dd5fc91298554b7c4cfa4c3a1db50f4c797945637cc93c0844ae",
|
||||
"zh:993ecc0adbf6bd535a59fbc9b735d8c33950e6f6eb5e621d750da9b71d65d80a",
|
||||
"zh:ad722bc59d4edbf1415e827fc007c0efe6e0e9462d5568bae20b34be1058a261",
|
||||
"zh:ae9448e1f87b2f9a6c5197a0e9862162ec6b137cb3a3835e11522995d8939e7c",
|
||||
"zh:bc9cdd3aac784f759125c6627f6f6416e8726a1c184eb9cf3e55b9edbc94c627",
|
||||
"zh:c8e35b89572ba1c40a9b20022e033a3395fb8d42e7604d50c900f193ba10382e",
|
||||
"zh:e2deaa8a9975ef81d9f62baed12c41286918b0a10908e0e031f13f69a3b730a1",
|
||||
"zh:ee39707557210a0ab1098aa357d2cdfe502e5a312d0dbdffb09d08facc4d3fc5",
|
||||
"zh:f81afe4eb63e8aa9e0ea71be6c990f0dc69cb360e7191c0742a991f4a5081b64",
|
||||
]
|
||||
}
|
||||
|
||||
provider "registry.opentofu.org/hashicorp/vault" {
|
||||
version = "5.10.1"
|
||||
constraints = ">= 4.0.0"
|
||||
|
||||
@@ -136,12 +136,53 @@ data "authentik_property_mapping_provider_scope" "oauth2" {
|
||||
managed_list = each.value.scope_mappings
|
||||
}
|
||||
|
||||
locals {
|
||||
# Providers whose client secret is pre-seeded in Vault and only read here.
|
||||
oauth2_secret_read = {
|
||||
for k, v in var.providers_oauth2 : k => v
|
||||
if v.client_secret_vault != null && !v.client_secret_vault.generate
|
||||
}
|
||||
# Providers whose client secret is generated here and published to Vault, so
|
||||
# onboarding needs no operator seeding the path first.
|
||||
oauth2_secret_generate = {
|
||||
for k, v in var.providers_oauth2 : k => v
|
||||
if v.client_secret_vault != null && v.client_secret_vault.generate
|
||||
}
|
||||
|
||||
oauth2_client_secret = merge(
|
||||
{ for k, v in local.oauth2_secret_read : k => data.vault_kv_secret_v2.oauth2[k].data["client_secret"] },
|
||||
{ for k, v in local.oauth2_secret_generate : k => random_password.oauth2_client_secret[k].result },
|
||||
)
|
||||
}
|
||||
|
||||
data "vault_kv_secret_v2" "oauth2" {
|
||||
for_each = { for k, v in var.providers_oauth2 : k => v if v.client_secret_vault != null }
|
||||
for_each = local.oauth2_secret_read
|
||||
mount = each.value.client_secret_vault.mount
|
||||
name = each.value.client_secret_vault.path
|
||||
}
|
||||
|
||||
# Alphanumeric only: the secret is pasted into consumer configs and CLI flags,
|
||||
# where punctuation is an easy way to hit shell/URL escaping bugs.
|
||||
resource "random_password" "oauth2_client_secret" {
|
||||
for_each = local.oauth2_secret_generate
|
||||
|
||||
length = 64
|
||||
special = false
|
||||
}
|
||||
|
||||
# Publish the generated credential so consumers (terraform-vault, app configs)
|
||||
# read it from Vault instead of an operator copying it out of Authentik.
|
||||
resource "vault_kv_secret_v2" "oauth2_client_secret" {
|
||||
for_each = local.oauth2_secret_generate
|
||||
|
||||
mount = each.value.client_secret_vault.mount
|
||||
name = each.value.client_secret_vault.path
|
||||
data_json = jsonencode({
|
||||
client_id = each.value.client_id
|
||||
client_secret = random_password.oauth2_client_secret[each.key].result
|
||||
})
|
||||
}
|
||||
|
||||
# Default JWT signing key for OAuth2 providers. Without a signing_key Authentik
|
||||
# signs ID tokens with HS256, which RS256-only RP clients (argocd, grafana, ...)
|
||||
# reject. Look up the estate's RSA keypair by name so providers default to RS256.
|
||||
@@ -157,7 +198,7 @@ resource "authentik_provider_oauth2" "this" {
|
||||
invalidation_flow = data.authentik_flow.oauth2_invalidation[each.key].id
|
||||
client_type = each.value.client_type
|
||||
client_id = each.value.client_id
|
||||
client_secret = each.value.client_secret_vault != null ? data.vault_kv_secret_v2.oauth2[each.key].data["client_secret"] : null
|
||||
client_secret = lookup(local.oauth2_client_secret, each.key, null)
|
||||
property_mappings = concat(
|
||||
try(data.authentik_property_mapping_provider_scope.oauth2[each.key].ids, []),
|
||||
[authentik_property_mapping_provider_scope.groups_hierarchical.id],
|
||||
|
||||
@@ -60,9 +60,13 @@ variable "providers_oauth2" {
|
||||
client_id = string
|
||||
# client_secret is never committed. Point at a Vault kv-v2 secret whose
|
||||
# `client_secret` key holds the value (seeded out of band); TF reads it.
|
||||
# generate = true flips that around: the secret is created here and written
|
||||
# to that path as {client_id, client_secret}, so onboarding needs no manual
|
||||
# seed. Requires write access to the kv path.
|
||||
client_secret_vault = optional(object({
|
||||
mount = string
|
||||
path = string
|
||||
mount = string
|
||||
path = string
|
||||
generate = optional(bool, false)
|
||||
}), null)
|
||||
# Managed identifiers of scope property mappings (e.g.
|
||||
# goauthentik.io/providers/oauth2/scope-openid). Resolved to ids.
|
||||
|
||||
@@ -9,5 +9,9 @@ terraform {
|
||||
source = "hashicorp/vault"
|
||||
version = ">= 4.0.0"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = ">= 3.6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user