Merge branch 'main' into benvin/ceph-saml
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful

This commit is contained in:
2026-07-24 22:16:29 +10:00
7 changed files with 87 additions and 0 deletions
+38
View File
@@ -82,6 +82,43 @@ resource "authentik_provider_saml" "this" {
signing_kp = each.value.signing_kp != null ? data.authentik_certificate_key_pair.saml_signing[each.key].id : null
}
# Build a Python expression per app that emits a role claim from the user's
# effective (hierarchical) group membership. Assembled from the config rules so
# the generated code has predictable indentation (no template-directive quirks).
locals {
role_mapping_expr = {
for k, v in var.providers_oauth2 : k => join("\n", concat(
[
"groups = {}",
"pending = list(user.ak_groups.all())",
"while pending:",
" grp = pending.pop()",
" if grp.pk in groups:",
" continue",
" groups[grp.pk] = grp.name",
" pending += list(grp.parents.all())",
"names = set(groups.values())",
],
flatten([
for rule in coalesce(try(v.role_mappings.rules, null), []) : [
"if ${jsonencode(rule.group)} in names:",
" return {${jsonencode(try(v.role_mappings.claim, ""))}: ${jsonencode(rule.role)}}",
]
]),
["return {${jsonencode(try(v.role_mappings.claim, ""))}: ${jsonencode(try(v.role_mappings.default, ""))}}"],
))
if v.role_mappings != null
}
}
resource "authentik_property_mapping_provider_scope" "role" {
for_each = { for k, v in var.providers_oauth2 : k => v if v.role_mappings != null }
name = "unkin: ${each.key} role"
scope_name = each.value.role_mappings.claim
expression = local.role_mapping_expr[each.key]
}
# Resolve oauth2 flows by slug and scope mappings by managed identifier, and
# read client secrets from Vault so nothing sensitive is committed.
data "authentik_flow" "oauth2_authorization" {
@@ -117,6 +154,7 @@ resource "authentik_provider_oauth2" "this" {
property_mappings = concat(
try(data.authentik_property_mapping_provider_scope.oauth2[each.key].ids, []),
[authentik_property_mapping_provider_scope.groups_hierarchical.id],
try([authentik_property_mapping_provider_scope.role[each.key].id], []),
)
signing_key = each.value.signing_key
access_token_validity = each.value.access_token_validity