Commit Graph
160 Commits
Author SHA1 Message Date
Story Crater Bot b8c3528848 fix(temporal): actually enable PostgreSQL persistence (chart schema mismatch)
Root cause: pinned to temporalio/helm-charts @ 0.74.0, which uses the OLD
flat persistence schema (server.config.persistence.<store>.driver/.sql),
NOT the datastores:-wrapped schema shown in the CURRENT chart's
values/values.postgresql.yaml example (that key was introduced in a later
major version). Our old values.yaml used the datastores: key, which doesn't
exist in 0.74.0 - Helm doesn't validate unknown keys, so it was silently a
no-op. persistence.default.driver / persistence.visibility.driver stayed at
their chart default ("cassandra", with empty hosts: []) the entire time,
regardless of anything nested under datastores:.

Verified before writing this fix: cloned temporalio/helm-charts, checked out
tag temporal-0.74.0 (exact pin), ran  +
 against our actual values.yaml - confirmed the rendered
schema-setup Job used CASSANDRA_HOST/temporal-cassandra-tool the whole time.
Re-rendered with the corrected flat schema - zero Cassandra references,
correct postgres12 pluginName/connectAddr wired to ddb-cluster-rw.

Also fixed two compounding no-ops found the same way:
  -  -> real keys are schema.setup.enabled /
    schema.update.enabled / schema.createDatabase.enabled (jobs.autoSetup
    doesn't exist anywhere in this chart's templates or values.yaml).
  - cassandra.enabled was never actually set to false (stayed at chart
    default true) - now explicitly false, along with mysql/elasticsearch/
    prometheus/grafana (none of which we want).

