# Intelligent Route: Projected Credential Mount
#
# Starts with an empty credential table and injects a provider credential
# that is resolved on demand from a projected Kubernetes Secret mount.
#
# This is the "no-route startup" path: the proxy can come up before any route
# that needs a credential exists. `intelligent_route` later selects a candidate
# whose `credential.secretRef` names a Secret that was NOT present in the
# `credential_inject` startup table. Because `projected_credential_mount_base`
# is configured, the filter resolves the selected reference from
# `{base}/{namespace}/{name}/{key}` on demand and injects it. Including the
# namespace keeps same-name Secrets in different namespaces distinct.
#
# The mount is read live with a short (250 ms) cache, so a Secret rotated or
# newly mounted after startup is picked up without a pod or config reload. An
# absent, unsafe, or invalid projected file fails closed with HTTP 503: a
# selected credential-bearing route is never forwarded without injection.
#
# DANGER: overlay digest and scope validation do NOT authenticate the
# publisher. Use this mode only with a trusted routing-overlay publisher, mount
# only Secrets this gateway is authorized to inject, and keep the mount
# read-only to untrusted processes.
#
# Usage:
#   cargo run -p praxis-ai-proxy -- \
#     -c examples/configs/intelligent-route-projected-credentials.yaml

listeners:
  - name: proxy
    address: "0.0.0.0:8080"
    filter_chains:
      - main

filter_chains:
  - name: main
    filters:
      # Promote the JSON body's `model` field into X-Model and strip any
      # client-supplied X-Model so the routed model cannot be spoofed.
      - filter: model_to_header
        header: X-Model

      # Route to the cluster that serves the requested model and attach the
      # final-hop credential reference the downstream filter must inject.
      - filter: intelligent_route
        local_site: site-a
        model_header: X-Model
        candidates:
          - kind: inference_model
            name: granite-3.3-8b
            site: site-a
            cluster: granite-local
            fresh: true
            credential:
              strategy: bearer_token
              secretRef:
                name: granite-provider
                namespace: grid-demo
                key: token

      # Inject the selected credential. The startup table is empty: every
      # credential is resolved on demand from the projected Secret mount.
      - filter: credential_inject
        credentials: []
        projected_credential_mount_base: /run/secrets/projected-credentials

      # Forward to whichever cluster intelligent_route selected.
      - filter: load_balancer
        clusters:
          - name: granite-local
            endpoints:
              - "127.0.0.1:8001"

admin:
  address: "127.0.0.1:9901"
shutdown_timeout_secs: 5

insecure_options:
  allow_private_endpoints: true # example proxies to local backends
