Lab 31: Multi-Target Runtime Promotion, Workload Identity & Pre-Flight Auditing
Goalโ
Welcome to the hands-on kickoff of Part 7: Cloud Runtimes & Enterprise! Taking the canonical support-ops-agent (gemini-3.8-flash) that you built, evaluated, gated, and cost-tuned in Part 6 (Modules 30.1โ30.4), you will:
- Promote
support-ops-agentacrosscloud_runandagent_runtimeinfrastructure profiles (including Agent Identity and Agent GatewayDockerfileroot-CA readiness) without touchingapp/agent.py. - Inspect live non-destructive rollout plans using
agents-cli deploy --dry-run. - Build a Python Cloud Runtime & Identity Readiness Auditor (
scripts/audit_runtime_matrix.py) that programmatically verifies manifest invariants,Dockerfilegateway CA trust, reasoning-engine adapter routes, and Cloud Run--dry-runsecurity flags. - Solve four enterprise deployment architecture & Workload Identity design scenarios.
(Zero live cloud billing is required in this lab โ every command runs 100% locally via scaffold enhance --skip-checks and deploy --dry-run, preparing your workspace for live Cloud Run, GKE, and Agent Runtime rollouts in Modules 32โ35!)
Environment setup:
- 1-Click Launch (Browser): Open in GitHub CodespacesOpen in Google Cloud Shell
- Local machine: If you're continuing the course in sequence,
cdinto theadk-trainingproject you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:uv init adk-training --python 3.10 && cd adk-training
uv add "google-adk>=2.1.0" python-dotenv- DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python 3.11,
uv,gcloud, and all core ADK dependencies are pre-installed in your container environment.
Prerequisitesโ
- Python 3.10+,
uv, andgoogle-agents-cli(v1.10+) installed from Part 6 (uv tool install google-agents-cli). - Your
support-ops-agentproject from Part 6 (or use the 10-second fast-bootstrap in Step 1 below).
Step 1: Reuse or Fast-Bootstrap support-ops-agentโ
If you already have support-ops-agent/ from Part 6, cd into it. Otherwise, fast-bootstrap the canonical support-ops-agent in your workspace directory (remember: never mkdir before agents-cli create):
cd /path/to/your/adk-training
# Only if support-ops-agent/ does not exist yet:
agents-cli create support-ops-agent \
--agent adk \
--prototype \
--agent-guidance-filename GEMINI.md \
--skip-checks -y
curl -fsSL https://mauripsale.github.io/doc-adk-training/samples/part6/agent.py \
-o support-ops-agent/app/agent.py
cd support-ops-agent
agents-cli info
Verify that app/agent.py uses MODEL = "gemini-3.8-flash", Agent(name="support_ops_agent", ...), and app = App(root_agent=root_agent, name="app").
Step 2: Compare cloud_run vs. agent_runtime Infrastructure Promotionโ
-
First, enhance
support-ops-agentfor Cloud Run with managed Cloud SQL Postgres sessions:agents-cli scaffold enhance . \
--deployment-target cloud_run \
--session-type cloud_sql \
--cicd-runner github_actions \
--skip-checks -yInspect
agents-cli-manifest.yaml,app/fast_api_app.py, anddeployment/terraform/. Notice howotel_to_cloud = Trueis wired directly inapp/fast_api_app.pyand Terraform includes Cloud SQL +app_sa+cicd_runner_sadefinitions whileapp/agent.pywas preserved untouched. -
Preview a hardened Cloud Run rollout with
agents-cli deploy --dry-run: Supposesupport-ops-agentwill sit behind Identity-Aware Proxy (--iap), keep 1 warm instance (--min-instances 1), and support long-lived streaming sessions (--timeout 3600):# If you added the deploy override gate in Module 30.3, either pass with a green scorecard
# or set AGENTS_CLI_DISABLE_OVERRIDES=1 to inspect the raw built-in dry-run directly:
AGENTS_CLI_DISABLE_OVERRIDES=1 agents-cli deploy \
--deployment-target cloud_run \
--project enterprise-support-prod \
--region us-central1 \
--iap \
--min-instances 1 \
--timeout 3600 \
--dry-run -
Now re-target the project in place for Agent Runtime with
agent_identityand--agent-gateway: Remember: on Agent Runtime, sessions are managed automatically viaVertexAiSessionService, so you must not pass a custom--session-type!# TODO: Run `agents-cli scaffold enhance .` with:
# --deployment-target agent_runtime
# --agent-runtime-identity-default agent_identity
# --agent-gateway
# --cicd-runner github_actions
# --skip-checks -yOpen
Dockerfileandapp/fast_api_app.pyafter running the command:- What build argument and CA certificate block did
--agent-gatewayadd toDockerfile? - Which adapter route helper did
--deployment-target agent_runtimeattach at the bottom ofapp/fast_api_app.py?
- What build argument and CA certificate block did
Step 3: Implement the Runtime & Identity Readiness Auditor (scripts/audit_runtime_matrix.py)โ
Platform engineering teams validate repository scaffolding invariants in CI before allowing agents-cli deploy to run. Create scripts/audit_runtime_matrix.py inside support-ops-agent/ and complete the # TODO 1 through # TODO 4 checks:
"""
Pre-flight Runtime & Workload Identity Auditor for `support-ops-agent`.
Verifies Agent Runtime manifest invariants, Agent Gateway CA trust, dual-protocol
routes, and hardened Cloud Run `--dry-run` rollout flags.
"""
from pathlib import Path
import os
import subprocess
import sys
import yaml
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def check_manifest_and_gateway(root: Path) -> list[str]:
"""Returns a list of validation errors (empty list == all checks passed)."""
errors: list[str] = []
manifest_path = root / "agents-cli-manifest.yaml"
dockerfile_path = root / "Dockerfile"
fastapi_path = root / "app" / "fast_api_app.py"
manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
create_params = manifest.get("create_params") or {}
# TODO 1: Verify core `agents-cli-manifest.yaml` invariants for Agent Runtime:
# - `manifest.get("agent_directory")` MUST equal `"app"`
# - `create_params.get("deployment_target")` MUST equal `"agent_runtime"`
# - `(create_params.get("agent_runtime") or {}).get("identity_default")` MUST equal `"agent_identity"`
# - Record an error string in `errors` if any check fails.
dockerfile_text = dockerfile_path.read_text(encoding="utf-8")
# TODO 2: Verify Agent Gateway TLS inspection readiness in `Dockerfile`:
# - Confirm `"AGENT_GATEWAY_ROOT_CERTIFICATES"` appears in `dockerfile_text`
# so `--agent-gateway-egress` will not fail outbound TLS handshakes.
fastapi_text = fastapi_path.read_text(encoding="utf-8")
# TODO 3: Verify dual-protocol serving in `app/fast_api_app.py`:
# - Confirm BOTH `"attach_a2a_routes"` AND `"attach_reasoning_engine_routes"`
# are present in `fastapi_text`.
return errors
def preview_cloud_run_dry_run(root: Path) -> list[str]:
"""Executes `agents-cli deploy --dry-run` for Cloud Run and verifies flags."""
errors: list[str] = []
env = {**os.environ, "AGENTS_CLI_DISABLE_OVERRIDES": "1"}
# TODO 4: Run `subprocess.run(...)` from `cwd=root` with `env=env`, `capture_output=True`, `text=True`:
# Command:
# ["agents-cli", "deploy", "--deployment-target", "cloud_run",
# "--project", "enterprise-support-prod", "--region", "us-central1",
# "--iap", "--min-instances", "1", "--timeout", "3600", "--dry-run"]
# Verify `proc.returncode == 0` and confirm the combined stdout/stderr output
# includes `"--iap"`, `"3600"`, and `"enterprise-support-prod"`. Append descriptive
# messages to `errors` if any assertion fails.
return errors
def main() -> int:
all_errors = check_manifest_and_gateway(PROJECT_ROOT) + preview_cloud_run_dry_run(PROJECT_ROOT)
if all_errors:
print("โ Runtime & Identity Readiness Audit FAILED:")
for err in all_errors:
print(f" - {err}")
return 1
print("โ
Runtime & Identity Readiness Audit PASSED (Agent Runtime + Gateway CA + Cloud Run dry-run verified)!")
return 0
if __name__ == "__main__":
sys.exit(main())
Run your auditor and confirm it exits 0:
uv run python scripts/audit_runtime_matrix.py
Step 4: Enterprise Runtime & Workload Identity Scenariosโ
Match each architecture requirement below to the exact agents-cli target, session, and identity configuration:
- Scenario 1 โ Serverless Partner A2A & Eventarc Webhook: Needs instant HTTPS scale-to-zero, Eventarc Pub/Sub triggers (
/apps/app/trigger/*), durable PostgreSQL sessions, and least-privilege service-account execution. - Scenario 2 โ Regulated Healthcare Agent with Governed Egress & User OAuth: Needs HIPAA + FedRAMP posture, per-agent cryptographic identity, outbound TLS inspection via an Agent Gateway, CMEK encryption, and Gemini Enterprise OAuth 2.0 user consent.
- Scenario 3 โ Multi-Tenant Kubernetes Mesh with GPU Sidecars: Runs inside an existing platform cluster requiring custom GPU node pools and strict Kubernetes
NetworkPolicyisolation between namespaces. - Scenario 4 โ Browser Duplex Voice Concierge (
gemini-3.8-live) on Serverless Containers: Serves long-lived 30-minute WebSocket/run_livestreams without cold-start audio dropouts or 5-minute request cutoffs.
Self-Reflection Questionsโ
- Why is
agent_identity(--agent-runtime-identity-default agent_identity/--agent-identity) required before binding an Agent Runtime service to an Agent Gateway, and how does it differ from a shared project service account? - Why must you run
agents-cli scaffold enhance . --agent-gatewaybefore deploying with--agent-gateway-egress? - Why does
agents-clicreate two distinct identities in Terraform (cicd_runner_saandapp_sa) instead of reusing a single service account for both CI/CD rollouts and runtime execution?
๐ Reference Solution Vaultโ
Official Solution Vault โ Module 31
Locked Challenge โ Active Pedagogical Socratic Gate