vault: add OpenBao OIDC integration with Kanidm
Some checks failed
Run nix flake check / flake-check (push) Has been cancelled

This commit is contained in:
2026-02-09 19:20:13 +01:00
parent 2f5a2a4bf1
commit d7f6603620
5 changed files with 127 additions and 0 deletions

View File

@@ -40,6 +40,21 @@
preferShortUsername = true; preferShortUsername = true;
scopeMaps.users = [ "openid" "profile" "email" "groups" ]; scopeMaps.users = [ "openid" "profile" "email" "groups" ];
}; };
systems.oauth2.openbao = {
displayName = "OpenBao Secrets";
# Both CLI (localhost) and Web UI callback URLs
originUrl = [
"http://localhost:8250/oidc/callback"
"https://vault.home.2rjus.net:8200/ui/vault/auth/oidc/oidc/callback"
];
originLanding = "https://vault.home.2rjus.net:8200/";
basicSecretFile = config.vault.secrets.openbao-oauth2.outputDir;
preferShortUsername = true;
# Allow groups scope for role binding
scopeMaps.admins = [ "openid" "profile" "email" "groups" ];
scopeMaps.users = [ "openid" "profile" "email" "groups" ];
};
}; };
}; };
@@ -72,6 +87,15 @@
group = "kanidm"; group = "kanidm";
}; };
# Vault secret for OpenBao OAuth2 client secret
vault.secrets.openbao-oauth2 = {
secretPath = "services/openbao/oauth2-client-secret";
extractKey = "password";
services = [ "kanidm" ];
owner = "kanidm";
group = "kanidm";
};
# Note: Kanidm does not expose Prometheus metrics # Note: Kanidm does not expose Prometheus metrics
# If metrics support is added in the future, uncomment: # If metrics support is added in the future, uncomment:
# homelab.monitoring.scrapeTargets = [ # homelab.monitoring.scrapeTargets = [

View File

@@ -106,6 +106,7 @@ locals {
"secret/data/hosts/kanidm01/*", "secret/data/hosts/kanidm01/*",
"secret/data/kanidm/*", "secret/data/kanidm/*",
"secret/data/services/grafana/*", "secret/data/services/grafana/*",
"secret/data/services/openbao/*",
] ]
} }

49
terraform/vault/oidc.tf Normal file
View File

@@ -0,0 +1,49 @@
# OIDC authentication backend for Kanidm integration
resource "vault_jwt_auth_backend" "oidc" {
path = "oidc"
type = "oidc"
oidc_discovery_url = "https://auth.home.2rjus.net/oauth2/openid/openbao"
oidc_client_id = "openbao"
oidc_client_secret = random_password.auto_secrets["services/openbao/oauth2-client-secret"].result
default_role = "default"
tune {
listing_visibility = "unauth"
default_lease_ttl = "1h"
max_lease_ttl = "24h"
token_type = "default-service"
}
}
# Admin role - maps Kanidm admins group to admin policy
resource "vault_jwt_auth_backend_role" "admin" {
backend = vault_jwt_auth_backend.oidc.path
role_name = "admin"
token_policies = ["oidc-admin"]
user_claim = "preferred_username"
groups_claim = "groups"
bound_claims = { groups = "admins" }
role_type = "oidc"
allowed_redirect_uris = [
"http://localhost:8250/oidc/callback",
"https://vault.home.2rjus.net:8200/ui/vault/auth/oidc/oidc/callback",
]
}
# Default role - any authenticated user (limited access)
resource "vault_jwt_auth_backend_role" "default" {
backend = vault_jwt_auth_backend.oidc.path
role_name = "default"
token_policies = ["oidc-default"]
user_claim = "preferred_username"
groups_claim = "groups"
role_type = "oidc"
allowed_redirect_uris = [
"http://localhost:8250/oidc/callback",
"https://vault.home.2rjus.net:8200/ui/vault/auth/oidc/oidc/callback",
]
}

View File

@@ -8,3 +8,50 @@ path "sys/metrics" {
} }
EOT EOT
} }
# OIDC admin policy - full read/write to all secrets
resource "vault_policy" "oidc_admin" {
name = "oidc-admin"
policy = <<EOT
# Full access to KV secrets
path "secret/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
# Read system health and metrics
path "sys/health" {
capabilities = ["read"]
}
path "sys/metrics" {
capabilities = ["read"]
}
# List auth methods and mounts
path "sys/auth" {
capabilities = ["read"]
}
path "sys/mounts" {
capabilities = ["read"]
}
EOT
}
# OIDC default policy - minimal access for authenticated users
resource "vault_policy" "oidc_default" {
name = "oidc-default"
policy = <<EOT
# Read own token info
path "auth/token/lookup-self" {
capabilities = ["read"]
}
# Read system health
path "sys/health" {
capabilities = ["read"]
}
EOT
}

View File

@@ -115,6 +115,12 @@ locals {
password_length = 64 password_length = 64
} }
# OpenBao OAuth2 client secret (for Kanidm OIDC)
"services/openbao/oauth2-client-secret" = {
auto_generate = true
password_length = 64
}
# NKey for nixos-exporter NATS cache sharing # NKey for nixos-exporter NATS cache sharing
"shared/nixos-exporter/nkey" = { "shared/nixos-exporter/nkey" = {
auto_generate = false auto_generate = false