Skip to content

feat(telepresence): refresh hour-long environment tokens with a credential plugin - #98

Merged
akshaykalia merged 6 commits into
mainfrom
security/telepresence-token-refresh
Dec 1, 2026
Merged

akshaykalia merged 6 commits into
mainfrom
security/telepresence-token-refresh

Conversation

@akshaykalia

Copy link
Copy Markdown
Contributor

Problem

Environment kubeconfigs are moving from never-expiring service-account tokens to 1-hour TokenRequest tokens (nautilus#854). exec, logs and port-forward aren't affected:

  • each command fetches a new kubeconfig when it starts;
  • the API server checks a token only when a request starts, so a running stream outlives its token.

Telepresence is different. Its daemon keeps making API requests with the token it was given, so a session would lose API access after an hour.

Change

  • telepresence connect, and the MCP telepresence_connect tool, now write a ~/.shipyard/kubeconfig that holds no token. Instead its user has a client.authentication.k8s.io/v1 exec credential plugin: this executable's hidden shipyard telepresence credential --env <id> command.
  • The plugin fetches the environment's kubeconfig from core and prints its token as an ExecCredential:
    • expirationTimestamp is 2 minutes before the JWT's exp, so client-go asks again in time;
    • legacy tokens on old clusters have no exp, so their credential has no expiry, and client-go keeps them until it gets a 401.
  • The daemon may have started under another mode, so the plugin is pinned to what the connect used:
    • the absolute --config path;
    • --org= (always set, even when empty);
    • SHIPYARD_API_URL (always set, including the default);
    • for a config-file token, an empty SHIPYARD_API_TOKEN, so the config is read again;
    • the SHA-256 of the API token. The plugin refuses to send any other token and asks the user to telepresence quit -s and reconnect. The API token itself is never written to the kubeconfig.

Compatibility

  • With this core, old clusters still return never-expiring tokens, so nothing changes there.
  • Older CLIs keep working against new clusters for exec, logs and port-forward. Their telepresence sessions lose API access after about an hour, and need telepresence quit -s and a reconnect.
  • Release this before, or with, the nautilus release.

Tests

  • Unit tests cover:
    • the credential's expiry (before exp, inside the margin, no exp, opaque token);
    • failures (no token, request refused);
    • the kubeconfig rewrite: no token left, and client-go accepts it;
    • an end-to-end client-go request over TLS that runs a stand-in plugin and sends its token;
    • plugin args and env pinning: relative config, default URL, empty org;
    • the token-hash check.
  • go test ./... passes. golangci-lint reports nothing new; its 9 findings are all in untouched files.
  • Codex review: none, after four rounds of fixes.
  • Manual: against a QA environment on an old nautilus, shipyard telepresence credential printed a v1 ExecCredential with no expiry (legacy token). kubectl get pods with a kubeconfig whose user is this plugin listed the environment's pods.

Verify on QA (after nautilus#854 is deployed)

  1. shipyard --config ~/.shipyard/qa.yaml telepresence connect --env <env>, then telepresence list works.
  2. grep -c 'token:' ~/.shipyard/kubeconfig prints 0, and the file has an exec: block.
  3. shipyard telepresence credential --env <env> | jq .status.expirationTimestamp shows about now + 58 minutes. Don't print .status.token.
  4. Leave telepresence connected for more than 1 hour. telepresence list still works, and the daemon log (telepresence gather-logs) shows the plugin ran again.

…credential plugin

Environment tokens now expire after an hour on current clusters. The
kubeconfig telepresence connect writes holds no token; it runs the hidden
shipyard telepresence credential command, which fetches a fresh kubeconfig
from core and prints its token as an ExecCredential expiring just before
the token does.
@akshaykalia
akshaykalia merged commit a0b62ba into main Dec 1, 2026
6 checks passed
@akshaykalia
akshaykalia deleted the security/telepresence-token-refresh branch December 1, 2026 20:59
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