Skip to content

fix(auth): keep the auth cache out of the invocation directory - #793

Merged
ian-flores merged 16 commits into
mainfrom
auth-cache-out-of-cwd
Nov 18, 2026
Merged

ian-flores merged 16 commits into
mainfrom
auth-cache-out-of-cwd

Conversation

@ian-flores

@ian-flores ian-flores commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

VIP wrote a live session (IdP, Connect, and Workbench cookies) and a minted Connect API key into the invocation directory, which is exactly what users zip and share. This moves the auth cache out of that directory.

File Before After
.vip-auth-cache.json ./ ~/.cache/vip/auth/<hash of cwd>/
.vip-auth-cache.meta.json ./ same directory
  • Root is $XDG_CACHE_HOME (absolute only), then ~/.cache. On Windows, %LOCALAPPDATA% comes before XDG_CACHE_HOME. The vip/, vip/auth/ and leaf directories are 0700.
  • Keyed on the resolved invocation directory, so vip verify and vip cleanup still share one cache per directory.
  • Existing caches in cwd are moved on first use, keeping their mtime so the 4-hour TTL still applies (also across filesystems). If a new cache already exists, the old files are deleted.
  • If the cache directory can't be written, VIP skips caching. It never falls back to cwd.
  • vip verify and vip cleanup delete other directories' caches that have not been written for a day. A cache older than 4 hours is never reused.
  • README now says where credentials live, including inline secrets in vip.toml.
  • The User Guide has a new section on where the saved session lives.

A shareable vip bundle command is tracked in #794.

Closes #620

Copilot AI balanced review requested due to automatic review settings October 21, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cache lookup failures can abort authentication, and failed writes can leave incomplete credentials eligible for reuse.

2 open issues
What changed in this PR

Moves VIP’s authentication cache away from shareable output directories into a per-user cache keyed by invocation directory.

Changes:

  • Adds cache-location resolution and legacy-file migration.
  • Handles cache write failures and adds migration, permissions, and path tests.
  • Documents credential storage and safe-sharing precautions.
File Description
vip.toml.example Warns against sharing real API keys.
src/​vip/​auth/​cache.py Relocates caches and migrates legacy files.
selftests/​test_auth_cache.py Tests paths, migration, permissions, and write failures.
README.md Documents cached credentials and sharing precautions.
AGENTS.md Updates the documented cache-location contract.

Review effort: Balanced

Comment thread src/vip/auth/cache.py Resolved
Comment thread src/vip/auth/cache.py Resolved
@ian-flores
ian-flores marked this pull request as ready for review October 21, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Live cookies and API keys can still be exposed in shared invocation directories because migration may be skipped or exit before cleanup, and cache roots can remain inside those directories.

5 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/vip/auth/cache.py Resolved
Comment thread src/vip/auth/cache.py Resolved
Comment thread src/vip/plugin/auth.py Resolved
Comment thread selftests/test_auth_cache.py Resolved
Comment thread src/vip/auth/cache.py Resolved
@ian-flores

Copy link
Copy Markdown
Collaborator Author

@copilot all good now?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Concurrent cache pruning can delete authentication storage still used by an active run, causing later browser contexts to fail.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

High severity Keep a private cache snapshot alive for the duration of a run

src/​vip/​auth/​cache.py:155

If a run reuses a cache shortly before its four-hour expiry, a command from another directory can delete the file while that run is still using it. _load_cached_auth() returns the cache itself as storage_state_path, so later browser contexts in the first run fail when it disappears. Return a private, session-owned snapshot tracked by _tmpdir, and update the cache-reuse tests to verify it survives pruning.

Medium severity Clean up legacy credentials when no cache root is available

src/​vip/​auth/​cache.py:113

When cwd is accessible but no home or cache root can be resolved, this early return leaves the legacy cookies and API key in the directory users share. Best-effort delete the legacy state/metadata pair before returning, warning if removal fails. Update test_no_home_directory_leaves_legacy_cache_alone to expect removal.

5 resolved since last review

Review effort: Balanced

Comment thread selftests/conftest.py Resolved
Comment thread src/vip/auth/cache.py Resolved
ian-flores and others added 2 commits November 18, 2026 15:04
Add pytest hooks to manage authentication cache during tests.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ian-flores
ian-flores requested a balanced review from Copilot November 18, 2026 23:06

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot all good now?

Not quite yet. The latest commit (b603dbf) fixes the non-UTF-8 path hashing issue, but the review still lists unresolved cache-snapshot/pruning, no-cache-root legacy cleanup, and selftest startup-isolation concerns. The latest smoke workflows are still running, so I can’t confirm the full CI result yet.

@ian-flores

Copy link
Copy Markdown
Collaborator Author

Both suggestions from the latest review are applied in b8d2518 (selftests no longer prepare the real cache during outer pytest setup) and b603dbf (cache key uses os.fsencode). 0b74e5f adds a regression test for a directory name that is not valid UTF-8.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because unpublished findings identify credential-exposure risks, deletion of caches still in use, and tests that can move real credential files.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@ian-flores

Copy link
Copy Markdown
Collaborator Author

On the unpublished finding about deleting caches still in use: fixed in f0ede10. A run can reuse a cache that is almost 4 hours old and keep reading it for the rest of the run, so pruning another directory cache at 4 hours could pull it out from under that run. Pruning now waits until a cache has not been written for a day. Reuse still stops at 4 hours.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human review is needed to assess credential-retention and concurrent-migration risks that could expose legacy credentials or leave the authentication cache unusable.

No open issues 🎉

Review effort: Balanced

@ian-flores

Copy link
Copy Markdown
Collaborator Author

Both risks are known trade-offs. Credential retention: another directory cache can stay on disk for up to a day after its last write, so a long run that reused it keeps working. It is never reused after 4 hours, the folder is owner-only, and the next login removes its Connect key. Concurrent migration: if two runs in the same directory move the legacy cache at once, the one that loses the race leaves the moved files alone and deletes what is left in the working directory. The worst case is a session file with no meta file, which the loader treats as a miss, so that run signs in again.

@ian-flores
ian-flores merged commit e4900a3 into main Nov 18, 2026
52 checks passed
@ian-flores
ian-flores deleted the auth-cache-out-of-cwd branch November 18, 2026 23:26
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-11-18 23:27 UTC

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.

[Feature] Keep credentials out of shareable VIP output: redact the auth cache and add a bundle command

3 participants