# Policy fixture for the `security/policy-rate-limit.yaml` example integration
# test. The test rewrites the example's `config_path` to a copy of this file,
# with the key directory path pointed at `api-keys.yaml` beside it.
#
# Shape: an `identity/api-key` resolver, a pre-identity limiter keyed on the
# client address plus a coarse shared limit, and a post-identity limiter keyed
# on the resolved subject.

engine_settings:
  dispatch: policy

plugins:
  - name: api-keys
    kind: identity/api-key
    hooks: [identity.resolve]
    on_error: fail
    config:
      credential:
        kind: header
        name: Authorization
      prefix: "Bearer sk-test-"
      provider:
        kind: file
        path: /etc/praxis/api-keys.yaml
        index: sha256
      record_map:
        subject:
          id: user

  # Runs before the key is checked. Each IPv6 /64 is one address key, so the
  # rule without `variables` bounds what rotating addresses can reach. The
  # address limit leaves room for the harness's readiness probes.
  - name: edge-limits
    kind: ratelimit/limitador
    hooks: [ratelimit.pre_identity]
    capabilities: [read_headers]
    config:
      namespace: edge
      bindings:
        client: http.client_address
      limits:
        - max: 20
          seconds: 60
          variables: [client]
        - max: 1000
          seconds: 1

  # Runs after the key resolves, keyed on its subject.
  - name: per-user-limits
    kind: ratelimit/limitador
    hooks: [ratelimit.post_identity]
    capabilities: [read_subject, read_headers]
    config:
      namespace: per-user
      bindings:
        subject_id: subject.id
      limits:
        - max: 3
          seconds: 60
          variables: [subject_id]

global:
  authentication:
    - api-keys
  rate_limits:
    - edge-limits
    - per-user-limits
  authorization:
    pre_invocation:
      - "require(authenticated)"
