Copilot 326e04d191
Add PreRouting phase support for authentication policies (#934)
JWT, BasicAuthentication, and APIKeyAuthentication policies were
ignoring the `phase` parameter. The data plane already supports these at
gateway level, but the control plane wasn't threading the phase
information through.

## Changes

- **Validation rule**: Updated to allow `jwtAuthentication`,
`basicAuthentication`, and `apiKeyAuthentication` in PreRouting phase
alongside existing policies (extAuth, transformation, extProc)

- **Policy processing**: Added `policyPhase` parameter to
`processJWTAuthenticationPolicy`, `processBasicAuthenticationPolicy`,
and `processAPIKeyAuthenticationPolicy` functions. Each now calls
`phase(policyPhase)` when building the TrafficPolicySpec.

- **Translation layer**: Updated `translateTrafficPolicyToAgw` to pass
`traffic.Phase` to all three authentication policy processors.

## Example

```yaml
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
spec:
  targetRefs:
  - kind: Gateway
    name: my-gateway
  traffic:
    phase: PreRouting  # Now respected by auth policies
    jwtAuthentication:
      mode: Strict
      providers: [...]
```

The phase now correctly propagates: `PreRouting` → `GATEWAY` in the
proto output.

> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `cgr.dev`
> - Triggering command: `/usr/libexec/docker/cli-plugins/docker-buildx
/usr/libexec/docker/cli-plugins/docker-buildx buildx build --build-arg
VERSION=eaeb1fb-dirty --build-arg
GIT_REVISION=eaeb1fb553685bc5442de8bf8b2e08149edd4993 -t
ghcr.io/agentgateway/agentgateway:eaeb1fb-dirty . --progress=plain
0.1-go1.25.1.lin/tmp/cc60Bcwp.o -ato -bool t
rg/toolchain@v0.0.1-go1.25.1.linux-amd64/pkg/tool/linux_amd64/compile
-errorsas -ifaceassert t
rg/toolchain@v0.0.1-go1.25.1.lin/tmp/ccQMzFBl.o` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/agentgateway/agentgateway/settings/copilot/coding_agent)
(admins only)
>
> </details>

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Some pre routing policies are missing control plane
support</issue_title>
> <issue_description>in the traffic policies implementation, we ignore
the phase for some policies. We need this for any that support being pre
routing. I know jwt has this issue but there may be some others
too</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes agentgateway/agentgateway#933

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/agentgateway/agentgateway/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: howardjohn <623453+howardjohn@users.noreply.github.com>
2026-02-11 06:58:07 -08:00

7 lines
513 B
Plaintext

github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=