# Query-parameter API key authentication
#
# Authenticates requests whose API key arrives in the query string, as
# WebSocket and SSE clients that cannot set headers send it. The `policy`
# filter loads a policy whose `identity/api-key` resolver reads
# `?api_key=<key>`; a missing, unknown or repeated key is rejected with
# HTTP 401.
#
# The filter does not rewrite the URL, so the key reaches the upstream, and
# access logs, CDN logs and browser history can record it. Prefer a header
# credential where the client can send one. A policy that reads a query
# credential cannot also delegate. Keep `policy` ahead of `path_rewrite`,
# `url_rewrite` and header-rewriting filters so it authorizes the request
# the client sent.
#
# Usage:
#   cargo run -p praxis-proxy -- -c examples/configs/security/policy-query-credential.yaml
#   curl "http://localhost:8080/events?api_key=sk-test-alice"

listeners:
  - name: default
    address: "127.0.0.1:8080"
    filter_chains:
      - main

filter_chains:
  - name: main
    filters:
      # `config_path` points at the policy document. Its resolver declares
      # `credential: { kind: query_param, name: api_key }` and the
      # `read_query` capability the query credential needs.
      - filter: policy
        config_path: /etc/praxis/query-credential-policy.yaml

      - filter: router
        routes:
          - path_prefix: "/"
            cluster: backend

      - filter: load_balancer
        clusters:
          - name: backend
            endpoints:
              - "127.0.0.1:3000"

insecure_options:
  allow_private_endpoints: true # example proxies to local backends
