Skip to content

Preserve existing sessions through credential cutover - #143

Merged
lawrencecchen merged 6 commits into
mainfrom
fix/legacy-key-transition
Aug 4, 2026
Merged

lawrencecchen merged 6 commits into
mainfrom
fix/legacy-key-transition

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Preserves already-running clients while hosted credentials rotate.

  • accepts only the exact legacy Stack-derived tenant key during a fixed 30-day transition
  • persists one absolute cutoff under the registry lock so restarts cannot extend it
  • caps configured grace at 90 days and remains fail-closed when no cutoff exists
  • documents that a fresh sr login rotates to scoped credentials

Regression sequence:

  • 49d76c2 adds the failing continuity and durable-cutoff tests
  • 78e8845 implements the transition

Verification: go test ./...


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Adds a fixed, one-time cutoff for legacy Stack-derived tenant keys with a default 30-day grace so existing sessions survive the deployment and expire on schedule. The cutoff is persisted atomically and directory-synced; sync failures are surfaced and safe to retry without extending the deadline.

  • New Features

    • Fixed cutoff for legacy Stack tenant keys, durably persisted (atomic rename + directory fsync); on fsync failure we return an error and later starts read the same cutoff.
    • New --stack-legacy-key-grace flag (default 30d, max 90d); cutoff is logged at startup.
    • Proxy allows legacy keys during grace and rejects them at and after the cutoff; if no cutoff exists, legacy keys fail closed.
  • Migration

    • Existing sessions continue until the cutoff; then legacy keys return 401.
    • Run sr login to rotate to scoped, broker-issued credentials.
    • Optionally adjust grace with --stack-legacy-key-grace.

Written for commit 94f0216. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added a configurable grace period for legacy Stack tenant credentials.
    • Legacy credentials now expire permanently after the migration cutoff, including across restarts.
    • Fresh sr login requests issue a new scoped credential.
    • Startup now validates and preserves the configured credential cutoff.
  • Bug Fixes

    • Prevented expired legacy credentials from regaining validity after service restarts.
    • Continued rejecting direct client credential exchanges while preserving tenant-scoped URLs and short-lived credential leasing.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds a durable grace-period cutoff for legacy Stack tenant credentials. Server startup persists and shares the cutoff with the multi-tenant handler. Matching legacy credentials work before the cutoff and return unauthorized at or after it.

Changes

Legacy credential expiration

Layer / File(s) Summary
Persist the legacy credential cutoff
internal/tenant/tenant.go, internal/tenant/tenant_test.go
The registry validates the grace period, persists a UTC cutoff with 0600 permissions, reuses existing cutoffs, and tests non-extension behavior.
Enforce cutoff during tenant authentication
internal/proxy/multitenant.go, internal/proxy/multitenant_test.go
MultiTenant applies the configured cutoff to derived legacy Stack credentials and supports an injectable clock. Tests cover access before the cutoff and rejection at the cutoff.
Initialize and document startup behavior
cmd/subrouter/main.go, deploy/gcp/README.md
serve adds the grace-period flag, initializes the cutoff during Stack-authenticated startup, shares the tenant registry, and documents key expiration and rotation behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Serve
  participant Registry
  participant MultiTenant
  participant Client

  Serve->>Registry: Ensure persistent legacy credential cutoff
  Registry-->>Serve: Return cutoff
  Serve->>MultiTenant: Configure cutoff and shared registry
  Client->>MultiTenant: Submit legacy tenant credential
  MultiTenant-->>Client: 200 OK before cutoff or 401 Unauthorized at cutoff
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes preserving existing client sessions during the credential cutover.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/legacy-key-transition

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deploy/gcp/README.md`:
- Around line 101-104: Update the deployment README text describing the
legacy-key cutoff to state that 30 days is the default, document the
--stack-legacy-key-grace option for configuring the grace period, and specify
its maximum of 90 days.

In `@internal/tenant/tenant.go`:
- Around line 154-156: Update the cutoff rename flow in the relevant tenant
method to sync r.stateDir immediately after os.Rename(temporaryPath, path)
succeeds. Preserve the existing error return for the rename, and propagate any
parent-directory sync error before returning success so the rename survives a
host crash.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 04047138-b27a-42af-a0b5-4d3d27d5dae3

📥 Commits

Reviewing files that changed from the base of the PR and between 3fbb4c7 and 78e8845.

📒 Files selected for processing (6)
  • cmd/subrouter/main.go
  • deploy/gcp/README.md
  • internal/proxy/multitenant.go
  • internal/proxy/multitenant_test.go
  • internal/tenant/tenant.go
  • internal/tenant/tenant_test.go

Comment thread deploy/gcp/README.md
Comment on lines +101 to +104
rejected. A durable 30-day cutoff lets tenant keys issued before the broker
migration survive the deployment without extending their lifetime on restart;
after the cutoff they fail closed. A fresh `sr login` rotates to the scoped key.
The CLI writes the tenant-scoped public URL to the local Codex configuration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document the configurable grace period.

Line 101 states a fixed 30-day cutoff. --stack-legacy-key-grace permits a configured grace period up to 90 days. State that 30 days is the default and document the flag and cap.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deploy/gcp/README.md` around lines 101 - 104, Update the deployment README
text describing the legacy-key cutoff to state that 30 days is the default,
document the --stack-legacy-key-grace option for configuring the grace period,
and specify its maximum of 90 days.

Comment thread internal/tenant/tenant.go
@lawrencecchen
lawrencecchen merged commit 2d3824b into main Aug 4, 2026
7 checks passed
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