Skip to main content

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:

  1. Promote support-ops-agent across cloud_run and agent_runtime infrastructure profiles (including Agent Identity and Agent Gateway Dockerfile root-CA readiness) without touching app/agent.py.
  2. Inspect live non-destructive rollout plans using agents-cli deploy --dry-run.
  3. Build a Python Cloud Runtime & Identity Readiness Auditor (scripts/audit_runtime_matrix.py) that programmatically verifies manifest invariants, Dockerfile gateway CA trust, reasoning-engine adapter routes, and Cloud Run --dry-run security flags.
  4. 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, cd into the adk-training project 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, and google-agents-cli (v1.10+) installed from Part 6 (uv tool install google-agents-cli).
  • Your support-ops-agent project 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โ€‹

  1. First, enhance support-ops-agent for 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 -y

    Inspect agents-cli-manifest.yaml, app/fast_api_app.py, and deployment/terraform/. Notice how otel_to_cloud = True is wired directly in app/fast_api_app.py and Terraform includes Cloud SQL + app_sa + cicd_runner_sa definitions while app/agent.py was preserved untouched.

  2. Preview a hardened Cloud Run rollout with agents-cli deploy --dry-run: Suppose support-ops-agent will 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
  3. Now re-target the project in place for Agent Runtime with agent_identity and --agent-gateway: Remember: on Agent Runtime, sessions are managed automatically via VertexAiSessionService, 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 -y

    Open Dockerfile and app/fast_api_app.py after running the command:

    • What build argument and CA certificate block did --agent-gateway add to Dockerfile?
    • Which adapter route helper did --deployment-target agent_runtime attach at the bottom of app/fast_api_app.py?

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:

  1. 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.
  2. 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.
  3. Scenario 3 โ€” Multi-Tenant Kubernetes Mesh with GPU Sidecars: Runs inside an existing platform cluster requiring custom GPU node pools and strict Kubernetes NetworkPolicy isolation between namespaces.
  4. Scenario 4 โ€” Browser Duplex Voice Concierge (gemini-3.8-live) on Serverless Containers: Serves long-lived 30-minute WebSocket /run_live streams 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-gateway before deploying with --agent-gateway-egress?
  • Why does agents-cli create two distinct identities in Terraform (cicd_runner_sa and app_sa) instead of reusing a single service account for both CI/CD rollouts and runtime execution?

๐Ÿ” Reference Solution Vaultโ€‹

๐Ÿงช

31: Deployment Strategies & Identity(Challenge Lab)

Part 7: Cloud Runtimes & Enterprise โ€ข Module 31