Encrypting Sensitive State Data at Rest and in Transit
Google Cloud encrypts your ADK session data by default — but what you put in state is your call. A layered guide: AES-256 at rest, TLS in transit, and encrypt-before-state plus Secret Manager at the application layer.
Published on • December 3, 2026
AI Assistant

Your agent’s session.state is a dictionary that gets serialized, stored, transmitted, and — because it feeds instructions — sent to a model. So the question “is our data encrypted?” has three different answers, and they are owned by three different parties: Google Cloud encrypts storage at rest and traffic in transit by default; you decide what is allowed to enter state in the first place. Conflating the layers is how teams end up with a security review finding a raw API key sitting in a user:-scoped key, encrypted perfectly at rest and exposed to every prompt that reads it.
This article separates the layers, cites what Google guarantees, and gives you the ADK-side pattern: encrypt sensitive values before they touch state, and keep secrets out of state entirely — by reference instead.
Prerequisites
- An ADK app using a persistent
SessionService(DatabaseSessionServiceorVertexAiSessionService). - Basic vocabulary: state prefixes (
user:,app:,temp:), artifacts, and the difference between data at rest and data in transit. - For the application-layer examples:
pip install cryptography(Fernet) and, where noted,google-cloud-secret-manager.
1. Where session data actually lives
Every piece of an ADK conversation has a resting place — and knowing it tells you which encryption layer applies:
| Data | Lives in | Encrypted by default? |
|---|---|---|
session.state (incl. user:/app: keys) | SessionService storage: your DB, or Agent Platform via Vertex AI | Yes — storage layer of the backing service |
session.events (message log) | Same SessionService storage | Yes |
| Artifacts (attachments, generated files) | InMemory* (RAM) or GCS bucket via GcsArtifactService | GCS: yes, at rest; in-memory: no persistence at all |
| Traffic: client → your API → ADK runtime | The network | TLS in transit on Google Cloud endpoints |
| Traffic: state → model prompt | Provider API call | TLS to the endpoint; the plaintext is now in the prompt |
The last row is the one no storage encryption fixes. Encryption at rest protects a disk; it does not protect a value that has been read into a prompt, logged, or echoed to a user.
2. Encryption at rest: what Google guarantees
Google Cloud encrypts all customer content stored at rest by default, without any action from you, using AES-256 at the storage layer: data is chunked, each chunk encrypted with its own data encryption key (DEK), and DEKs are wrapped by key encryption keys (KEKs) — envelope encryption — with the key hierarchy held in Google’s Keystore. Cloud SQL, Cloud Storage, and Vertex AI storage all inherit this default.
When policy or regulation requires your control over keys, Cloud KMS provides CMEK (customer-managed encryption keys): you create, rotate, track, and delete the key, and the service uses it to encrypt your data.
| Key option | Who owns it | Who rotates it | Use when |
|---|---|---|---|
| Google-managed (default) | Default posture — encryption without configuration | ||
| CMEK via Cloud KMS | You | You (or Cloud KMS auto-rotation) | Compliance needs key control, audit logs, or revocation |
| Application-layer encryption (Section 4) | You | You | Value-level protection before storage |
Nothing about ADK changes with CMEK: your sessions, events, and GCS artifacts are encrypted by the backing service either way — CMEK changes whose key is in the hierarchy, not whether encryption happens.
3. Encryption in transit: TLS everywhere, with two caveats
Between endpoints, Google Cloud secures data with TLS: requests to Google Cloud services over HTTPS/HTTP2/HTTP3 are secured with TLS terminated at the Google Front End (BoringSSL), service-to-service traffic inside Google’s network uses ALTS, and VM-to-VM traffic over internal IPs in a VPC is encrypted and integrity-protected at the network layer. Modern endpoints negotiate TLS 1.2+ with forward-secure key exchange.
Two caveats matter for an ADK deployment:
- External-IP connections are not automatically encrypted inside Google’s network — traffic between VMs (or to Cloud SQL) reached via external IP addresses relies on the application protocol for encryption. Prefer internal IPs, private access, or TLS to the load balancer for every hop that carries state.
- Your client hops are yours to secure. Terminate TLS at the load balancer (Google-managed certificates are fine), and require HTTPS from the browser to your API — the ADK runtime never sees plaintext it wasn’t sent over a channel you control.
4. Application layer: encrypt before state, reference instead of store
Storage encryption is a property of the platform. What enters session.state is a property of your code. Two rules cover most findings:
Rule 1 — never put raw secrets or unnecessary PII in state. State is read into prompts, dumped in debugging, replayed in audits, and — if a key is prefixed user: — carried across every session of that user. Store a reference and resolve it at use time:
# BAD: secret lives in state, in prompts, in every replayed event delta.
# event state_delta -> {"user:api_key": "sk-live-..."}
#
# GOOD: state holds only a pointer; the value never enters the session document.
from google.adk.events import Event, EventActions
async def store_credential_ref(session, session_service, secret_id: str, ts: float):
delta = {
"user:payment_credential_ref": f"secretmanager://projects/{PROJECT}/"
f"secrets/{secret_id}/versions/latest",
"user:credential_scope": "payment",
"user:credential_updated_at": ts,
}
await session_service.append_event(
session,
Event(invocation_id="inv_store_ref", author="system",
actions=EventActions(state_delta=delta), timestamp=ts),
)
Per-user credentials stay in Secret Manager, fetched by your backend with IAM checks — never assembled into an instruction string or handed to the model. The model only ever needs to know a credential exists and what it is scoped to.
Rule 2 — if a value must live in state, encrypt it before the write. For genuinely session-sensitive values (a decrypted document extract, a token with a short window), seal them at the application layer:
import base64
import os
from cryptography.fernet import Fernet
# Load once per process from your secret store — never hardcode.
_FERNET = Fernet(base64.urlsafe_b64encode(os.environ["STATE_ENC_KEY"].encode()[:32].ljust(32, b"=")))
def seal(value: str) -> str:
return _FERNET.encrypt(value.encode()).decode()
def open_sealed(token: str) -> str:
return _FERNET.decrypt(token.encode()).decode()
# Write path — still through a sanctioned state write:
# delta = {"user:oauth_token_enc": seal(access_token)}
# Read path — decrypt only at the moment of use, never for logging.
Key management for STATE_ENC_KEY follows the same principle as everything else: it is a secret, so it comes from Secret Manager or your platform’s secret store, it is rotated on a schedule, and it is never written to state itself.
5. The layer map
| Threat | Control | Owner |
|---|---|---|
| Stolen disk / backup media | AES-256 encryption at rest (default), optional CMEK | Google Cloud |
| Network interception | TLS 1.2+ to endpoints, ALTS/VPC internal encryption | Google Cloud + your TLS config |
| Secret leaking into prompts/logs | Secrets out of state; Secret Manager references | Your application code |
| PII in long-lived storage | Encrypt-before-state for values that must persist | Your application code |
| Over-broad access to stored data | IAM on bucket/DB, per-user authorization on artifact fetch | Your application code |
Checklist
- Inventory of state keys exists — every
user:/app:key is classified: harmless / PII / secret. - No raw secrets (API keys, tokens, passwords) anywhere in
session.stateor event deltas. - Per-user credentials live in Secret Manager (or equivalent) and are referenced, not stored.
- Values that must persist in state are sealed with an application-layer key (
seal()before the write). - The state-encryption key itself comes from a secret store and has a rotation procedure.
- Every client hop is HTTPS; no state carries traffic over external-IP plaintext channels.
- CMEK policy is decided (and documented) for the DB / GCS bucket / Vertex AI resources backing the
SessionService. - Debug logs, audit exports, and replay tooling redact the sealed values and sensitive keys.
- Artifact buckets have per-user authorization on any client fetch path.
Conclusion
Encryption for an ADK app is a stack, not a switch. Google Cloud gives you AES-256 at rest and TLS in transit by default — with CMEK when compliance needs your key in the loop — and ADK’s state and artifact plumbing rides on those guarantees automatically. The layer that does not come for free is the one you own: what enters session.state in the first place. Keep secrets in Secret Manager and reference them, seal anything sensitive that must persist, and treat every state delta as data that will one day be read back, replayed, and logged. Encrypt before state, and the platform’s defaults become a floor rather than a false sense of coverage.