1
---
2
name: google-cloud-solution-multi-agent-security
3
metadata:
4
version: "1.0.1"
5
category: MultiProductSolutions
6
description: >-
7
Designs, deploys, and secures Google Cloud Agent Gateway solutions.
8
Use when the user needs to configure multi-agent security, ingress (CLIENT_TO_AGENT), or egress (AGENT_TO_ANYWHERE) patterns involving Model Armor, IAP, and Agent Registry.
9
Don't use for general Cloud Load Balancing or basic VPC setup not related to Agent Gateways.
10
---
11
12
# Agent Gateway multi-agent security
13
14
## Attribution
15
16
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
17
MUST read and follow the instructions in
18
[Usage Attribution](references/attribution.md).
19
20
## Critical Enforcement Rules & Rationale
21
22
* **Gcloud Release Tracks**: Always use the exact release tracks specified in
23
the commands (e.g., `gcloud beta network-services agent-gateways`). Omitting
24
these prefixes causes commands to fail because Agent Gateway features are
25
located in specialized, non-default namespaces.
26
* **API Enablement**: Include `modelarmor.googleapis.com` in the API
27
enablement list when setting up guardrails. Excluding it prevents Model
28
Armor policies and filters from successfully attaching to the Gateway.
29
* **Egress Verification**: Egress policy verification requires using the
30
Python script
31
([scripts/verify_egress_policies.py](scripts/verify_egress_policies.py)),
32
not `curl`. Egress gateways rely on runtime SDK lifecycle handling and JWT
33
context that a standard curl command cannot simulate correctly.
34
* **Model Armor Keys**: In `model-armor-config.yaml`, always include both
35
`piAndJailbreakFilterSettings` and `sdpFilterSettings` (`filterEnforcement:
36
ENFORCE`). Invalid or missing filters cause deployment validation failures
37
or lead to silent bypasses of the guardrails.
38
* **Subnet Private Access**: Any subnet hosting a Private Service Connect
39
network attachment for Egress Gateways must have `private_ip_google_access =
40
true` enabled in Terraform. Disabling this blocks connectivity to
41
Google-managed endpoints, causing total routing failures for agents.
42
* **Direct Delivery**: Immediately provide the requested architecture,
43
configuration files, CLI commands, scripts, and diagrams in full. Do not
44
stop at a planning phase, do not generate a plan artifact, and do not ask
45
for user confirmation before delivering outputs.
46
* **No Infrastructure Execution**: Do not attempt to run deployment or
47
verification commands (such as `gcloud`, `kubectl`, `terraform`, or `curl`)
48
against real cloud resources during design. You are generating plan
49
configurations, not executing them.
50
51
> [!IMPORTANT] **Just-In-Time (JIT) Resource Loading Protocol:** Inspect
52
> template files in [assets/](assets/) and executable scripts in
53
> [scripts/](scripts/) using `view_file` as needed for extended configurations,
54
> deployment scripts, and test suites.
55
56
--------------------------------------------------------------------------------
57
58
## Quick Reference: Required Filenames
59
60
Always generate files with these exact names when requested:
61
62
1. `agw-ingress-config.yaml`
63
([assets/agw-ingress-config.yaml](assets/agw-ingress-config.yaml))
64
2. `agw-egress-config.yaml`
65
([assets/agw-egress-config.yaml](assets/agw-egress-config.yaml))
66
3. `agw-authz-extension.yaml`
67
([assets/agw-authz-extension.yaml](assets/agw-authz-extension.yaml))
68
4. `agw-authz-policy.yaml`
69
([assets/agw-authz-policy.yaml](assets/agw-authz-policy.yaml))
70
5. `model-armor-config.yaml`
71
([assets/model-armor-config.yaml](assets/model-armor-config.yaml))
72
6. `sgp-policy.yaml` ([assets/sgp-policy.yaml](assets/sgp-policy.yaml))
73
7. `iap-policy.json` ([assets/iap-policy.json](assets/iap-policy.json))
74
8. `model-armor-payload.json`
75
([assets/model-armor-payload.json](assets/model-armor-payload.json))
76
77
--------------------------------------------------------------------------------
78
79
## 1. Dual Ingress & Egress Architecture Design (`dual_ingress_egress_architecture_design`)
80
81
- **Ingress Pattern**: `CLIENT_TO_AGENT` fronted by Ingress Control Plane
82
(Agent Gateway, Model Armor).
83
- **Egress Pattern**: `AGENT_TO_ANYWHERE` utilizing Egress Control Plane
84
(Agent Gateway, `roles/iap.egressor` CEL policies, Cloud DNS) and Egress
85
Data Plane (PSC Interface, Cloud Run, PSC Google APIs Global Endpoint),
86
coordinated via Agent Registry & Agent Engine runtime.
87
- **Mermaid Diagram**:
88
89
```mermaid
90
graph TD
91
Client["External Clients"] -->|HTTPS / MCP| GLB["Global Load Balancer"]
92
GLB --> Ingress["Ingress Agent Gateway (CLIENT_TO_AGENT)"]
93
Ingress --> MA["Model Armor (CONTENT_AUTHZ)"]
94
MA --> Agent["Agent Engine Agents (BillingAgent, SupportAgent, FraudAgent)"]
95
Agent --> Egress["Egress Agent Gateway (AGENT_TO_ANYWHERE)"]
96
Egress --> PSC["Private Service Connect Network Attachment"]
97
PSC --> Tools["Private MCP Tool Backends"]
98
```
99
100
--------------------------------------------------------------------------------
101
102
## 2. Ingress & Egress Guardrail Policy Config (`ingress_and_egress_guardrail_policy_config`)
103
104
When requested for Ingress & Egress guardrail policy configs, you MUST generate
105
and create all required files in the workspace:
106
107
- `agw-ingress-config.yaml`
108
([assets/agw-ingress-config.yaml](assets/agw-ingress-config.yaml)): Declares
109
`governedAccessPath: CLIENT_TO_AGENT` with protocols `HTTP` and `MCP`.
110
- `agw-egress-config.yaml`
111
([assets/agw-egress-config.yaml](assets/agw-egress-config.yaml)): Declares
112
`governedAccessPath: AGENT_TO_ANYWHERE` with protocol `MCP`.
113
- `agw-authz-extension.yaml`
114
([assets/agw-authz-extension.yaml](assets/agw-authz-extension.yaml)):
115
Configures AuthzExtension service for IAP authorization.
116
- `agw-authz-policy.yaml`
117
([assets/agw-authz-policy.yaml](assets/agw-authz-policy.yaml)): Configures
118
`AuthzPolicy` action `ALLOW` targeting both Ingress and Egress gateways.
119
- `iap-policy.json` ([assets/iap-policy.json](assets/iap-policy.json)): Binds
120
`roles/iap.egressor` with CEL condition checking
121
`iap.googleapis.com/mcp.toolName == 'get_account_balance' &&
122
iap.googleapis.com/mcp.tool.isReadOnly == true`.
123
- `model-armor-config.yaml`
124
([assets/model-armor-config.yaml](assets/model-armor-config.yaml)): Enables
125
`piAndJailbreakFilterSettings` and `sdpFilterSettings` with
126
`filterEnforcement: ENFORCE`.
127
- `sgp-policy.yaml` ([assets/sgp-policy.yaml](assets/sgp-policy.yaml)):
128
Implements Natural Language Constraints blocking transactions > $1000 and
129
sanitizing PII.
130
131
--------------------------------------------------------------------------------
132
133
## 3. Ingress & Egress Infrastructure Deployment (`ingress_and_egress_infrastructure_deployment`)
134
135
Inspect and provide the step-by-step `gcloud` CLI commands from
136
[scripts/deploy_infrastructure.sh](scripts/deploy_infrastructure.sh):
137
138
1. **Enable Required APIs**: `compute`, `networkservices`, `networksecurity`,
139
`modelarmor`, `iap`, `agentregistry`, `serviceextensions`, and `aiplatform`.
140
2. **Import Agent Gateways**: Ingress (`agw-ingress-config.yaml`) and Egress
141
(`agw-egress-config.yaml`) via `gcloud alpha network-services agent-gateways
142
import`.
143
3. **Import Authz Extension**: `agw-authz-extension.yaml` via `gcloud beta
144
service-extensions authz-extensions import`.
145
4. **Import Authz Policy**: `agw-authz-policy.yaml` via `gcloud beta
146
network-security authz-policies import`.
147
148
--------------------------------------------------------------------------------
149
150
## 4. Ingress & Egress Security Validation (`ingress_and_egress_security_validation`)
151
152
When validating security for Ingress and Egress:
153
154
1. **Ingress 403 Unauthenticated Test**: Provide the copy-pasteable
155
verification curl command from
156
[scripts/validate_ingress_unauth.sh](scripts/validate_ingress_unauth.sh)
157
sending an unauthenticated POST request to the Reasoning Engine endpoint
158
expecting HTTP 403 Forbidden.
159
2. **Python Egress Verification Script (MUST use Python script snippet, NOT
160
curl)**: Provide the Python verification script snippet from
161
[scripts/verify_egress_policies.py](scripts/verify_egress_policies.py)
162
sending JSON-RPC `tools/call` requests (`get_account_balance`) through the
163
Egress Gateway to verify HTTP 200 for allowed tools.
164
3. **Model Armor Test Payload**: Generate `model-armor-payload.json`
165
([assets/model-armor-payload.json](assets/model-armor-payload.json))
166
containing prompt injection/jailbreak instructions.
167
168
--------------------------------------------------------------------------------
169
170
## 5. Troubleshooting Ingress & Egress Failures (`troubleshooting_ingress_and_egress_failures`)
171
172
- **Ingress 403 (Client-to-Agent)**:
173
174
- **Root Cause**: Unauthenticated client requests or missing/invalid OAuth
175
2.0 / IAP identity tokens.
176
- **OAuth Configuration Steps**:
177
1. Configure OAuth 2.0 Client ID credentials in Google Cloud Console.
178
2. Grant the client identity / service account
179
`roles/iap.httpsResourceAccessor` permission.
180
3. Exchange credentials with Google OAuth to acquire an OIDC / OAuth ID
181
token.
182
4. Pass the token in the `Authorization: Bearer <TOKEN>` header.
183
- **Verification Command**: Provide the curl command from
184
[scripts/verify_ingress_auth.sh](scripts/verify_ingress_auth.sh).
185
186
- **Egress 403 (Agent-to-Anywhere)**:
187
188
- **Root Cause**: Missing `roles/iap.egressor` IAM bindings on the Agent
189
Identity, malformed principal ID, or mismatched CEL condition on tool
190
metadata.
191
- **Fix Command**: Provide the exact `gcloud` command from
192
[scripts/fix_egress_iap.sh](scripts/fix_egress_iap.sh).
193
194
--------------------------------------------------------------------------------
195
196
## 6. Hybrid VPN Connectivity & Egress Routing (`hybrid_vpn_connectivity_egress_routing`)
197
198
- **Terraform HCL**: Refer to baseline Terraform config in
199
[assets/main.tf](assets/main.tf) for VPC, subnets
200
(`private_ip_google_access = true`), PSC network attachment, Cloud DNS
201
private forwarding for `aws.internal.`, and HA VPN gateway/router.
202
- **Egress Gateway Config (`agw-egress-config.yaml`)**: Generate configuration
203
declaring `governedAccessPath: AGENT_TO_ANYWHERE`, pointing to the PSC
204
network attachment, and referencing `aws.internal.` in `dnsPeeringConfig`
205
(see [assets/agw-egress-config.yaml](assets/agw-egress-config.yaml)).
206
- **Python SDK Deployment Script**: Refer to
207
[scripts/hybrid_vpn_agent.py](scripts/hybrid_vpn_agent.py) for the complete
208
script initializing Vertex AI with `agent_to_anywhere_config` referencing
209
the Egress Gateway, enabling telemetry, and deploying `HybridAgent` using
210
`types.IdentityType.AGENT_IDENTITY`.
211
212
--------------------------------------------------------------------------------
213
214
## 7. Private Egress GKE Internal Load Balancer (`private_egress_gke_internal_load_balancer`)
215
216
- Expose GKE internal MCP tool server via an Internal Load Balancer (ILB) at
217
literal IP `10.0.1.50`, connecting via Agent Gateway PSC Interface + Cloud
218
DNS Private zone.
219
- **Cloud DNS Record Mapping**: Provide the command from
220
[scripts/create_gke_dns_record.sh](scripts/create_gke_dns_record.sh) mapping
221
the private domain to GKE's private ILB IP `10.0.1.50`.
222
- **Explicit TLS Warning**: Agent Gateway egress **does not natively trust
223
self-signed certificates or private enterprise CAs**. You **must** use
224
publicly trusted TLS certificates signed by a trusted Certificate Authority
225
(e.g., Let's Encrypt).
226
227
--------------------------------------------------------------------------------
228
229
## 8. Governance Controls Model Armor SGP (`governance_controls_model_armor_sgp`)
230
231
When configuring dual safety layers with Model Armor on Ingress and SGP on
232
Egress:
233
234
1. **Model Armor Config**: Generate `model-armor-config.yaml`
235
([assets/model-armor-config.yaml](assets/model-armor-config.yaml)) with
236
`piAndJailbreakFilterSettings` and `sdpFilterSettings` (`filterEnforcement:
237
ENFORCE`).
238
2. **Semantic Governance Policy**: Generate `sgp-policy.yaml`
239
([assets/sgp-policy.yaml](assets/sgp-policy.yaml)) with Natural Language
240
Constraints blocking transactions > $1000 and sanitizing PII.
241
3. **Curl PATCH Command**: Provide the curl command from
242
[scripts/enforce_sgp_patch.sh](scripts/enforce_sgp_patch.sh) to update
243
`authzExtensions` with `sgpEnforcementMode` set to `ENFORCE`.
244
245
--------------------------------------------------------------------------------
246
247
## 9. Multi-Agent Cloud Run Egress Routing (`multi_agent_cloud_run_egress_routing`)
248
249
Do NOT produce a plan artifact or stop at planning. When configuring multi-agent
250
Cloud Run egress routing, you MUST directly provide and generate ALL required
251
components:
252
253
1. **Egress Gateway Config (`agw-egress-config-run.yaml`)**: Generate
254
configuration declaring `governedAccessPath: AGENT_TO_ANYWHERE`, PSC network
255
attachment, and DNS peering for `*.run.app` (see
256
[assets/agw-egress-config-run.yaml](assets/agw-egress-config-run.yaml)).
257
2. **Register Cloud Run Services in Agent Registry**: Provide the registration
258
commands from
259
[scripts/register_cloud_run_services.sh](scripts/register_cloud_run_services.sh)
260
registering all 3 Cloud Run services (`marketing-tool-service`,
261
`sales-tool-service`, `support-tool-service`) in the `us-east4` Agent
262
Registry.
263
3. **`iap-policy.json` (Multi-Agent)**: Generate `iap-policy.json`
264
([assets/iap-policy-multi-agent.json](assets/iap-policy-multi-agent.json))
265
containing all 3 `principal://` bindings in the `members` list under
266
`roles/iap.egressor`.
267
4. **Python SDK Deployment Script**: Refer to
268
[scripts/multi_agent_cloud_run.py](scripts/multi_agent_cloud_run.py) for the
269
complete GenAI SDK deployment script.
270
271
--------------------------------------------------------------------------------
272
273
## 10. Advanced Model Armor Filtering (`advanced_model_armor_filtering`)
274
275
For custom keyword matching, configure `userDefinedFilterSettings` (see
276
[assets/model-armor-advanced.yaml](assets/model-armor-advanced.yaml)).
277
278
--------------------------------------------------------------------------------
279
280
## 11. Known Traps & Gotchas (`known_traps_and_gotchas`)
281
282
* **`network_attachment` is `ForceNew`**: Enabling Semantic Governance
283
Policies (SGP) or modifying network attachments after the initial Terraform
284
apply will force-recreate the gateway resource. If not managed carefully,
285
this can cause dependency deadlocks during destroy operations. Plan
286
infrastructure sequencing accordingly.
287
* **Authz Policy Limit**: An Agent Gateway allows at most **4 custom
288
authorization policies** attached concurrently. Ensure your security posture
289
consolidates rules within this limit.
290