chore(iam): expire relationship cache entries at the answer plus cache_ttl

Summary

  • Problem: the relationship cache wrote each entry with a relative lifetime, so a SET that stalled started a fresh cache_ttl when it landed. An entry could outlive its IAM answer plus cache_ttl. !3759 (merged) narrowed this by subtracting the store deadline from the lifetime. The reviewer's comment on that MR says what remains: Redis can run a command it received after the client gave up, and "only an absolute expiry (PXAT) closes" that.
  • Impact: a stale grant could be served after a revoke and a fresh deny, for longer than the ADR-021 bound on the Artifact Registry's share of the role-change window. Users see nothing else.
  • Change: cacheStore.set takes the IAM answer time and writes SET ... PXAT <answeredAt + cache_ttl> in the same command as the value, through go-redis SetArgs{ExpireAt}. A write whose expiry has already passed is skipped before the marshal, because Redis would delete the key and reply OK, dropping a fresher entry another pod wrote. The store-deadline subtraction and the 1 ms skip are gone, so entries live the full cache_ttl again.
  • Logging: the first failed get and the first failed set per cache instance log one Warn from CachingResolver, with the cache name, the command and the cause. Every failure is still counted. The store counts and returns the error and never logs it, so a failure is reported once.
  • Downsides: the cache server must be Redis 6.2 or later, or Valkey. Redis reads the expiry on its own clock, so pod-to-Redis clock skew shifts every lifetime by the skew. Redis's own error text can echo the key and the first payload bytes into the Warn, in the contrived case where SET is renamed or disabled on the server.

Checklist

  • Ran it: a headless /verify against real Redis 7.0 and Valkey 7.2. A write sets an absolute pxat of the answer time plus the TTL. A slow write keeps the lifetime that runs from the answer. An already-expired write sends no command and records no error event. The failure Warn fires once per command per instance. A real Redis below 6.2 was not run.
  • Interfaces and data: CacheStoreClient changes Set to SetArgs, an internal interface. The key and the stored value format are unchanged, so existing entries stay readable and expire on their old relative lifetime. The spec, the configuration reference, the self-managed install guide and the observability catalog say so.
  • Failure: a Redis below 6.2 answers ERR syntax error, so every write fails safe, is counted and logged once, and reads fall through to a direct IAM call. No authorization decision changes.
  • Rollout: the staging and production Memorystore instances must be 6.2 or later before this merges. The author confirms that before merge. Old and new pods share keys, and the value format has not changed.
  • Hot path: no added commands, queries or allocations. The expiry still rides in the same SET.
  • Database: n/a, no migration or query change.
  • Security: no new input or route. The change tightens how long an authorization answer can be served from the shared cache. The log carries the cause but never the hashed key. One caveat is listed under Downsides.
  • ADRs: ADR-021, which bounds the Artifact Registry's share of the role-change window to one cache_ttl. This change keeps that bound for a stalled or late write.
  • E2E: none. The change is internal to the cache write path, and no request, response or configuration changes.
  • Simplicity: rejected a boot-time Redis version check, because the docs state the floor and a failed write already fails safe. Rejected a safety margin before skipping an expired write, because it brings back the "a tiny cache_ttl never stores" downside.

Size

570 reviewable lines, of which about 380 are tests. The expiry change, the skip rule and the once-per-instance log share one write path and one set of fakes, and the tests that pin each need the same changed store interface, so a split would leave a part that does not compile or a behavior without its test.

Plan and spec amendments

  • docs/specs/S25-iam-relationships-client.md, Caching section and acceptance criteria: an entry expires at the IAM answer time plus cache_ttl, in the same command as the value. A write whose expiry has passed is skipped. Redis reads the expiry on its own clock, and the server must be Redis 6.2 or later, or Valkey. The first failed get and the first failed set per cache instance log one Warn.

Related to #1279

Edited by David Fernandez

Merge request reports

Loading
Loading