Skip to content

Source cluster token and CA from a Kubernetes Secret ref#36

Merged
joy-software merged 1 commit into
mainfrom
feat/29-token-secret-ref
Jun 7, 2026
Merged

Source cluster token and CA from a Kubernetes Secret ref#36
joy-software merged 1 commit into
mainfrom
feat/29-token-secret-ref

Conversation

@joy-software

Copy link
Copy Markdown
Contributor

What

The fleet registry held each cluster's bearer token (and ca) inline as plaintext, and the StateStore persisted it verbatim. This adds a seam so the sensitive fields can be sourced from a Kubernetes Secret instead.

A registry record may now carry tokenSecretRef / caSecretRef ({name, namespace, key?}) in place of an inline token / ca. The new resolve_secrets(record, reader) in src/elpio/api/gateway.py reads each ref through an injectable secret_reader, base64-decodes the value, and fills token/ca on a copy of the record. The input record is never mutated, so plaintext is never persisted back into the registry.

Details

  • resolve_secrets is pure and testable: the secret_reader (Callable[[name, namespace, key], str]) is injected, so unit tests pass a fake reader and never touch a cluster. The default reader reads Secrets via elpio.k8s.get_object.
  • KubeCRGateway gains a secret_reader param and resolves the record in _client before building the dynamic client. The existing client_factory seam is unchanged.
  • Inline token/ca keeps working (back-compat). When both an inline value and a matching ref are present, the explicit ref wins.
  • The management API accepts the refs on ClusterCreate. Secret refs carry no secret material, so they round-trip in responses; the existing redaction still strips token/ca, and no resolved plaintext token is ever returned.
  • src/elpio/k8s.py signatures are untouched.

Tests

  • tests/unit/test_gateway.py: ref resolves to a working token record; custom ca key; inline token still works with no reader; resolver does not mutate or persist plaintext (gateway resolves at connect time, registry keeps only the ref); explicit ref overrides a stale inline token.
  • tests/unit/test_api.py: a tokenSecretRef survives in API responses while carrying no plaintext.

160 unit tests pass; ruff clean.

The fleet registry kept each cluster's bearer token (and CA) inline as
plaintext, and the StateStore persisted it as-is. Let a registry record
instead carry tokenSecretRef / caSecretRef ({name, namespace, key?}) and
resolve the secret material only at connection time.

resolve_secrets(record, reader) reads each ref through an injectable
secret_reader, base64-decodes the value, and fills token/ca on a copy of
the record. The original is never mutated, so plaintext is never written
back into the registry. Inline token/ca keeps working for back-compat;
an explicit ref wins when both are present.

KubeCRGateway gains a secret_reader seam (defaults to reading Secrets via
elpio.k8s.get_object) and resolves the record in _client before building
the dynamic client. The management API accepts the refs on ClusterCreate;
they carry no secret material so they round-trip in responses, while the
existing redaction still strips token/ca and no resolved token is ever
returned.
@joy-software joy-software merged commit b9157bf into main Jun 7, 2026
7 of 8 checks passed
@joy-software joy-software deleted the feat/29-token-secret-ref branch June 7, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant