Skip to content

feat: add offline support with automatic secret caching#294

Draft
nimish-ks wants to merge 5 commits intomainfrom
feat/offline-support
Draft

feat: add offline support with automatic secret caching#294
nimish-ks wants to merge 5 commits intomainfrom
feat/offline-support

Conversation

@nimish-ks
Copy link
Copy Markdown
Member

@nimish-ks nimish-ks commented Mar 29, 2026

Summary

Adds offline support to the Phase CLI. Encrypted API responses are cached locally on every successful fetch. Users set PHASE_OFFLINE=1 to serve secrets from cache when network is unavailable.

Depends on: phasehq/golang-sdk#21

Behavior

PHASE_OFFLINE Caches on success Serves from cache Network errors
unset Yes No Fail with hint
1 / true No (skips network) Yes N/A

Changes

  • cmd/auth*.go — always store wrapped_key_share (remove OfflineEnabled gate)
  • pkg/offline/IsOffline() and CacheDir() helpers
  • pkg/phase/phase.go — configures SDK OfflineConfig from PHASE_OFFLINE env var
  • pkg/errors/errors.go — network error messages include PHASE_OFFLINE=1 hint
  • go.mod — local replace directive for SDK development

Cache structure

~/.phase/secrets/offline/{user_id}/
  userdata.json                              # encrypted AppKeyResponse
  secrets/
    {sha256(env|app|appID|path)}.json        # encrypted secrets array

Test plan

  • phase auth → verify wrapped_key_share in ~/.phase/secrets/config.json
  • phase secrets list → verify cache files are encrypted JSON (not plaintext)
  • Disconnect network → phase secrets list → fails with PHASE_OFFLINE=1 hint
  • PHASE_OFFLINE=1 phase secrets list → serve from cache
  • PHASE_OFFLINE=1 phase secrets create ... → error cleanly
  • Dynamic secrets + PHASE_OFFLINE=1 → skipped with warning
  • PHASE_OFFLINE=0 PHASE_HOST=https://bogus:777 phase secrets list → no fallback, clean error

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 29, 2026

Deploying phase-cli-install-script with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8c3e5ee
Status: ✅  Deploy successful!
Preview URL: https://385d9723.phase-cli-install-script.pages.dev
Branch Preview URL: https://feat-offline-support.phase-cli-install-script.pages.dev

View logs

@nimish-ks nimish-ks marked this pull request as draft March 29, 2026 13:04
@nimish-ks nimish-ks self-assigned this Mar 29, 2026
Configure the SDK's OfflineConfig in NewPhase to enable transparent
caching of encrypted API responses. Users set PHASE_OFFLINE=1 to
serve secrets from cache when network is unavailable.

- Always store wrapped_key_share after auth (remove OfflineEnabled gate)
- pkg/offline: IsOffline() and CacheDir() helpers
- pkg/phase: configure SDK OfflineConfig from PHASE_OFFLINE env var
- pkg/errors: network error messages include PHASE_OFFLINE=1 hint
- go.mod: local replace directive for SDK development

Depends on: phasehq/golang-sdk#21
@nimish-ks nimish-ks force-pushed the feat/offline-support branch from 2f53b5a to 446f66b Compare April 2, 2026 08:28
Regular logout (without --purge) was not cleaning up the user's
offline cache directory. Now removes ~/.phase/secrets/offline/{id}/
when logging out a specific user. Uses offline.CacheDir() to keep
the path definition in one place.
@nimish-ks nimish-ks force-pushed the feat/offline-support branch from ae74077 to ac681e5 Compare April 3, 2026 06:30
Missed in the initial offline support commit — the other three auth
files (auth.go, auth_aws.go, auth_webauth.go) were already updated.
Avoid implying cached data exists when it may not (e.g. first-time
users). Changed to "if available" phrasing.
Prevents cache pollution when ad-hoc env var auth uses a different
identity than the logged-in config user.
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