feat(sessions): add secret: session state scope#5132
Draft
caohy1988 wants to merge 1 commit intogoogle:mainfrom
Draft
feat(sessions): add secret: session state scope#5132caohy1988 wants to merge 1 commit intogoogle:mainfrom
caohy1988 wants to merge 1 commit intogoogle:mainfrom
Conversation
Introduce a new `secret:` prefix for session state keys that keeps sensitive data (tokens, credentials) in process memory only — never persisted to any storage backend and never logged by BQ Agent Analytics. - Add `State.SECRET_PREFIX` constant and wire it through `extract_state_delta()` so secret keys are excluded from all persistence buckets. - Add process-local cache and lifecycle helpers on `BaseSessionService` (_apply, _trim, _seed, _restore, _evict). - Update all four session services (InMemory, Database, Sqlite, VertexAI) to seed/restore/evict secret state on create/get/delete. - Harden BQ Agent Analytics redaction: redact `secret:*` keys and detect JSON-encoded blobs containing sensitive credential keys. - Accept `secret:` as a valid prefix in instruction template injection. - 32 new tests (unit + integration across all service types). Closes google#5112 (Phase 1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
Automated notice: a potentially related change has been submitted. Please verify no merge conflicts exist with incoming PRs. (ref: triage cross-check) |
caohy1988
added a commit
to caohy1988/adk-python
that referenced
this pull request
Apr 4, 2026
Migrate existing credential writers to use the `secret:` prefix so that OAuth tokens and credentials are never persisted to session storage backends. - Change BIGQUERY_TOKEN_CACHE_KEY to "secret:bigquery_token_cache" - Update SessionStateCredentialService.save_credential and load_credential to prefix credential_key with State.SECRET_PREFIX - Update tests to expect secret-prefixed state keys This is a breaking change for existing sessions: cached credentials under the old unprefixed keys will not be found, requiring re-authentication. This is intentional — the old behavior stored credentials in plaintext in session backends. Depends on google#5132 (Phase 1: secret: scope infrastructure) Closes google#5112 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5 tasks
caohy1988
added a commit
to caohy1988/adk-python
that referenced
this pull request
Apr 4, 2026
Migrate existing credential writers to use the `secret:` prefix so that OAuth tokens and credentials are never persisted to session storage backends. - Change BIGQUERY_TOKEN_CACHE_KEY to "secret:bigquery_token_cache" - Update SessionStateCredentialService.save_credential and load_credential to prefix credential_key with State.SECRET_PREFIX - Add backward-compatible fallback: load paths try the secret-prefixed key first, then fall back to the legacy unprefixed key so existing sessions migrate without re-authentication - Update and add tests for prefixed keys and legacy fallback Depends on google#5132 (Phase 1: secret: scope infrastructure) Closes google#5112 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
caohy1988
added a commit
to caohy1988/adk-python
that referenced
this pull request
Apr 4, 2026
Migrate existing credential writers to use the `secret:` prefix so that OAuth tokens and credentials are never persisted to session storage backends. - Change BIGQUERY_TOKEN_CACHE_KEY to "secret:bigquery_token_cache" - Update SessionStateCredentialService.save_credential and load_credential to prefix credential_key with State.SECRET_PREFIX - Backward-compatible migration: load paths try the secret-prefixed key first, then fall back to the legacy unprefixed key. On fallback hit, the value is copied to the secret: key and the legacy key is set to None so it is cleared from persistent storage on the next state delta flush. - Use key-presence check (not truthiness) so explicit None in the secret-scoped key is respected and does not revive stale legacy credentials. Depends on google#5132 (Phase 1: secret: scope infrastructure) Closes google#5112 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 1 of the RFC in #5112: a new
secret:prefix for session state keys that keeps sensitive data (tokens, credentials, API keys) in process memory only — never persisted to any storage backend and never logged by BigQuery Agent Analytics.State.SECRET_PREFIX("secret:") added alongside existingapp:,user:,temp:prefixesextract_state_delta()now excludessecret:keys from all persistence bucketsBaseSessionServicewith lifecycle helpers (_apply,_trim,_seed,_restore,_evict)secret:*keys redacted; new_is_sensitive_json_string()detects credential-bearing JSON blobssecret:as a valid state prefixBehavior
Test plan
tests/unittests/sessions/test_secret_state.pyCloses #5112
🤖 Generated with Claude Code