Skip to content

Dex TLS certificate rotation is not detected by kargo-api, breaking OIDC login until manual restart #6866

Open

Description

@nickdallavalentina

Pre-submission checklist

  • I have searched existing issues and confirmed this is not a duplicate.

Description

I suspect that when api.oidc.dex.enabled=true and api.oidc.dex.tls.selfSignedCert=true, kargo-api reverse-proxies /dex/* to the internal kargo-dex-server service over TLS, trusting Dex's certificate via the ca.crt key of the same cert-manager-issued Secret (api.oidc.dex.tls.secretName). When cert-manager renews/reissues that Certificate, kargo-api keeps failing TLS verification against Dex's newly served certificate until kargo-api is manually restarted. kargo-dex-server does not need a restart its side is fine, the certificate presented is current and valid

Steps to Reproduce

Install the chart with api.oidc.enabled=true, api.oidc.dex.enabled=true, api.oidc.dex.tls.selfSignedCert=true
Wait for (or force) cert-manager to reissue the kargo-dex-server Certificate.
Without restarting kargo-api, attempt OIDC login through the UI

Requests to /dex/.well-known/openid-configuration (and other /dex/* paths proxied by kargo-api) return an empty 502 response

UI display

OIDC: "response" is not a conformant Authorization Server Metadata response (unexpected HTTP status code)

Expected Behavior

Login continues to work across certificate renewals, either because kargo-api reloads its trusted CA at runtime, or because the deployment automatically rolls when the Dex TLS secret changes.

Actual Behavior

kargo-api fails to establish a trusted TLS connection to the internal kargo-dex-server after cert-manager renews the Dex TLS certificate, and stays broken until kargo-api is manually restarted.

Kargo Version

v1.9.5

Relevant Logs

Dex:

time=2026-08-24T00:37:58.199Z level=INFO msg="keys rotated" next_rotation=2026-08-24T06:37:58.199Z
2026/08/24 02:57:04 http: TLS handshake error from x:51240: remote error: tls: bad certificate
2026/08/24 02:57:35 http: TLS handshake error from x:49438: remote error: tls: bad certificate
time=2026-08-24T06:37:58.723Z level=INFO msg="keys expired, rotating"
time=2026-08-24T06:37:58.941Z level=INFO msg="keys rotated" next_rotation=2026-08-24T12:37:58.941Z
2026/08/24 07:22:57 http: TLS handshake error from x:59866: remote error: tls: bad certificate
2026/08/24 07:23:22 http: TLS handshake error from x:42200: remote error: tls: bad certificate

Screenshots

No response

Activity

  1. added
    kind/bug
    on Aug 24, 2026
  2. added
    needs/area
    needs/priority
    on Aug 24, 2026
  3. fuskovic commented on Aug 24, 2026

    @fuskovic
    Member

    Two possible approaches for reloading at runtime:

    1. fsnotify + poll hybrid. This is what controller-runtime's own certwatcher does for this kind of problem. Event-driven reload for low latency with a poll ticker running . They both run the whole time and either can trigger a reload. The reason the ticker is needed at all is because K8s updates a mounted Secret via an atomic symlink swap, not an in-place write. fsnotifys watch on the file can get invalidated by that swap and the library's own recovery (re-Add-on-Remove/Chmod) can itself fail (with no retry) if the timing is unlucky.

    2. Poll-only. A ticker re-reads the CA file every N seconds and atomically swaps in a fresh cert. We could optionally make N configurable with something like DEX_CA_CERT_RELOAD_INTERVAL

    Suggestion

    1 has lower latency and higher complexity. The latter is the inverse. So I think if we made the latency configurable via DEX_CA_CERT_RELOAD_INTERVAL then I think 2 seems like a reasonable choice.

    Thoughts @krancour

  4. self-assigned this
    on Aug 24, 2026
  5. fuskovic commented on Aug 24, 2026

    @fuskovic
    Member

    It looks like there's a second location OIDC login can break on cert rotation: https://github.com/akuity/kargo/blob/main/pkg/server/auth_middleware.go#L507-L572

    getKeySet builds an httpClient whose CA trust for Dex's TLS cert is loaded once via os.ReadFile and baked into a static RootCAs field (L554-L565). That client is wrapped in an oidc.RemoteKeySet and cached into authMiddleware.oidcTokenVerifyFn on first success, never rebuilt for the process's lifetime (L375-L379).

    RemoteKeySet periodically re-fetches Dex's JWKS over that same stale trust. When cert-manager rotates Dex's TLS cert, the next JWKS refresh fails TLS verification. Breaking OIDC token verification for all users (not just new logins), silently, until kargo-api is restarted.

    We could fix by not letting getKeySet's httpClient freeze a RootCAs snapshot at construction time. Instead, we give its Transport a DialTLSContext that re-reads a shared, live-reloading CACertPool on every dial so each JWKS refresh re-checks current trust instead of a cached one.

  6. added
    area/security
    priority/normal
    and removed
    needs/priority
    needs/area
    on Aug 24, 2026
  7. krancour commented on Aug 24, 2026

    @krancour
    Member

    Issue acknowledged, but I would consider this a lower priority.

  8. added
    priority/low
    and removed
    priority/normal
    on Aug 24, 2026
  9. github-actions commented on Nov 23, 2026

    @github-actions

    This issue has been automatically marked as stale because it had no activity for 90 days. It will be closed if no activity occurs in the next 30 days but can be reopened if it becomes relevant again.

  10. added
    stale
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/securitykind/bugpriority/lowstale

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions