Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions assets/agw-docs/pages/security/csrf.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ For requests without a `Sec-Fetch-Site` header, the policy compares the host and
{{< /version >}}

Review the following diagram to see an example CSRF request flow:
{{< version exclude-if="1.0.x,1.1.x,1.2.x,1.3.x,1.4.x,1.5.x,1.6.x,1.7.x,2.2.x" >}}
```mermaid
sequenceDiagram
participant Attacker as Malicious Site<br/>(attacker.com)
participant User as User's Browser
participant AGW as AgentGateway Proxy
participant Backend as Backend Service

Note over Attacker,Backend: CSRF Attack Attempt

Attacker->>User: Trick user into visiting<br/>malicious page with hidden form
User->>AGW: POST /api/action<br/>Origin: malicioussite.com<br/>Cookie: session=abc123

AGW->>AGW: CSRF validation:<br/>Origin (malicioussite.com)<br/>vs Destination (api.example.com)

alt Origin does NOT match destination<br/>and NOT in additionalOrigins
AGW-->>User: 403 Forbidden<br/>"csrf validation failed"
Note over User,AGW: Attack blocked
end

Note over User,Backend: Legitimate Request

User->>AGW: POST /api/action<br/>Origin: allowThisOne.example.com<br/>Cookie: session=abc123

AGW->>AGW: CSRF validation:<br/>Origin in additionalOrigins list
AGW->>Backend: Forward request
Backend-->>AGW: 200 OK
AGW-->>User: 200 OK
```
{{< /version >}}
{{< version include-if="1.0.x,1.1.x,1.2.x,1.3.x,1.4.x,1.5.x,1.6.x,1.7.x,2.2.x" >}}
```mermaid
sequenceDiagram
participant Attacker as Malicious Site<br/>(attacker.com)
Expand Down Expand Up @@ -41,6 +72,7 @@ sequenceDiagram
Backend-->>AGW: 200 OK
AGW-->>User: 200 OK
```
{{< /version >}}

> [!NOTE]
> Note that because CSRF attacks specifically target state-changing requests, the filter only acts on HTTP requests that have a state-changing method such as `POST` or `PUT`.
Expand Down Expand Up @@ -101,6 +133,17 @@ Configure an {{< reuse "agw-docs/snippets/policy.md" >}} to enable CSRF protecti

Example output:

{{< version exclude-if="1.0.x,1.1.x,1.2.x,1.3.x,1.4.x,1.5.x,1.6.x,1.7.x,2.2.x" >}}
```console
* Request completely sent off
< HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
...
<
csrf validation failed%
```
{{< /version >}}
{{< version include-if="1.0.x,1.1.x,1.2.x,1.3.x,1.4.x,1.5.x,1.6.x,1.7.x,2.2.x" >}}
```console
* Request completely sent off
< HTTP/1.1 403 Forbidden
Expand All @@ -109,6 +152,7 @@ Configure an {{< reuse "agw-docs/snippets/policy.md" >}} to enable CSRF protecti
<
CSRF validation failed%
```
{{< /version >}}

3. Send another request to the httpbin app. This time, you include the `allowThisOne.example.com` origin header that is allowed in your policy. Verify that you get back a 200 HTTP response code, because the origin matches the origin that you specified in the {{< reuse "agw-docs/snippets/policy.md" >}} resource.

