Skip to content

Add debug logging and default TTL for credentials without expiry - #11

Merged
IvMisticos merged 1 commit into
mainfrom
claude/sweet-davinci-42sgzb
Jun 19, 2026
Merged

Add debug logging and default TTL for credentials without expiry#11
IvMisticos merged 1 commit into
mainfrom
claude/sweet-davinci-42sgzb

Conversation

@IvMisticos

Copy link
Copy Markdown
Owner

Summary

This PR adds debug logging capabilities and handles credential plugins that don't report an expiration timestamp, which previously caused credentials to be re-fetched on every call.

Key Changes

  • Debug logging: Added KUBE_CREDENTIAL_CACHE_DEBUG environment variable to enable verbose diagnostics. When enabled, logs cache key, hit/miss decisions, expiry information, and refresh operations to stderr without exposing credential material.

  • Default TTL for credentials without expiry: Added logic to detect credentials with missing or implausibly old expiration timestamps (e.g., the zero time 0001-01-01T00:00:00Z emitted by plugins like passman) and apply a default TTL instead of treating them as permanently expired.

    • KUBE_CREDENTIAL_CACHE_DEFAULT_TTL (default 1h): TTL applied to credentials with no usable expiry
    • KUBE_CREDENTIAL_CACHE_NO_EXPIRY_THRESHOLD (default 24h): threshold for determining if an expiry is "missing" vs. genuinely recently-expired
  • Helper functions:

    • withDefaultExpiry(): Substitutes default expiry for credentials reporting no usable one
    • isTruthy(): Parses environment variable values as boolean flags
    • debugf(): Conditional debug logging that respects the debug flag
  • Comprehensive tests: Added TestWithDefaultExpiry() and TestIsTruthy() to validate the new functionality

  • Documentation: Updated README with troubleshooting guidance for plugins without expiry timestamps and documented the new configuration options

Implementation Details

The default TTL logic distinguishes between:

  • Credentials with no expiry (zero time or far past): applies defaultTTL
  • Recently-expired credentials (within noExpiryCutoff): allows normal refresh behavior
  • Valid future expiry: uses as-is

This ensures plugins that omit expiration timestamps are still cached effectively while preserving the refresh behavior for genuinely expired credentials.

https://claude.ai/code/session_01XP6Vo1jhL3S96g8hQ76umo

Some credential plugins (e.g. the passman krew plugin) emit an
ExecCredential without a status.expirationTimestamp, which decodes to the
zero time. Such credentials look permanently expired, so they were
re-fetched on every call and never effectively cached despite leaving an
entry in the OS secret store.

When a refreshed credential's expiry is more than
KUBE_CREDENTIAL_CACHE_NO_EXPIRY_THRESHOLD (default 24h) in the past, treat
it as "no expiry provided" and cache it for KUBE_CREDENTIAL_CACHE_DEFAULT_TTL
(default 1h). Genuinely recently-expired credentials still refresh.

Add KUBE_CREDENTIAL_CACHE_DEBUG to log the cache key, backend, hit/miss,
expiry and refresh decisions to stderr (never credential material).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XP6Vo1jhL3S96g8hQ76umo
@IvMisticos
IvMisticos merged commit c5b43e0 into main Jun 19, 2026
7 checks passed
@IvMisticos
IvMisticos deleted the claude/sweet-davinci-42sgzb branch June 19, 2026 23:55
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.

2 participants