diff --git a/bootstrap/platform/main.tf b/bootstrap/platform/main.tf index d9779e2..5bd974d 100644 --- a/bootstrap/platform/main.tf +++ b/bootstrap/platform/main.tf @@ -970,7 +970,7 @@ resource "helm_release" "traefik" { wait = true # Helm waits for the LoadBalancer IP; the allocator and its pool must # exist first, especially when OpenTofu parallelism is one. - depends_on = [null_resource.calico_ready, null_resource.metallb_l2_config] + depends_on = [null_resource.calico_ready, null_resource.metallb_l2_config] values = [ yamlencode({ @@ -1149,6 +1149,16 @@ resource "helm_release" "argocd" { params = { "server.insecure" = true } + cm = var.argocd_sso_enabled ? { + url = trimsuffix(var.argocd_public_url, "/") + "oidc.config" = yamlencode({ + name = "Dex" + issuer = trimsuffix(var.grafana_oidc_url, "/") + clientID = "argocd" + clientSecret = "$argocd-dex-oauth:clientSecret" + requestedScopes = ["openid", "profile", "email"] + }) + } : {} } applicationSet = { nodeSelector = local.argocd_node_selector @@ -1581,8 +1591,8 @@ resource "helm_release" "kyverno_policies" { validationAllowExistingViolations = true # Keep admission-time auditing, but do not continuously rescan the # hostPath-heavy system workloads and churn PolicyReports in etcd. - background = false - failurePolicy = "Ignore" + background = false + failurePolicy = "Ignore" }) ] } @@ -2094,25 +2104,25 @@ resource "helm_release" "prometheus_stack" { } prometheus = { prometheusSpec = { - externalLabels = { cluster_profile = var.cluster_profile, cluster_uid = var.cluster_identity_uid } + externalLabels = { cluster_profile = var.cluster_profile, cluster_uid = var.cluster_identity_uid } priorityClassName = kubernetes_priority_class_v1.monitoring.metadata[0].name nodeSelector = local.prometheus_stack_node_selector retention = var.observability.prometheus.retention additionalScrapeConfigs = yamlencode(concat([ { - job_name = "debian-host" + job_name = "debian-host" static_configs = [{ targets = [var.debian_host_metrics_target], labels = { host_group = "debian-laptop" } }] }, { - job_name = "pimox-host" + job_name = "pimox-host" static_configs = [{ targets = [var.pimox_host_metrics_target], labels = { host_group = "orange-pi-hypervisor" } }] }, { - job_name = "debian-compose" + job_name = "debian-compose" static_configs = [{ targets = [var.debian_compose_metrics_target], labels = { host_group = "debian-laptop" } }] }, { - job_name = "rpi-compose" + job_name = "rpi-compose" static_configs = [{ targets = [var.rpi_compose_metrics_target], labels = { host_group = "edge-dns-worker" } }] }, { @@ -2419,10 +2429,10 @@ resource "helm_release" "extra_tools" { create_namespace = each.value.create_namespace timeout = each.value.timeout values = concat(each.value.values_yaml != "" ? [each.value.values_yaml] : [], each.key == "tetragon" ? [yamlencode({ - tetragon = { enabled = var.tetragon_agent_enabled } + tetragon = { enabled = var.tetragon_agent_enabled } nodeSelector = { "homelab.dev/kernel-btf" = "true" } })] : []) - depends_on = [null_resource.calico_ready] + depends_on = [null_resource.calico_ready] dynamic "set" { for_each = each.value.set_values diff --git a/bootstrap/platform/variables.tf b/bootstrap/platform/variables.tf index 4ef4870..1612536 100644 --- a/bootstrap/platform/variables.tf +++ b/bootstrap/platform/variables.tf @@ -354,6 +354,18 @@ variable "grafana_sso_enabled" { default = false } +variable "argocd_sso_enabled" { + description = "Enable Argo CD OIDC when the Dex client secret exists." + type = bool + default = false +} + +variable "argocd_public_url" { + description = "Public Argo CD URL used for OIDC callbacks." + type = string + default = "https://argocd.lab2025.duckdns.org" +} + variable "grafana_oidc_url" { description = "Public OIDC issuer URL used by Grafana's OAuth client." type = string @@ -390,8 +402,8 @@ variable "extra_helm_releases" { default = { tetragon = { - repository = "https://helm.cilium.io" - chart = "tetragon" + repository = "https://helm.cilium.io" + chart = "tetragon" # Tetragon 1.8 CRD CEL expressions are rejected by the k3s 1.31 API # server; keep the known-compatible 1.7.1 chart until the CRDs are # published with a schema compatible with this Kubernetes minor. diff --git a/infra/dex/README.md b/infra/dex/README.md index 0086520..7916397 100644 --- a/infra/dex/README.md +++ b/infra/dex/README.md @@ -22,6 +22,19 @@ Managed OIDC clients: - Grafana: `https://grafana.lab2025.duckdns.org/login/generic_oauth` - Gitea: `https://lab2025.duckdns.org/git/user/oauth2/dex/callback` +- Argo CD: `https://argocd.lab2025.duckdns.org/auth/callback` + +`./jeannie sso apply` creates an Argo CD client secret in the encrypted Dex +secret file when needed, installs the corresponding Kubernetes secret, and +configures the platform chart. Back up and commit the updated encrypted file +so the client secret survives a rebuild. Argo CD SSO users receive its default +read-only role; the existing local administrator remains available. This flow +requires a working Kubernetes API and an active Dex service. + +n8n has its own user accounts; configuring an ingress login alone would not +replace them. Native n8n OIDC depends on its supported license and must be +configured in n8n. Application API tokens and the deliberately vulnerable +security-lab application are not interactive Dex clients. The encrypted Dex secret is expected at: diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 547fd7e..8655c25 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -17,6 +17,16 @@ configure_platform_grafana_sso() { fi } +configure_platform_argocd_sso() { + export TF_VAR_argocd_public_url="${LAB_ARGOCD_PUBLIC_URL:-https://argocd.${LAB_DOMAIN:-lab2025.duckdns.org}}" + if command -v kubectl >/dev/null 2>&1 && + kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${LAB_ARGOCD_NAMESPACE:-argocd}" get secret argocd-dex-oauth >/dev/null 2>&1; then + export TF_VAR_argocd_sso_enabled=true + else + export TF_VAR_argocd_sso_enabled=false + fi +} + configure_platform_tetragon_capabilities() { local enabled enabled="$(python3 "${REPO_ROOT}/scripts/tetragon-capabilities.py" "$@")" || return 1 @@ -828,6 +838,7 @@ run_tofu_stack() { if [[ "${stack}" == "bootstrap/platform" ]]; then configure_platform_grafana_sso + configure_platform_argocd_sso ensure_platform_scheduling_labels || return 1 configure_platform_tetragon_capabilities --label-nodes || return 1 fi @@ -896,6 +907,7 @@ run_tofu_plan_stack() { if [[ "${stack}" == "bootstrap/platform" ]]; then configure_platform_grafana_sso + configure_platform_argocd_sso configure_platform_tetragon_capabilities || return 1 fi @@ -971,7 +983,21 @@ render_dex_config() { local user_password_hash="${10}" local office_public_url="${11:-}" local office_client_secret="${12:-}" + local argocd_public_url="${13:-}" + local argocd_client_secret="${14:-}" local office_client_block="" + local argocd_client_block="" + + if [[ -n "${argocd_public_url}" && -n "${argocd_client_secret}" ]]; then + argocd_client_block="$(cat </dev/null sudo chown "${dex_uid}:${dex_gid}" "${install_dir}/config.yaml" sudo chown -R "${dex_uid}:${dex_gid}" "${data_dir}" @@ -1286,6 +1315,30 @@ OFFICE_OIDC_EOF echo "Nextcloud data: ${nextcloud_data_dir}; ONLYOFFICE endpoint: https://${onlyoffice_host}." } +ensure_argocd_dex_client() { + local dex_env secret_file client_secret + dex_env="$(dex_secret_values)" || return 1 + eval "${dex_env}" + if [[ -z "${DEX_ARGOCD_CLIENT_SECRET:-}" ]]; then + secret_file="$(dex_secret_file)" + client_secret="$(generate_dex_secret_value)" || return 1 + SOPS_AGE_KEY_FILE="$(sops_age_key_file)" sops set "${secret_file}" \ + '["stringData"]["DEX_ARGOCD_CLIENT_SECRET"]' "\"${client_secret}\"" || return 1 + echo "Added encrypted Argo CD client secret to ${secret_file}; back up and commit the encrypted file." + fi +} + +configure_argocd_dex_secret() { + local dex_env + dex_env="$(dex_secret_values)" || return 1 + eval "${dex_env}" + [[ -n "${DEX_ARGOCD_CLIENT_SECRET:-}" ]] || return 1 + kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${LAB_ARGOCD_NAMESPACE:-argocd}" create secret generic argocd-dex-oauth \ + --from-literal=clientSecret="${DEX_ARGOCD_CLIENT_SECRET}" --dry-run=client -o yaml | + kubectl --kubeconfig "${KUBECONFIG_PATH}" apply -f - || return 1 + kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${LAB_ARGOCD_NAMESPACE:-argocd}" label secret argocd-dex-oauth app.kubernetes.io/part-of=argocd --overwrite +} + configure_grafana_dex_secret() { local namespace="${TF_VAR_grafana_namespace:-monitoring}" local secret_name="${TF_VAR_grafana_oauth_secret_name:-grafana-dex-oauth}" @@ -1441,11 +1494,14 @@ sso() { plan) grafana_sso plan gitea_sso plan + echo "Argo CD: Dex OIDC will be configured with read-only default access." ;; apply) + ensure_argocd_dex_client || return 1 deploy_dex edge_apply configure_grafana_dex_secret + configure_argocd_dex_secret || return 1 run_tofu_stack "bootstrap/platform" configure_gitea_sso_source edge_flush_caches diff --git a/lib/jeannie/security.sh b/lib/jeannie/security.sh index a779893..2a40c9b 100644 --- a/lib/jeannie/security.sh +++ b/lib/jeannie/security.sh @@ -327,7 +327,7 @@ required = [ "DEX_USER_ID", "DEX_USER_PASSWORD", ] -optional = ["DEX_OFFICE_CLIENT_SECRET"] +optional = ["DEX_OFFICE_CLIENT_SECRET", "DEX_ARGOCD_CLIENT_SECRET"] missing = [key for key in required if not values.get(key)] if missing: print(f"Missing Dex secret keys: {', '.join(missing)}", file=sys.stderr)