Expand Down
13 changes: 8 additions & 5 deletions content/docs/kubernetes/latest/documentation/llm/models/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,25 @@ The model did not attach to the listener, or it is not reachable by clients. Com
-o jsonpath='{.spec.template.spec.containers[0].env[?(@.name=="AGW_ENABLE_AGENTGATEWAY_MODELS")].value}'
```

2. Check how many routes attached to the listener. This count includes every `{{< reuse "agw-docs/snippets/agentgatewaymodel.md" >}}` that attached, whether public or internal.
2. Check whether the parent accepted the model. An unaccepted model reports `Accepted: False` in `status.parents`.

```sh
kubectl get agentgatewaymodel gpt-4 -n {{< reuse "agw-docs/snippets/namespace.md" >}} -o yaml
```

3. Check how many routes attached to the listener. This count includes every `{{< reuse "agw-docs/snippets/agentgatewaymodel.md" >}}` that attached, whether public or internal.

```sh
kubectl get gateway agentgateway-proxy -n {{< reuse "agw-docs/snippets/namespace.md" >}} \
-o jsonpath='{.status.listeners[0].attachedRoutes}'
```

3. List the models that clients can reach. If a model is missing here but the `attachedRoutes` count includes it, the model is `Internal`.
4. List the models that clients can reach. If a model is missing here but the `attachedRoutes` count includes it, the model is `Internal`.

```sh
curl -s http://$INGRESS_GW_ADDRESS/v1/models
```

> [!WARNING]
> The `{{< reuse "agw-docs/snippets/agentgatewaymodel.md" >}}` resource does not yet report status. The `status.parents` field stays empty even when a model serves traffic correctly, so you cannot use `kubectl describe agmodel` to debug attachment. Use the checks in this section instead.

### Cleanup

> [!NOTE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The following table shows which resource types each policy section can target.
| -- | -- | -- | -- |
| `frontend` | Gateway | Depends on the field. See [Frontend section restrictions](#frontend-restrictions) for more information. | Applies to all listeners on the targeted Gateway. A `targetRef` or `targetSelector` can also set `port` to scope the policy to a single listener port on the Gateway. |
| `traffic` | Gateway, HTTPRoute, GRPCRoute, ListenerSet | Optional | When targeting a Gateway, the `sectionName` selects a specific listener. When targeting a ListenerSet, the `sectionName` selects a specific listener in that ListenerSet. When targeting an HTTPRoute or GRPCRoute, the `sectionName` selects a specific route rule. |
| `backend` | Gateway, HTTPRoute, GRPCRoute, ListenerSet, Service, {{< reuse "agw-docs/snippets/backend.md" >}} | Optional | When targeting a Service, the `sectionName` selects a specific port. When targeting an {{< reuse "agw-docs/snippets/backend.md" >}}, the `sectionName` selects a specific sub-backend. |
| `backend` | Gateway, HTTPRoute, GRPCRoute, Service, {{< reuse "agw-docs/snippets/backend.md" >}} | Optional | When targeting a Service, the `sectionName` selects a specific port. When targeting an {{< reuse "agw-docs/snippets/backend.md" >}}, the `sectionName` selects a specific sub-backend. |

### Frontend section restrictions {#frontend-restrictions}

Expand Down Expand Up @@ -79,14 +79,19 @@ Each policy section follows a different precedence order based on the specificit
| `frontend` | Gateway < Port < Listener |
| `traffic` (Gateway listeners) | Gateway < Listener < Route < Route rule |
| `traffic` (ListenerSet listeners) | Gateway < ListenerSet < ListenerSet listener < Route < Route rule |
| `backend` | Gateway < Listener < Route (targetRef) < Route rule (targetRef) < Backend (targetRef) < Backend (inline on the backend object) < Route backend ref (inline on the route) |
| `backend` | Gateway < Listener < Service or Backend (targetRef) < Sub-backend (targetRef with `sectionName`) < Route (targetRef) < Route rule (targetRef) < Backend (inline on the backend object) < Route backend ref (inline on the route) |

A listener is defined either on the Gateway or in a ListenerSet. So a `traffic` policy follows the Gateway listener order or the ListenerSet listener order, depending on where its listener is defined.

For a `frontend` policy, you can only apply the policy at the Listener level when the `frontend` policy field supports setting a `sectionName`. For more information about the fields that support the `sectionName` setting, see [Frontend section restrictions](#frontend-restrictions).

For `backend`, precedence works the same way but with more levels. For example, if a Gateway-level policy sets `backend.tcp` and `backend.tls`, and a Backend-level policy sets `backend.tls`, the effective policy uses `tcp` from the Gateway policy and `tls` from the Backend policy.

A `backend` policy that targets a Route overrides a `backend` policy that targets the Service or Backend that the route sends traffic to. For example, if a Route-level policy and a Backend-level policy both set `backend.transformation`, the effective policy uses the value from the Route policy.

> [!NOTE]
> A `backend` policy that targets a ListenerSet has no effect. The Kubernetes API server accepts the policy and the policy reports `Attached`, but agentgateway does not apply it to the backend. To apply a `backend` policy to every route on a ListenerSet listener, target the Gateway or each Route instead. Policies in the `traffic` section can target a ListenerSet.

### Equal specificity {#ties}

If multiple policies with the same specificity set the same field, the oldest policy wins, based on its Kubernetes `metadata.creationTimestamp`. If the timestamps are equal, agentgateway uses lexicographic order of the policy key to break the tie. The selection is stable across controller restarts.
Expand Down
Loading