# Policy Security Filter
#
# Embeds the Praxis Policy Engine in-process to enforce multi-source
# identity, APL route policy, RFC 8693 OAuth 2.0 token exchange, field
# redaction, session taint, audit emission, and (under
# `body_access: read_write`) request / response body rewriting.
#
# The policy filter consumes `mcp.method` / `mcp.name` metadata from
# an upstream protocol classifier filter (available in the `praxis-ai` package), which
# MUST be ordered before it in the chain.
#
# `config_path` points at the policy document (plugins + routes) that
# the filter loads once at construction. It is operator-supplied, not
# shipped here: a real policy carries your own issuers, secrets, routes,
# PDPs, and delegators. See the praxis-demos repo
# (`demos/cpex/policy.yaml`) for a fully-featured policy, and
# `tests/integration/fixtures/policy.yaml` for the minimal
# single-HS256-identity-plugin policy the integration test loads.
#
# `require_protocol_metadata: true` (the default) fail-closes when the
# protocol classifier filter is missing or ordered after `policy` — this guards
# against a misconfigured chain silently bypassing policy.
#
# Usage:
#   cargo run -p praxis-proxy -- \
#     -c examples/configs/security/policy.yaml
#
# Exercise (assumes the backend at :3000 echoes 200):
#
#   # Missing Authorization → 401 with WWW-Authenticate and
#   # X-Policy-Violation header:
#   curl -i -X POST http://localhost:8080/rpc \
#     -H "Content-Type: application/json" \
#     -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
#          "params":{"name":"echo","arguments":{}}}'
#
#   # Token rejected by HS256 signature mismatch → 401:
#   curl -i -X POST http://localhost:8080/rpc \
#     -H "Authorization: Bearer bogus.token.bytes" \
#     -H "Content-Type: application/json" \
#     -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
#          "params":{"name":"echo","arguments":{}}}'
#
# Supply your own policy document at `config_path` before running this
# example; the minimal test fixture uses a placeholder shared secret
# that must not be used beyond local experimentation.

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

filter_chains:
  - name: main
    filters:
      # A protocol classifier filter (from praxis-ai) must precede `policy` in the
      # chain to stash mcp.method / mcp.name in filter_metadata.
      # See the praxis-ai documentation for setup instructions.

      - filter: policy
        config_path: /etc/praxis/policy.yaml
        # Fail-closed when mcp.method metadata is missing. Set to
        # `false` only when intentionally fronting non-classified traffic
        # through the policy filter for identity-only enforcement.
        require_protocol_metadata: true

      - 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