Password wiring: existingSecret: temporal-db-role + secretKey: password,
pointing at the CNPG-generated Secret - avoids storing the DB password as
plaintext in this values file. Added a new temporal-db-secret-sync
Application (sync-wave 7, one before temporal's wave 8) with a PreSync hook
Job that copies that Secret from the ddb namespace into temporal (Secrets
are namespace-scoped; CNPG creates it in ddb, but Temporal's pods run in
temporal). Deliberately a standalone directory/Application rather than
folded into temporal/'s own kustomization.yaml, which has a The Temporal CLI manages, monitors, and debugs Temporal apps. It lets you run
a local Temporal Service, start Workflow Executions, pass messages to running
Workflows, inspect state, and more.

* Start a local development service:
      `temporal server start-dev`
* View help: pass `--help` to any command:
      `temporal activity complete --help`

Usage:
  temporal [command]

Available Commands:
  activity    Operate on Activity Executions
  batch       Manage running batch jobs
  completion  Generate the autocompletion script for the specified shell
  config      Manage config files (EXPERIMENTAL)
  env         Manage environments
  help        Help about any command
  operator    Manage Temporal deployments
  schedule    Perform operations on Schedules
  server      Run Temporal Server
  task-queue  Manage Task Queues
  worker      Read or update Worker state
  workflow    Start, list, and operate on Workflows

Flags:
      --client-connect-timeout duration
                The client connection timeout. 0s means no timeout.
                (default 0s)
      --color string
                Output coloring. Accepted values: always, never, auto.
                (default "auto")
      --command-timeout duration
                The command execution timeout. 0s means no timeout.
                (default 0s)
      --config-file $CONFIG_PATH/temporalio/temporal.toml
                File path to read TOML config from, defaults to
                $CONFIG_PATH/temporalio/temporal.toml where
                `$CONFIG_PATH` is defined as `$HOME/.config` on Unix,
                `$HOME/Library/Application Support` on macOS, and
                `%AppData%` on Windows.
      --disable-config-env
                If set, disables loading environment config from
                environment variables.
      --disable-config-file
                If set, disables loading environment config from config file.
      --env ENV
                Active environment name (ENV). (default "default")
      --env-file $HOME/.config/temporalio/temporal.yaml
                Path to environment settings file. Defaults to
                $HOME/.config/temporalio/temporal.yaml.
  -h, --help
                help for temporal
      --log-format string
                Log format. Accepted values: text, json. (default "text")
      --log-level string
                Log level. Default is "never" for most commands and
                "warn" for "server start-dev". Accepted values: debug,
                info, warn, error, never. (default "never")
      --no-json-shorthand-payloads
                Raw payload output, even if the JSON option was used.
  -o, --output string
                Non-logging data output format. Accepted values: text,
                json, jsonl, none. (default "text")
      --profile string
                Profile to use for config file.
      --time-format string
                Time format. Accepted values: relative, iso, raw.
                (default "relative")
  -v, --version
                version for temporal

Use "temporal [command] --help" for more information about a command. transformer that would silently rewrite the copy-job's ddb-scoped
RoleBinding back to temporal (same class of bug just fixed in
k8s/security/iam/kustomization.yaml).
2026-07-21 16:49:20 -07:00
Story Crater Bot f08fb2bb75 fix(iam): register authentik-provision-job.yaml in kustomization + remove unsafe namespace transformer
Root cause of the provisioning Job never appearing in-cluster despite being
committed and pushed: k8s/security/iam/kustomization.yaml has an explicit
resources: allowlist (not a plain directory scan) and the new file was never
added to it, so ArgoCD's Kustomize build silently omitted every object in it
- no error, no drift shown, iam-jobs just reported Synced/Healthy against a
manifest set that never included the new Job/ConfigMap/RBAC at all.

Also removed the top-level  transformer. It would have
force-rewritten metadata.namespace to iam on every resource in this
kustomization, including authentik-provision-job.yaml's RoleBindings which
deliberately target cicd/argocd/logging/storage (least-privilege access for
the authentik-provisioner ServiceAccount to read/create Secrets in exactly
those namespaces and no others). Every manifest in this directory already
sets its own explicit namespace, so dropping the transformer is a no-op for
the existing key-rotation-cronjob.yaml.

Verified with apiVersion: v1
kind: ServiceAccount
metadata:
  name: authentik-provisioner
  namespace: iam
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: authentik-provisioner
rules:
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - get
  - list
  - create
  - update
  - patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: authentik-provisioner
  namespace: argocd
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: authentik-provisioner
subjects:
- kind: ServiceAccount
  name: authentik-provisioner
  namespace: iam
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: authentik-provisioner
  namespace: cicd
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: authentik-provisioner
subjects:
- kind: ServiceAccount
  name: authentik-provisioner
  namespace: iam
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: authentik-provisioner
  namespace: iam
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: authentik-provisioner
subjects:
- kind: ServiceAccount
  name: authentik-provisioner
  namespace: iam
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: authentik-provisioner
  namespace: logging
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: authentik-provisioner
subjects:
- kind: ServiceAccount
  name: authentik-provisioner
  namespace: iam
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: authentik-provisioner
  namespace: storage
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: authentik-provisioner
subjects:
- kind: ServiceAccount
  name: authentik-provisioner
  namespace: iam
---
apiVersion: v1
data:
  authentik-provision.py: |
    #!/usr/bin/env python3
    """
    Authentik OAuth provisioning - idempotent, safe to re-run (ArgoCD PostSync hook).

    Creates/updates, in order:
      1. A custom "groups" OAuth2 scope mapping (Authentik ships openid/email/profile
         by default but NOT groups - required for ArgoCD RBAC group mapping and
         Grafana's role_attribute_path, both of which read a `groups` claim).
      2. Groups: homelab-admins (is_superuser=true), grafana-admins.
      3. User "rock": created if missing, always (re-)synced into both groups above.
         Password is generated once and only written to the k8s Secret
         rock-credentials (iam ns) the first time the user is created - re-runs
         never rotate an existing password.
      4. OAuth2/OIDC providers + Applications for: grafana, minio, forgejo, argocd.
         Client secrets are read from existing k8s Secrets (grafana-oidc, minio-oidc)
         if present, or generated once and written out (forgejo-oidc, oidc-secret)
         the first time.
      5. PolicyBinding of homelab-admins -> every Application above, so "rock" (and
         anyone else in that group) has guaranteed access regardless of each app's
         default visibility.

    Talks to Authentik over the in-cluster Service (authentik-server.iam.svc:80),
    authenticating with the bootstrap token. Everything is done with GET-then-
    create-or-patch so this can be re-run on every ArgoCD sync without duplicating
    or clobbering objects (PostSync hook, not a one-shot Job with hook-delete).

    kubectl is used only to read/write the small set of Secrets this script
    touches - it shells out rather than using the Python k8s client to keep the
    container image to stdlib Python + the kubectl binary, no pip installs.
    """
    import json
    import os
    import secrets
    import string
    import subprocess
    import sys
    import urllib.error
    import urllib.request

    AUTHENTIK_URL = "http://authentik-server.iam.svc.cluster.local"
    TOKEN = os.environ["AUTHENTIK_BOOTSTRAP_TOKEN"]

    def api(method, path, data=None):
        url = f"{AUTHENTIK_URL}{path}"
        body = json.dumps(data).encode() if data is not None else None
        req = urllib.request.Request(
            url,
            data=body,
            method=method,
            headers={
                "Authorization": f"Bearer {TOKEN}",
                "Content-Type": "application/json",
            },
        )
        try:
            with urllib.request.urlopen(req, timeout=30) as resp:
                raw = resp.read()
                return resp.status, (json.loads(raw) if raw else {})
        except urllib.error.HTTPError as e:
            raw = e.read()
            try:
                parsed = json.loads(raw) if raw else {}
            except json.JSONDecodeError:
                parsed = {"raw": raw.decode(errors="replace")}
            return e.code, parsed

    def die(msg):
        print(f"FATAL: {msg}", file=sys.stderr)
        sys.exit(1)

    def gen_secret(n=40):
        alphabet = string.ascii_letters + string.digits
        return "".join(secrets.choice(alphabet) for _ in range(n))

    def kubectl_get_secret_key(namespace, name, key):
        """Returns decoded value, or None if the secret/key doesn't exist."""
        p = subprocess.run(
            ["kubectl", "-n", namespace, "get", "secret", name, "-o", f"jsonpath={{.data.{key}}}"],
            capture_output=True, text=True,
        )
        if p.returncode != 0 or not p.stdout.strip():
            return None
        import base64
        return base64.b64decode(p.stdout).decode()

    def kubectl_create_secret(namespace, name, literals: dict):
        """Idempotent: create-or-update via dry-run|apply, same pattern used
        elsewhere in this repo (setup_vault.sh, apply-vault-secrets.sh)."""
        args = ["kubectl", "-n", namespace, "create", "secret", "generic", name]
        for k, v in literals.items():
            args += [f"--from-literal={k}={v}"]
        args += ["--dry-run=client", "-o", "yaml"]
        render = subprocess.run(args, capture_output=True, text=True)
        if render.returncode != 0:
            die(f"rendering secret {namespace}/{name}: {render.stderr}")
        apply = subprocess.run(["kubectl", "apply", "-f", "-"], input=render.stdout,
                                capture_output=True, text=True)
        if apply.returncode != 0:
            die(f"applying secret {namespace}/{name}: {apply.stderr}")
        print(f"  secret {namespace}/{name}: {apply.stdout.strip()}")

    def get_or_create(list_path, create_path, query, payload, patch_existing=None):
        status, res = api("GET", f"{list_path}?{query}")
        if status != 200:
            die(f"GET {list_path}?{query} -> {status} {res}")
        results = res.get("results", [])
        if results:
            obj = results[0]
            if patch_existing:
                status, obj2 = api("PATCH", f"{create_path}{obj['pk']}/", patch_existing)
                if status not in (200, 201):
                    die(f"PATCH {create_path}{obj['pk']}/ -> {status} {obj2}")
                return obj2
            return obj
        status, obj = api("POST", create_path, payload)
        if status not in (200, 201):
            die(f"POST {create_path} -> {status} {obj}")
        return obj

    # -----------------------------------------------------------------------------
    print("[1/5] Ensuring custom 'groups' scope mapping exists...")
    groups_mapping = get_or_create(
        "/api/v3/propertymappings/provider/scope/",
        "/api/v3/propertymappings/provider/scope/",
        "scope_name=groups",
        {
            "name": "homelab: groups claim",
            "scope_name": "groups",
            "expression": (
                "return {\"groups\": [group.name for group in request.user.ak_groups.all()]}"
            ),
        },
    )
    GROUPS_MAPPING_PK = groups_mapping["pk"]

    # Fetch the standard openid/email/profile mapping pks (shipped by default).
    status, res = api("GET", "/api/v3/propertymappings/provider/scope/")
    by_scope = {m["scope_name"]: m["pk"] for m in res["results"]}
    SCOPE_PKS = [by_scope["openid"], by_scope["email"], by_scope["profile"], GROUPS_MAPPING_PK]

    status, res = api("GET", "/api/v3/flows/instances/?slug=default-provider-authorization-implicit-consent")
    AUTHORIZATION_FLOW_PK = res["results"][0]["pk"]
    status, res = api("GET", "/api/v3/flows/instances/?slug=default-provider-invalidation-flow")
    INVALIDATION_FLOW_PK = res["results"][0]["pk"]
    status, res = api("GET", "/api/v3/crypto/certificatekeypairs/?has_key=true")
    SIGNING_KEY_PK = res["results"][0]["pk"]

    # -----------------------------------------------------------------------------
    print("[2/5] Ensuring groups homelab-admins / grafana-admins exist...")
    homelab_admins = get_or_create(
        "/api/v3/core/groups/", "/api/v3/core/groups/",
        "name=homelab-admins",
        {"name": "homelab-admins", "is_superuser": True},
    )
    grafana_admins = get_or_create(
        "/api/v3/core/groups/", "/api/v3/core/groups/",
        "name=grafana-admins",
        {"name": "grafana-admins", "is_superuser": False},
    )

    # -----------------------------------------------------------------------------
    print("[3/5] Ensuring user 'rock' exists with admin group membership...")
    status, res = api("GET", "/api/v3/core/users/?username=rock")
    rock_password = None
    if res.get("results"):
        rock = res["results"][0]
        status, rock = api("PATCH", f"/api/v3/core/users/{rock['pk']}/", {
            "groups": [homelab_admins["pk"], grafana_admins["pk"]],
            "is_active": True,
        })
        if status not in (200, 201):
            die(f"PATCH user rock -> {status} {rock}")
        print("  rock already exists, group membership synced (password unchanged)")
    else:
        rock_password = gen_secret(24)
        status, rock = api("POST", "/api/v3/core/users/", {
            "username": "rock",
            "name": "Rock",
            "is_active": True,
            "groups": [homelab_admins["pk"], grafana_admins["pk"]],
            "path": "users",
            "type": "internal",
        })
        if status not in (200, 201):
            die(f"POST user rock -> {status} {rock}")
        status, pw_res = api("POST", f"/api/v3/core/users/{rock['pk']}/set_password/",
                              {"password": rock_password})
        if status not in (200, 204):
            die(f"set_password for rock -> {status} {pw_res}")
        kubectl_create_secret("iam", "rock-credentials", {
            "username": "rock",
            "password": rock_password,
        })
        print("  rock created, credentials stored in iam/rock-credentials")

    # -----------------------------------------------------------------------------
    print("[4/5] Ensuring OAuth2 providers + applications for grafana/minio/forgejo/argocd...")

    SERVICES = {
        "grafana": {
            "client_secret_source": ("logging", "grafana-oidc", "GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET"),
            "redirect_uris": ["https://grafana.riotpiao.com/login/generic_oauth"],
            "launch_url": "https://grafana.riotpiao.com",
            "display_name": "Grafana",
        },
        "minio": {
            "client_secret_source": ("storage", "minio-oidc", "MINIO_IDENTITY_OPENID_CLIENT_SECRET"),
            "redirect_uris": ["https://minio.riotpiao.com/oauth_callback"],
            "launch_url": "https://minio.riotpiao.com",
            "display_name": "MinIO",
        },
        "forgejo": {
            # No secret exists yet for forgejo - generate + store on first run.
            "client_secret_source": ("cicd", "forgejo-oidc", "CLIENT_SECRET"),
            "generate_if_missing": True,
            "redirect_uris": [
                "https://forgejo.riotpiao.com/user/oauth2/authentik/callback",
                "https://forgejo.riotpiao.com/user/oauth2/openidconnect/callback",
            ],
            "launch_url": "https://forgejo.riotpiao.com",
            "display_name": "Forgejo",
        },
        "argocd": {
            # oidc-secret uses hyphenated keys (client-id/client-secret) per
            # argocd-values.yaml's `$oidc-secret:client-id` / `:client-secret` refs.
            "client_secret_source": ("argocd", "oidc-secret", "client-secret"),
            "generate_if_missing": True,
            "extra_secret_literals": {"client-id": "argocd"},
            "redirect_uris": ["https://argocd.riotpiao.com/auth/callback"],
            "launch_url": "https://argocd.riotpiao.com",
            "display_name": "Argo CD",
        },
    }

    app_pks_for_binding = []

    for name, cfg in SERVICES.items():
        ns, secret_name, key = cfg["client_secret_source"]
        client_secret = kubectl_get_secret_key(ns, secret_name, key)
        if client_secret is None:
            if not cfg.get("generate_if_missing"):
                print(f"  WARNING: {ns}/{secret_name} key {key} not found and "
                      f"generate_if_missing not set for '{name}' - skipping provider/app")
                continue
            client_secret = gen_secret(40)
            literals = {key: client_secret}
            literals.update(cfg.get("extra_secret_literals", {}))
            kubectl_create_secret(ns, secret_name, literals)
            print(f"  {name}: generated new client secret -> {ns}/{secret_name}")
        else:
            print(f"  {name}: using existing client secret from {ns}/{secret_name}")

        provider = get_or_create(
            "/api/v3/providers/oauth2/", "/api/v3/providers/oauth2/",
            f"name={name}",
            {
                "name": name,
                "client_id": name,
                "client_secret": client_secret,
                "client_type": "confidential",
                "authorization_flow": AUTHORIZATION_FLOW_PK,
                "invalidation_flow": INVALIDATION_FLOW_PK,
                "signing_key": SIGNING_KEY_PK,
                "property_mappings": SCOPE_PKS,
                "sub_mode": "hashed_user_id",
                "include_claims_in_id_token": True,
                "redirect_uris": [
                    {"matching_mode": "strict", "url": u} for u in cfg["redirect_uris"]
                ],
            },
            # Keep the redirect_uris/mappings in sync on re-run, but never touch
            # client_secret again once created (that's the source of truth in the
            # k8s Secret, and re-sending it here is harmless/idempotent anyway).
            patch_existing={
                "property_mappings": SCOPE_PKS,
                "redirect_uris": [
                    {"matching_mode": "strict", "url": u} for u in cfg["redirect_uris"]
                ],
            },
        )

        application = get_or_create(
            "/api/v3/core/applications/", "/api/v3/core/applications/",
            f"slug={name}",
            {
                "name": cfg["display_name"],
                "slug": name,
                "provider": provider["pk"],
                "meta_launch_url": cfg["launch_url"],
            },
            patch_existing={
                "provider": provider["pk"],
                "meta_launch_url": cfg["launch_url"],
            },
        )
        app_pks_for_binding.append((name, application["pk"]))
        print(f"  {name}: provider pk={provider['pk']} application pk={application['pk']}")

    # -----------------------------------------------------------------------------
    print("[5/5] Binding homelab-admins to every application (guaranteed access for rock)...")
    for name, app_pk in app_pks_for_binding:
        get_or_create(
            "/api/v3/policies/bindings/", "/api/v3/policies/bindings/",
            f"target={app_pk}&group={homelab_admins['pk']}",
            {
                "target": app_pk,
                "group": homelab_admins["pk"],
                "order": 0,
                "enabled": True,
            },
        )
        print(f"  {name}: homelab-admins bound")

    print("\nDone. Summary:")
    print("  groups:  homelab-admins (superuser), grafana-admins")
    print("  user:    rock -> homelab-admins + grafana-admins")
    print(f"  apps:    {', '.join(n for n, _ in app_pks_for_binding)}")
    if rock_password:
        print("  NOTE: rock's password was generated this run - see")
        print("  kubectl -n iam get secret rock-credentials -o jsonpath='{.data.password}' | base64 -d")
kind: ConfigMap
metadata:
  name: authentik-provision-script
  namespace: iam
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: authentik-key-rotation
  namespace: iam
spec:
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - command:
            - sh
            - -c
            - rustc /scripts/rotate_key.rs -o /tmp/rotate_key && /tmp/rotate_key
            env:
            - name: AUTHENTIK_BASE_URL
              value: http://authentik-server.iam.svc.cluster.local
            - name: AUTHENTIK_BOOTSTRAP_TOKEN
              valueFrom:
                secretKeyRef:
                  key: AUTHENTIK_BOOTSTRAP_TOKEN
                  name: authentik-key-rotation-token
            image: rust:1.82-slim
            name: rotate
            volumeMounts:
            - mountPath: /scripts
              name: script
          restartPolicy: OnFailure
          volumes:
          - configMap:
              name: key-rotation-script
            name: script
  schedule: 0 0 1 */3 *
---
apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
  name: authentik-provision
  namespace: iam
spec:
  backoffLimit: 3
  template:
    spec:
      containers:
      - command:
        - /bin/sh
        - -c
        - |
          set -e
          echo "waiting for authentik-server..."
          until wget -q -O /dev/null http://authentik-server.iam.svc.cluster.local/-/health/ready/ 2>/dev/null; do
            sleep 5
          done
          echo "installing kubectl..."
          apk add --no-cache curl >/dev/null
          KVER=$(curl -sL https://dl.k8s.io/release/stable.txt)
          curl -sLo /usr/local/bin/kubectl "https://dl.k8s.io/release/${KVER}/bin/linux/amd64/kubectl"
          chmod +x /usr/local/bin/kubectl
          echo "running provisioning script..."
          python3 /script/authentik-provision.py
        env:
        - name: AUTHENTIK_BOOTSTRAP_TOKEN
          valueFrom:
            secretKeyRef:
              key: AUTHENTIK_BOOTSTRAP_TOKEN
              name: authentik-secrets
        image: python:3.12-alpine
        name: provision
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
        volumeMounts:
        - mountPath: /script
          name: script
      restartPolicy: Never
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        seccompProfile:
          type: RuntimeDefault
      serviceAccountName: authentik-provisioner
      volumes:
      - configMap:
          name: authentik-provision-script
        name: script
  ttlSecondsAfterFinished: 600 locally before pushing -
confirms all 5 RoleBindings land in their correct distinct namespaces
(iam/cicd/argocd/logging/storage) and every resource renders as valid YAML.
2026-07-21 16:33:53 -07:00
Story Crater Bot d602ed8c78 feat(iam): automate Authentik OAuth provisioning + create admin user rock
Adds k8s/security/iam/authentik-provision-job.yaml - a PostSync hook Job
(reruns every ArgoCD sync via hook-delete-policy: BeforeHookCreation) that
replaces the never-migrated setup_talos_iam.sh / provision_oidc.py workflow
(both referenced helmfile + a Python script that no longer exists in this
repo - OAuth was never actually provisioned since the ArgoCD migration).

Idempotently creates:
  - Custom 'groups' OAuth2 scope mapping (Authentik doesn't ship one by
    default; required for ArgoCD's RBAC groups claim and Grafana's
    role_attribute_path, both of which read a groups claim from the token).
  - Groups: homelab-admins (is_superuser), grafana-admins.
  - User 'rock', member of both groups above - gets full Authentik superuser
    access, ArgoCD role:admin via the existing
     RBAC policy in argocd-values.yaml, and
    Grafana Admin role via role_attribute_path. Password generated once,
    stored in iam/rock-credentials (never rotated on re-run).
  - OAuth2 providers + Applications for grafana, minio, forgejo, argocd.
    Client secrets read from existing Secrets (grafana-oidc, minio-oidc) or
    generated once and written out (forgejo-oidc, argocd's oidc-secret).
  - PolicyBinding of homelab-admins -> every Application, guaranteeing rock
    access regardless of each app's default visibility.

Also fixes forgejo-values.yaml: oauth2.CLIENT_ID was set but CLIENT_SECRET
was missing entirely (oauth2 login could never have worked). Added via
extraEnv -> GITEA__oauth2__CLIENT_SECRET sourced from the new forgejo-oidc
Secret, since the oauth2: values map can't reference a Secret inline.

RBAC: dedicated ServiceAccount + ClusterRole (secrets get/list/create/update/
patch only) bound via namespace-scoped RoleBindings in iam/cicd/argocd/
logging/storage - the only 5 namespaces this job ever touches, and the only
resource type it ever touches.

NOTE: MinIO's OIDC env vars were removed from minio-tenant.yaml earlier
(blocked IAM init because the provider/app didn't exist yet -> 404 on
discovery). Now that this job creates them, re-adding MinIO's OIDC config is
a safe follow-up in a separate change.
2026-07-21 16:31:03 -07:00
Story Crater Bot 1dd261bb25 fix(monitoring,minio): prometheus CRD sync loop + stuck minio-policy-setup hook
1. prometheus CRD sync failure (OutOfSync, permanently failing):
   - helm.skipCrds: true on the prometheus Application - stop ArgoCD from
     managing these CRDs through client-side apply (kube-prometheus-stack's
     CRDs are large enough that the kubectl.kubernetes.io/last-applied-
     configuration annotation exceeds etcd's 262144-byte limit on every sync).
   - New prometheus-crds Application: plain git-sourced YAML (extracted via
     helm show crds, committed under k8s/platform/monitoring/crds/), synced
     with ServerSideApply=true. Chosen over a Helm-sourced 'CRDs only' app
     because there's no clean way to ask ArgoCD's Helm source for 'render only
     the crds/ directory' - a committed plain-YAML source is unambiguous.
   - ServerSideApply=true can't go on the main prometheus Application: it
     conflicts with managedNamespaceMetadata's forced namespace apply
     ('--force cannot be used with --server-side'), hence the split.

2. minio-tenant stuck OutOfSync (blocked 97+ minutes):
   - minio-policy-setup PostSync hook Job was NAME:
  mc alias set - set a new alias to configuration file

USAGE:
  mc alias set ALIAS URL ACCESSKEY SECRETKEY

FLAGS:
  --path value                     bucket path lookup supported by the server. Valid options are '[auto, on, off]' (default: "auto")
  --api value                      API signature. Valid options are '[S3v4, S3v2]'
  --config-dir value, -C value     path to configuration folder (default: "/Users/rockliang/.mc") [$MC_CONFIG_DIR]
  --quiet, -q                      disable progress bar display [$MC_QUIET]
  --disable-pager, --dp            disable mc internal pager and print to raw stdout [$MC_DISABLE_PAGER]
  --no-color                       disable color theme [$MC_NO_COLOR]
  --json                           enable JSON lines formatted output [$MC_JSON]
  --debug                          enable debug output [$MC_DEBUG]
  --resolve value                  resolves HOST[:PORT] to an IP address. Example: minio.local:9000=10.10.75.1 [$MC_RESOLVE]
  --insecure                       disable SSL certificate verification [$MC_INSECURE]
  --limit-upload value             limits uploads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited) [$MC_LIMIT_UPLOAD]
  --limit-download value           limits downloads to a maximum rate in KiB/s, MiB/s, GiB/s. (default: unlimited) [$MC_LIMIT_DOWNLOAD]
  --custom-header value, -H value  add custom HTTP header to the request. 'key:value' format.
  --help, -h                       show help

EXAMPLES:
  1. Add MinIO service under "myminio" alias. For security reasons turn off bash history momentarily.
     $ set +o history
     $ mc alias set myminio http://localhost:9000 minio minio123
     $ set -o history
  2. Add MinIO service under "myminio" alias, to use dns style bucket lookup. For security reasons
     turn off bash history momentarily.
     $ set +o history
     $ mc alias set myminio http://localhost:9000 minio minio123 --api "s3v4" --path "off"
     $ set -o history
  3. Add Amazon S3 storage service under "mys3" alias. For security reasons turn off bash history momentarily.
     $ set +o history
     $ mc alias set mys3 https://s3.amazonaws.com \
                 BKIKJAA5BMMU2RHO6IBB V8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
     $ set -o history
  4. Add Amazon S3 storage service under "mys3" alias, prompting for keys.
     $ mc alias set mys3 https://s3.amazonaws.com --api "s3v4" --path "off"
     Enter Access Key: BKIKJAA5BMMU2RHO6IBB
     Enter Secret Key: V8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
  5. Add Amazon S3 storage service under "mys3" alias using piped keys.
     $ set +o history
     $ echo -e "BKIKJAA5BMMU2RHO6IBB\nV8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12" | \
                 mc alias set mys3 https://s3.amazonaws.com --api "s3v4" --path "off"
     $ set -o history against
     http://minio.storage.svc.cluster.local:9000 - stale port. The minio
     Service's port now tracks requestAutoCert on the Tenant (443 when
     auto-TLS is on, 80 when off - we set it to false earlier), so 9000
     doesn't exist on that Service anymore and the job hung in its 'waiting
     for minio...' retry loop indefinitely, blocking ArgoCD's sync operation
     (PostSync hooks block the sync from completing until they succeed).
   - Fixed to use minio-cluster-hl.storage.svc.cluster.local:9000 - the
     headless per-pod Service, which always listens on 9000 regardless of
     the Tenant's TLS mode, so this can't silently break again the same way.
2026-07-21 16:21:37 -07:00
Story Crater Bot c64b437bca fix(ingress-nginx): force-ssl-redirect=true globally
Our Ingress objects intentionally omit per-rule tls: blocks (single wildcard
cert served via --default-ssl-certificate). nginx-ingress's normal ssl-redirect
setting only forces HTTPS 301 for hosts with an explicit TLS block on their own
Ingress resource - since none of ours do, plain http://*.riotpiao.com requests
were served directly instead of redirected, exposing every client-facing
console (forgejo, authentik, argocd, grafana, vault, etc.) over plaintext HTTP.

force-ssl-redirect forces the redirect globally regardless of per-ingress TLS
block presence. Verified fix works (tested via manual patch then reverted -
confirmed 308 redirects to https:// on forgejo/authentik/argocd) before
committing via GitOps.
2026-07-21 16:17:52 -07:00
Story Crater Bot 64ee19c822 fix(argocd): repoURL http://forgejo.riotpiao.com:3000 -> https://forgejo.riotpiao.com
Root cause of widespread 'Unknown' sync status / Skipping auto-sync across
almost every Application: CoreDNS rewrites forgejo.riotpiao.com to the nginx
ingress controller service (rewrite name forgejo.riotpiao.com -> ingress-nginx-
controller...), which only listens on 80/443, not 3000. Every git fetch from
argocd-repo-server to the :3000 repoURL was timing out (context deadline
exceeded), so ArgoCD couldn't compare desired vs live state for any app.

Fix: use https://forgejo.riotpiao.com (no port, TLS via nginx + wildcard cert)
consistent with the 'all external endpoints HTTPS' requirement. Verified git
smart-http response 200 on the new URL before committing.
2026-07-21 16:03:38 -07:00
Story Crater Bot 32cb01388c fix(ingress): correct broken/mismatched backends found in full audit
- minio console ingress: minio-console -> minio-cluster-console:9090 (service renamed by operator)
- minio-api ingress: point to minio:9000 (restored once requestAutoCert disabled)
- minio tenant: requestAutoCert: false (MinIO was TLS-only internally, breaking
  plain-HTTP clients like Vault's S3 backend - this was the real cause of the
  Vault S3 hang)
- argocd ingress: moved from namespace cicd -> argocd (service lives in argocd
  namespace; ingress in wrong namespace can never route, was returning 503)
- removed duplicate kmsvc ingress (sqs namespace already has management-service
  ingress with proper TLS block for same host/backend)

Audit method: cross-checked every ingress backend.service.{name,port} against
actual Service objects in cluster. Found 3 broken backends out of 15 ingresses.
2026-07-21 16:00:24 -07:00
Story Crater Bot 875b87cea2 fix(vault): correct api_addr to use iam namespace and add cluster_addr 2026-07-21 15:41:33 -07:00
Story Crater Bot d55e7ff31e fix(vault): use minio-cluster-hl:9000 instead of service port 2026-07-21 15:36:11 -07:00
Story Crater Bot eda152015c fix(vault): clean up S3 config with timeout 2026-07-21 15:26:54 -07:00
Story Crater Bot c9bf9f7dce fix(vault): correct S3 timeout config placement 2026-07-21 15:26:41 -07:00
Story Crater Bot 5170921eea fix(vault): add S3 session timeout to prevent hanging 2026-07-21 15:26:29 -07:00
Story Crater Bot b3017c525a fix(minio): remove OIDC config to unblock IAM initialization 2026-07-21 15:17:05 -07:00
Story Crater Bot f101b3381e fix(minio): add vault bucket to tenant spec 2026-07-21 14:58:48 -07:00
Story Crater Bot ef348d23f4 fix(vault): use minio service on port 80 (maps to 9000) 2026-07-21 14:52:24 -07:00
Story Crater Bot 04ec157c19 fix(vault): correct MinIO endpoint to minio-cluster-hl service 2026-07-21 14:46:54 -07:00
Story Crater Bot ded98329e5 Revert "fix(temporal): disable cassandra sub-chart and schema jobs, server uses PostgreSQL only"
This reverts commit d51056c684.
2026-07-21 14:04:57 -07:00
Story Crater Bot d51056c684 fix(temporal): disable cassandra sub-chart and schema jobs, server uses PostgreSQL only 2026-07-21 13:58:45 -07:00
Story Crater Bot c661d7eb77 fix(temporal): enable cassandra sub-chart with storage disabled, server uses PostgreSQL 2026-07-21 13:53:08 -07:00
Story Crater Bot edc12c388f fix(temporal): add minimal cassandra config stub to satisfy chart template 2026-07-21 13:47:40 -07:00
Story Crater Bot f0178b3bc5 fix(temporal): set cassandra.port even when disabled (chart requirement) 2026-07-21 13:44:25 -07:00
Story Crater Bot e82c4b36a4 fix(temporal): switch to PostgreSQL (CNPG ddb-cluster) instead of broken Cassandra/ES setup 2026-07-21 13:41:12 -07:00
Story Crater Bot 4ea25620dd fix(temporal): cassandra hosts as list (array) not string 2026-07-21 13:32:44 -07:00
Story Crater Bot 0588cb91b4 fix(temporal): scale elasticsearch to 1 replica (cluster constraint on single schedulable node) 2026-07-21 13:22:59 -07:00
Story Crater Bot 4bb99ef24f fix(minio): disable standalone console (use tenant built-in console instead) 2026-07-21 13:15:00 -07:00
Story Crater Bot fd07b3cff2 fix(sqs): add RBAC for temporalworkers resource 2026-07-21 13:07:42 -07:00
Story Crater Bot dc0bb63a01 fix(sqs): grant queue-operator deployments RBAC, install TemporalWorker CRD 2026-07-21 13:06:28 -07:00
Story Crater Bot b2191509fb fix(temporal): correct elasticsearch hostname to elasticsearch-master-headless 2026-07-21 12:54:14 -07:00
Story Crater Bot 5635482e0d fix(temporal): pin chart to v0.74.0 (keep original cassandra/ES config) 2026-07-21 12:43:52 -07:00
Story Crater Bot 328a713f4f Revert "fix(temporal): deploy Cassandra + Elasticsearch, pin chart to v0.74.0 (older version with sub-chart support)"
This reverts commit cc5325d905.
2026-07-21 12:42:16 -07:00
Story Crater Bot cc5325d905 fix(temporal): deploy Cassandra + Elasticsearch, pin chart to v0.74.0 (older version with sub-chart support) 2026-07-21 12:18:53 -07:00
Story Crater Bot 26f7da3610 fix(prometheus): drop ServerSideApply — conflicts with managedNamespaceMetadata forced ns apply, blocked all syncs; CRDs installed out-of-band 2026-07-21 11:26:54 -07:00
Story Crater Bot f2f4a2580f fix(prometheus): pin to az-a + longhorn-wffc SC — RWO PVC failed to attach on cp-2 (sole Longhorn node is cp-1) 2026-07-21 11:14:11 -07:00
Story Crater Bot 21e3987b11 fix(ingress): switch riotpiao-com-tls to letsencrypt-prod issuer
Wildcard cert was left on letsencrypt-staging; staging root is not
browser-trusted so HTTPS to *.riotpiao.com fails cert validation.
Switch issuerRef to letsencrypt-prod to issue a trusted wildcard.
2026-07-21 11:10:22 -07:00
Story Crater Bot 3e7238f71c fix(prometheus): scrapeTimeout must be <= scrapeInterval — authentik/nginx SMs (60s>30s) + global (60s>30s) blocked operator config gen, no Prometheus STS created 2026-07-21 11:08:23 -07:00
Story Crater Bot 88f8a764de fix(prometheus): set monitoring ns privileged via managedNamespaceMetadata — node-exporter hostNetwork/hostPID/hostPath blocked by baseline PSS 2026-07-21 11:05:04 -07:00
Story Crater Bot 34e996475f fix(promtail): set logging ns privileged via managedNamespaceMetadata — promtail hostPath/privileged/DAC_READ_SEARCH blocked by baseline PSS, DaemonSet created 0 pods 2026-07-21 11:03:58 -07:00
Story Crater Bot 3f4653ac56 fix(argocd): raise repo-server memory 512Mi->1Gi — OOMKilled under CMP+Helm rendering caused chronic restarts, not-ready endpoint, and cluster-wide sync 'no route to host' failures 2026-07-21 10:01:11 -07:00
Story Crater Bot 1dc6a2025f fix(kmsvc-redis): use bitnamilegacy/redis mirror + allowInsecureImages — docker.io/bitnami pulled version-pinned tags, ImagePullBackOff blocked redis + queue-operator 2026-07-21 09:47:19 -07:00
Story Crater Bot da925f3101 fix(forgejo-runner): add fsGroup 1000 so runner user can write /data/.runner — register hit permission denied on root-owned Longhorn PVC 2026-07-21 09:40:59 -07:00
Story Crater Bot 2443708abb chore(ci): refresh forgejo runner registration token — prior token invalid/expired 2026-07-21 09:38:15 -07:00
Story Crater Bot 9a34c12068 fix(forgejo-runner): point at in-cluster forgejo Service :3000 not public :443 — runner i/o timeout, forgejo serves 3000 not 443 2026-07-21 09:35:32 -07:00
Story Crater Bot f646bb06fd fix(minio,loki): declare loki-chunks/ruler/admin buckets in minio Tenant — loki failed with NoSuchBucket 2026-07-21 09:31:52 -07:00
Story Crater Bot 4363739d59 fix(loki,vault,iam): loki minio endpoint :80 not :9000, emit vault-minio-creds via CMP, drop redundant broken authentik-migrations job 2026-07-21 09:24:52 -07:00
Story Crater Bot 2bf543bba1 fix(ingress): add homelab-ingress ArgoCD app to apply orphaned ingress.yaml — services had no Ingress object, unreachable via LAN ingress .160 2026-07-21 09:15:58 -07:00
Story Crater Bot 6a2aacc4e6 feat(terraform): add per-node Cloudflare Tunnel cert SANs to controlplane certSANs — remote talosctl/kubectl over tunnel pass TLS verification
Adds optional cloudflare_talos_sans (machine.certSANs, talos API :50000) and
cloudflare_apiserver_sans (cluster.apiServer.certSANs, kube-apiserver :6443) per
control-plane node. cp-1 gets cp1.homelab + cp1-talos.homelab; cp-2/cp-3 get
their cpN-talos.homelab. Values set in gitignored tfvars.
2026-07-21 08:02:24 -07:00
Story Crater Bot 0471177250 chore(ci): add SOPS-encrypted runner-token secret record for forgejo-runner registration 2026-07-21 07:55:28 -07:00
Story Crater Bot 7fb73d6a4c fix(scheduling): pin portainer+forgejo-runner to az-a, add nodeSelector to runner chart template — WFFC alone insufficient with single Longhorn node (cp-1 only) 2026-07-20 23:51:46 -07:00
Story Crater Bot e0b24c83d0 fix(storage): add longhorn-wffc WaitForFirstConsumer default SC, repoint portainer/forgejo-runner — Immediate binding placed PVCs on non-storage nodes (cp-2/cp-3), attach failed 2026-07-20 23:49:01 -07:00
Story Crater Bot 9117fd777a fix(authentik): drop redundant authentik-migrate init container — server entrypoint migrates; old-image manage migrate tripped version-history precheck on empty DB 2026-07-20 23:40:08 -07:00