proxyfile

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0

README

proxyfile

Generates a proxy's config from a short file. Envoy first.

What proxyfile is

A proxyfile is a short file, written in YAML or in HOCON, that describes one gateway: the services behind it, the routes to them, an optional external auth check, the browser origins it admits and, for RPC routes, the methods. proxyfile render turns it into a complete Envoy configuration, written for Envoy 1.40. The same input always gives the same bytes, so you can commit the generated file and let proxyfile check fail a build when someone edits it by hand or forgets to render.

Install

Download the release file for your system, check it against the published checksum, and put it on your path. The release has proxyfile-linux-amd64, proxyfile-linux-arm64, proxyfile-darwin-amd64 and proxyfile-darwin-arm64, with checksums.txt and proxyfile.schema.json beside them.

curl -fsSLO https://github.com/kitecorp/proxyfile/releases/download/v1.2.0/proxyfile-linux-amd64
curl -fsSLO https://github.com/kitecorp/proxyfile/releases/download/v1.2.0/checksums.txt
shasum -a 256 -c --ignore-missing checksums.txt
install -m 0755 proxyfile-linux-amd64 /usr/local/bin/proxyfile

In a Dockerfile, copy the program out of the image. The image holds /proxyfile and nothing else.

COPY --from=ghcr.io/kitecorp/proxyfile:1.2.0 /proxyfile /usr/local/bin/proxyfile

With Go installed (the Go version go.mod names or newer):

go install github.com/kitecorp/proxyfile/cmd/proxyfile@v1.2.0

Commands

usage: proxyfile render [<file>] -o <envoy.yaml> [--rpc-methods <methods.json>] [--rpc-table <table.json>]
       proxyfile check [<file>] -o <envoy.yaml> [--rpc-methods <methods.json>] [--rpc-table <table.json>]
       proxyfile schema
       proxyfile version

With no file, proxyfile reads Proxyfile, proxyfile.conf, proxyfile.yaml or proxyfile.yml from the working directory, and exactly one of them must exist.

Command What it does
render Reads the proxyfile, the origins file when it names one and the RPC methods, which come from its rpc.methods or, with --rpc-methods, from the methods file, never both. Writes the Envoy configuration to the -o path, and with --rpc-table the RPC table too, which needs one of the two. It writes every output only when the whole input is free of problems.
check Renders in memory and compares the bytes with the files on disk. It writes nothing. A missing output file differs.
schema Prints the JSON Schema of the proxyfile format on standard output.
version Prints proxyfile <version>.

--help, -h and help print the usage text on standard output and exit with 0.

The flags may stand before or after the file. A proxyfile with an rpc entry (- rpc: in YAML, { rpc { ... } } in HOCON) takes its methods from rpc.methods or from --rpc-methods, never from both, and methods given with no rpc entry are refused. --rpc-table needs one of the two. An output path may not name the proxyfile, its origins file or its methods file, nor the other output.

The generated file starts with this line, and the same input always gives the same bytes:

# Generated by proxyfile. Do not edit: change the proxyfile beside it and run proxyfile render; proxyfile check fails on a hand edit.

Exit codes:

Code Meaning
0 The work is done, or the checked files match what render writes.
1 The input has problems and nothing is written, or a checked file differs (<path> differs from what proxyfile render writes), or a write fails.
2 A usage error. The message is printed with the usage text.

Each problem in the input is printed on standard error as <file>:<line>:<column>: <message>, as <file>:<line>: <message> when it has no column (a YAML syntax error names only its line), or as <file>: <message> when it is about the file as a whole, such as a file that cannot be read. A HOCON file gives a line and column only for a syntax error, and names every other problem by its key path instead, as <file>: <key path>: <message> (see "The HOCON form", which also says how a problem in an included file reads). The proxyfile is read first, and a run that finds problems in it reports all the problems of the first stage that finds any: reading and syntax, then the format of each key, then the rules that compare keys with each other. When the proxyfile is free of problems, the problems of the origins file, when origins names one, and of the methods are reported together. For example, a misspelled listen in a YAML file gives:

gateway.yaml:3:1: "listen" is required here
gateway.yaml:3:1: unknown key "liste"; known here: admin, auth, cors, limits, listen, log, namespace, origins, remove_from_clients, routes, rpc, services, timeouts, tracing

The format

examples/full/gateway.yaml holds every key a proxyfile can have except services.<name>.address and tracing, with invented values: cors, the origins by environment and rpc.methods are among them. examples/partial/gateway.yaml writes address and gives its methods the 1.0 way, with --rpc-methods examples/partial/methods.json, and its HOCON twin through include required("rpc-methods.conf"). examples/tracing/gateway.yaml writes tracing. Only listen, services, origins and routes are required. The rest is left out when you do not need it.

# yaml-language-server: $schema=../../schema/proxyfile.schema.json
# Every key a proxyfile can hold, with invented values, except tracing, which has its own example.
namespace: example.gateway
listen: 10000
admin: 9901
limits:
  heap: 256MiB
  connections: 4096
  request_headers: {size: 96KiB, count: 150}
timeouts:
  request: none
  idle: 90s
  upstream_idle: 45s
services:
  shop: {http: 8080, grpc: 8081}
  accounts: {grpc: 7070, http: 7070, host_header: "127.0.0.1:7070"}
auth:
  ask: accounts /auth/check
  timeout: 1500ms
  enabled: true
  when_unavailable: allow
  only_with_header: authorization
  send: [authorization, x-country]
  accept: [x-user-*, x-tier-*]
remove_from_clients: [x-user-*, x-client-*, x-tier-*, x-gateway-*]
cors:
  allow_methods: "*"
  allow_headers: "*"
  expose_headers: "Content-Disposition,X-Request-Id"
  max_age: "600"
origins:
  live:
    hosts: [api.example.com, api.example.org]
    origins: ["https://example.com", "https://www.example.com"]
    patterns: ["https://*.example.com"]
  test:
    hosts: [api.test.example.com]
    origins: ["http://localhost:3000", "https://test.example.com"]
    patterns: ["https://*.test.example.com"]
  local:
    hosts: [127.0.0.1, localhost]
    origins: []
    patterns: ["http://*.example.com:*", "http://localhost:*"]
routes:
  - {name: accounts-events, pattern: "^/events/[a-z0-9-]+$", to: accounts, auth: off}
  - rpc:
      retries: 1
      to:
        example.shop.*: {service: shop, name: shop}
        "*": accounts
  - {name: accounts-webhooks, path: /api/webhooks, method: POST, to: accounts, rewrite: /hooks/payments, auth: off}
  - {name: shop, prefix: /, to: shop, retries: 1}
rpc:
  methods:
    - {service: example.shop.v1.CartService, method: GetCart, action: browse}
    - {service: example.accounts.v1.ProfileService, method: GetProfile}
    - {service: example.shop.v1.CartService, method: AddItem, action: buy, reports: [browse]}
log: {status_from: 400, sample: 1%}

The first line points an editor at the schema in this repository. In your own files, use the URL under "Editors".

The examples in this section are YAML, whose file name ends in .yaml or .yml; "The HOCON form" gives the other names and the same keys in HOCON. An unknown key anywhere is a problem, and the message lists the keys that are known at that place.

Sizes are a whole number with KiB, MiB or GiB, such as 192MiB. Times are a whole number with ms, s, m or h, such as 125s, and at most 9223372035s (about 292 years), the largest whole number of seconds below the limit Envoy sets on a duration. auth.timeout has a lower limit, which its row gives. A percentage is a whole number from 0 to 100 with a %.

Keys
Key Meaning Rule
namespace The namespace of the gateway's own metadata, which the routes and the request log use. proxyfile when not written. Lower-case letters, digits, dots, - and _, starting with a letter.
listen The port of the public listener, on 0.0.0.0. Required. A port from 1 to 65535.
admin The port of the admin listener, on 127.0.0.1. It answers only /ready, /stats and /server_info. No admin listener when not written. A port from 1 to 65535, not the same as listen.
limits Limits on memory, connections and request headers. A mapping of the three keys below.
limits.heap The heap budget: the gateway shrinks its heap at 90% of it and refuses new requests at 98%. A size such as 192MiB.
limits.connections The most connections at once, from clients and to each service. A whole number from 1 to 4294967295.
limits.request_headers The largest header block and the most header fields a request may carry. A mapping with size and count, both required.
limits.request_headers.size The largest header block of a request. A size such as 96KiB, at most 8MiB.
limits.request_headers.count The most header fields in a request. A whole number from 1 to 4294967295.
timeouts How long a request, an idle request and an idle connection to a service may last. A mapping of the three keys below. Each is a time such as 125s, or none.
timeouts.request The longest a whole request may take. Without it a route has Envoy's default of 15 seconds, counted from the end of the request. none removes the limit. A time or none.
timeouts.idle The longest a request may go without sending or receiving data. A time or none.
timeouts.upstream_idle The longest a connection to a service is kept open with no request on it. Envoy's default is 1 hour. A time or none.
services The services behind the gateway, on the same host, by name. Required. A mapping from a service name to its settings. A name is lower-case letters, digits and -, starting with a letter. Each service has at least one port.
services.<name>.http The service's HTTP port, spoken as HTTP/1.1. A port from 1 to 65535.
services.<name>.grpc The service's gRPC port, spoken as HTTP/2 without TLS (h2c). A port from 1 to 65535.
services.<name>.host_header The Host header a request carries when a route sends it to this service. Without it a request keeps the client's Host. A host, with an optional port.
services.<name>.address The service's IP address. 127.0.0.1 when not written. An IP address, not a name: Envoy looks up no name for a static cluster.
auth The external check every request goes through before it reaches a service. Without auth there is no check. See "The auth check" below. A mapping of the keys below.
auth.ask The service and the path the gateway asks. Required. A service name, a space and a path, such as accounts /check. The service needs an http port.
auth.timeout How long the gateway waits for the answer. Required. A time such as 2s, at most 4294967295s. none is not accepted.
auth.enabled true runs the check on every request it applies to, false on none. Required. true or false.
auth.when_unavailable What happens to a request when the check cannot be asked: allow lets it through, deny refuses it. Required. allow or deny.
auth.only_with_header The check runs only on requests that carry this header. A request without it, or with it empty, goes through with no check. A lower-case header name.
auth.send The request headers the check is sent. A name ending in * is a prefix. A list of lower-case header names or prefixes ending in *.
auth.accept The headers of the check's answer that reach the service. A name ending in * is a prefix. The same form as send.
remove_from_clients Headers removed from every client request before routing and before any filter, so no route, filter or service sees a client's copy. A name ending in * is a prefix. A list of lower-case header names or prefixes ending in *. Envoy holds header names in lower case, so a name with a capital would never match.
cors The CORS settings every environment shares: allow_methods, allow_headers, expose_headers and max_age, each optional, with the rules of the origins section below. A mapping. Not written when origins names a file, which holds its own cors.
origins The browser origins each environment admits, by environment name: each environment is a key holding its hosts, origins and patterns. As in 1.0, it may instead name an origins file, relative to this file. Required. A mapping with at least one environment, or a file name. See the origins section below.
routes The routes, tried in the order written. The rpc entry (- rpc: in YAML, { rpc { ... } } in HOCON) marks where the RPC routes go. Required. A list, not empty. See "Route rules".
rpc The RPC methods the gateway routes, written here instead of in a methods file. A mapping with the one key methods. Not given together with --rpc-methods.
rpc.methods One entry for each RPC method, with the keys of the methods section below. Which service a method goes to is decided by the rpc entry of routes. Required in rpc. A list, which may be empty.
log Which requests the request log writes. Without log, every request is logged. A mapping with status_from and sample, both required.
log.status_from The lowest status that is always logged. A whole number from 100 to 599.
log.sample The share of the other requests that is logged. A whole percentage such as 1%.
tracing Trace segments for sampled requests, sent to AWS X-Ray. See "Tracing" below. A mapping; provider is required in it.

A proxyfile also has these rules, each reported with the file and where the problem is, a line in YAML and a key path in HOCON:

  • listen and admin are not the same port.
  • At least one service is declared, and each service has at least one port.
  • A route, auth.ask or an RPC mapping names a service that is declared and has a port of the protocol it needs: http for a route and for auth.ask, grpc for an RPC mapping.
  • auth: off on a route needs an auth key.
  • cors is not written when origins names a file, because the generator takes the CORS settings from that file and would ignore this key.
  • The RPC methods come from one place: rpc.methods or --rpc-methods, not both. They need an rpc entry in routes, and the rpc entry needs them.
Route rules

Each plain route is a mapping with these keys:

Key Meaning Rule
name The route's name. It appears in the request log. Required. Letters, digits, dots, - and _. Not used twice, and not rpc.
prefix Matches paths that start with this text. A path starting with /.
path Matches this path exactly. A path starting with /.
pattern Matches paths by this regular expression, in RE2 syntax. A regular expression that is not empty and compiles.
method Matches only requests with this HTTP method. An HTTP method in capitals, such as POST.
to The service the route goes to. Required. A declared service with an http port.
rewrite Replaces the matched prefix or path before the request goes to the service. A path starting with /. Not allowed with pattern.
auth off sends the route's requests to the service without the check. off. Needs an auth key.
retries How many times a request that never reached the service is tried again. A whole number from 0 to 4294967295.

How routes are matched:

  • The routes are tried in the order written, and the first that matches wins. Every environment gets the same list. Put a prefix: / route last, because it matches every path.
  • Write exactly one of prefix, path and pattern on each route.
  • Two routes with the same kind of match, the same text and the same method are a problem, because the later one is never reached.
  • A retry happens only when the request never reached the service (Envoy's connect-failure and reset-before-request conditions), so a request that the service saw is never sent twice.

The rpc entry (- rpc: in YAML, { rpc { ... } } in HOCON) is a place in the list. It holds one route for each method of rpc.methods or of the methods file, matched on the exact path a call carries, /<package>.<Service>/<Method>. Those routes are sorted by path and written where the entry stands, so a plain route written above the entry is tried before the RPC routes, and one written below it after them. A file has at most one rpc entry, and it needs methods: rpc.methods or --rpc-methods, never both.

Key Meaning Rule
retries How many times an RPC call that never reached its service is tried again. A whole number from 0 to 4294967295.
to The service the RPC methods of each package go to. Required, not empty. A mapping from a pattern to a service name, or to a mapping with service and an optional name.
to.<pattern> * matches every service. A package name ending in .* matches every service whose full name starts with that package and a dot. A full service name matches that service alone. The service needs a grpc port.
to.<pattern>.name The name of the routes. The service's name followed by -rpc when not written. Letters, digits, dots, - and _.

A method goes to the mapping with its exact service name if there is one. Otherwise it goes to the matching pattern with the longest text, and * is last. The order in which the patterns are written does not matter. A method that no pattern matches is a problem.

The auth check

With auth present, the gateway asks the service named by auth.ask about each request, in HTTP mode, so the auth service needs no Envoy-specific type.

  • The check gets a request to the path of ask, never the client's path or query, because paths can carry links and tokens. The headers it gets are the ones send names and the route's question below. HTTP mode adds the client's Host, the request's method, Authorization and Content-Length: 0, whatever send says.
  • Each RPC route adds its question to the check: x-gateway-action holds the method's action and x-gateway-reports its reports joined by commas. A plain route adds neither. The question is for the check alone, and no service sees it.
  • x-gateway-timeout-ms holds the deadline in milliseconds, the same as auth.timeout, so the auth service can keep its own calls inside it.
  • The service answers 200 to let the request through. The headers of the answer named by accept are set on the request to the service, replacing any value there. A 5xx counts as a failed call, which when_unavailable decides. Any other status is sent to the client as a denial.
  • With when_unavailable: allow, a request that could not be checked goes through with the header x-envoy-auth-failure-mode-allowed set, and the gateway writes a gateway_auth_unavailable log line for it. A client's own copy of that header is removed before anything reads it.
  • A check sent on a connection the auth service is closing fails. Set timeouts.upstream_idle under the auth service's own idle timeout, so the gateway closes an idle connection first.
Tracing

With tracing, the gateway takes part in an AWS X-Ray trace. It continues the trace that a request's x-amzn-trace-id names, or starts one. It sends a segment for each sampled request to an agent over UDP. It passes the trace on to the service in x-amzn-trace-id, with its own segment as the parent, and the auth check's request carries a subsegment of it.

tracing:
  provider:
    xray:
      agent: 127.0.0.1:2000
      segment: example-gateway
      sample:
        first: 1
        rate: 5%
        rules:
          # A WebSocket's segment would last as long as the socket, so the gateway samples no handshake by its own
          # rule.
          - {host: "*", method: "*", path: "/live*", first: 0, rate: 0%}
  tags:
    environment: {env: APP_ENVIRONMENT, default: local}
    request_id: {header: x-request-id}
  path_in_url: false

The same in HOCON:

tracing {
  provider {
    xray {
      agent = "127.0.0.1:2000"
      segment = example-gateway
      sample {
        first = 1
        rate = 5%
        // A WebSocket's segment would last as long as the socket, so the gateway samples no handshake by its own rule.
        rules = [
          { host = "*", method = "*", path = "/live*", first = 0, rate = 0% }
        ]
      }
    }
  }
  tags {
    environment { env = APP_ENVIRONMENT, default = local }
    request_id { header = x-request-id }
  }
  path_in_url = false
}

examples/tracing/ holds this gateway with auth and remove_from_clients added, in YAML and HOCON, and the envoy.yaml it generates.

In the table, xray stands for tracing.provider.xray.

Key Meaning Rule
tracing Trace segments for sampled requests. Optional. A mapping; provider is required in it.
tracing.provider The tracing system the segments go to: a mapping with one key that names it. 1.2 has one, xray. Required. A mapping whose one key is xray.
xray.agent Where the segments go over UDP: an X-Ray daemon, or an agent that takes X-Ray segments. An IPv4 address and a port from 1 to 65535, such as 127.0.0.1:2000. 127.0.0.1:2000 when not written.
xray.segment The name of the gateway's segments, which names its node in X-Ray's service map. Required. 1 to 200 characters: letters, digits, spaces and _ . : / % & # = + \ - @.
xray.sample Which requests are traced when the request does not say: the rules, then the default. A mapping of the keys below. Without it no manifest is written and Envoy's own rule applies, which is first: 1, rate: 5%.
xray.sample.first How many requests each second are traced before rate applies. A whole number from 0 to 4294967295. 1 when not written.
xray.sample.rate The share of the other requests that is traced. A whole percentage from 0% to 100%, the form of log.sample. 5% when not written.
xray.sample.rules Rules tried in the order written, before the default. The first that matches a request decides, with its own first and rate. A list of the mappings below; it may be empty.
xray.sample.rules[].host Matches the request's Host header, with its port when the request has one. A pattern of letters, digits, ., -, :, [, ], * and ?. * when not written.
xray.sample.rules[].method Matches the request's method. A method in capitals, or a pattern of capitals, * and ?. * when not written.
xray.sample.rules[].path Matches the request's path, with its query. A pattern of printable characters without spaces, starting with / or *. * when not written.
xray.sample.rules[].first, .rate As sample.first and sample.rate, for the requests the rule matches. Both required, in the same forms.
tracing.tags Annotations on each segment, by name. A mapping from a tag name (letters, digits and _) to a mapping with exactly one of env and header, and an optional default. Written order is kept, in both forms.
tracing.tags.<name>.env An environment variable of the gateway's process. A variable name: letters, digits and _, not starting with a digit.
tracing.tags.<name>.header A request header. A lower-case header name, the rule of auth.only_with_header.
tracing.tags.<name>.default The value when the variable is unset or the header is absent. Without it the segment gets no tag then. Text, not empty.
tracing.path_in_url Whether the segment's URL keeps the request's path. true or false. false when not written.

Envoy traces a request when a whole number it draws from 0 to 99 is below 100 times the rate, computed in floating point. 100 times 0.07, 0.14, 0.28, 0.55 and 0.56 comes out a little above the whole number. So rate: 7%, 14%, 28%, 55% and 56% trace 8%, 15%, 29%, 56% and 57% of the requests they apply to. Every other whole percentage is exact.

In host, method and path, * matches any run of characters and ? one character. Case does not matter, and the pattern must match the whole value. Each is * when not written. A request whose x-amzn-trace-id says Sampled=1 is traced and one that says Sampled=0 is not, whatever the rules say. Only the other requests are asked of the rules. So a client can have every request it sends traced, and X-Ray bills for each trace recorded.

path_in_url is false by default, for the reason the request log holds no path: paths can carry links and tokens. A segment still holds the URL's scheme and host, the method and the user agent. As client_ip it holds the whole X-Forwarded-For header as it came, or the connection's address when there is none. It holds the status and the response size. For a request whose content type is application/grpc or application/grpc+<x>, it holds the whole path in the grpc.path annotation, and no setting removes that. With path_in_url: true the URL keeps the first 256 characters of the path, query included. An environment tag is read by Envoy once, when it starts, never by proxyfile, so the same proxyfile gives the same bytes on every machine. A tag name is letters, digits and _, because X-Ray filter expressions take only those annotation keys. A tag with the name of a tag Envoy sets on every segment itself is dropped: Envoy sets its own tags before the custom tags, and the X-Ray tracer keeps the first value of a name. A tag named error whose value is true marks the segment as a fault. proxyfile keeps no list of Envoy's tag names.

What is written with the key:

  • The provider's fixed parts: envoy.tracers.xray and UDP.
  • The request id extension with pack_trace_reason: false, so x-request-id stays as the client sent it or Envoy generated it.
  • x-envoy-downstream-service-cluster and x-envoy-downstream-service-node, removed from clients after every other early removal, each unless an entry before it covers it: a remove_from_clients entry or an auth.accept name, the rule the question headers follow. Envoy strips them only from an edge request, and with use_remote_address: false (see "Defaults") no request is one.
  • None of Envoy's own sampling shares, so the rules decide.

With no agent listening, a segment is dropped and the request is served as before. Without the key, none of this is written, and a 1.1 proxyfile gives 1.1's file byte for byte.

In HOCON, the agent is quoted, agent = "127.0.0.1:2000", because of its colon (see "Quote what HOCON would read differently"). rate = 5% needs no quotes and is text, while rate = 5 is a number and is refused.

The HOCON form

The same gateway can be written in HOCON (Human-Optimized Config Object Notation, as the Lightbend specification defines it). Every key has the same name, meaning and rules as in the YAML form, and the generated file is the same, byte for byte.

A proxyfile's file name decides its form, never its content. A file named Proxyfile, with a capital P, or a name ending in .conf is HOCON, a name ending in .yaml or .yml is YAML, and any other name is refused.

# The smallest proxyfile, in HOCON: one service, one route, and the browser origins it admits.
listen = 8000
services {
  app { http = 3000 }
}
origins {
  all { hosts = [localhost], origins = ["http://localhost:3000"] }
}
routes = [
  { name = app, prefix = /, to = app }
]

examples/full/gateway.conf writes every key but services.<name>.address and tracing and sits beside examples/full/gateway.yaml, which gives the same file. examples/tracing/gateway.conf writes tracing and sits beside its YAML twin, examples/tracing/gateway.yaml. examples/partial/gateway.conf pulls its methods in with include required("rpc-methods.conf"): a plain include is skipped when the file is missing, and required refuses it by name.

The rules of the form:

  • Routes are an array. routes = [ ... ] lists the routes in the order they are tried, and the rpc entry is the item { rpc { ... } }, where YAML writes - rpc:. It is an array, not an object, because the first route that matches wins and HOCON does not require a reader to keep the order of an object's keys.
  • Quote what HOCON would read differently. Quote a key that holds . or *, as in "example.shop.*" = shop and "*" = web: an unquoted dotted key is a path (a.b = 1 means a { b = 1 }), and * is a syntax error outside quotes. Quote any value that holds anything but letters, digits, spaces and ., -, _, / and % (a substitution, below, is the one exception). HOCON refuses most other characters outside quotes, such as *, :, $, ^, +, ?, = and [, with a syntax error that does not say to quote, except the one for +, which says outside quotes. HOCON starts a comment at # and at //, so rewrite = /a#b is read as /a, and proxyfile cannot see the cut.
  • A string is text, and a number or a boolean is not. So max_age = "600", which needs text, and listen = 8000, which needs a number. A word written without quotes, such as allow, is a string. A quoted number where a number belongs, and a plain number where text belongs, are both refused.
  • A key written twice keeps the later value. Two objects under one key merge, and an array written twice keeps the later array: a second routes = [ ... ] replaces the first. Two routes with the same name are a problem in both forms. The YAML form refuses a key written twice. HOCON merges a service or an environment written twice and does not report it.
  • Includes are relative to the file that holds them, not to the working directory. A relative name may climb out of that directory, as include "../shared/origins.conf" does, and an absolute name is read as written, both as HOCON defines. include "other.conf" skips a file that is missing, as HOCON defines, and include required("other.conf") refuses it by name. Use required for a file the gateway cannot do without. The one exception to the first rule is a name inside file(...), as in include file("other.conf"), which HOCON does not read relative to the including file: proxyfile reads it relative to the working directory, so write include "other.conf" instead.
  • Substitutions read the files, never the environment. ${name} takes another key of the same file or of its includes. It never reads an environment variable, so the same files give the same bytes on every machine, and listen = ${HOME} is a problem. The key a substitution reads is a key of the format like any other, so a substitution copies one proxyfile value into another, such as accept = ${auth.send}. A key of your own, such as port = 3000 for http = ${port}, is refused as an unknown key: gateway.conf: port: unknown key "port"; known here: admin, auth, cors, ....
  • The order you write is kept. The generated file lists the services, their ports and the environments as written. When an object is written twice, the merged object lists the keys of the later one first.
  • An empty file is an empty object, so the problems name each required key.

What a problem looks like:

  • A syntax error is <file>:<line>:<column>: <message>, with a column, which a YAML syntax error does not have, for example gateway.conf:3:1: unexpected EOF, expected '}'.
  • Any later problem is <file>: <key path>: <message>, because the HOCON reader keeps no line for a value, for example gateway.conf: services.app.http: "http" must be a whole number from 1 to 65535, not quoted or block text. The key path joins the keys from the top with dots (services.app.http), writes an array item as its index from 0 in square brackets (routes[1].to), and quotes a key that holds anything but letters, digits, - and _ (routes[1].rpc.to."example.shop.*"). A problem at the top of the file, such as a missing required key, has no key path: gateway.conf: "listen" is required here.
  • A message that names another place says at <key path> where the YAML form says on line 7, for example gateway.conf: routes[1].name: route "app" is declared twice (the first is at routes[0].name).
  • A file that cannot be read is <file>: the file cannot be read: <reason>, the same text in both forms. An included file is the exception, below.
  • A problem inside an included file is reported against the file you gave. A syntax error there reads <file>: parse error at line <n>, col <m>: <message>, for example gateway.conf: parse error at line 3, col 1: unexpected EOF, expected '}'. It has no :<line>:<column>: after the file, and the line and column are the included file's, because the HOCON library does not say which file it was. A later problem names the key path the included file wrote, for example gateway.conf: rpc.methods[0]: the report "x,y" of a.v1.S/M contains a comma, the separator of x-gateway-reports. A missing include required(...) reads <included file>: cannot read include file: <reason>.
  • The ending , not quoted or block text follows a message about a whole number or true or false that was written as text. It is the YAML form's wording; in HOCON it means a string, and an unquoted word is one too, so http = abc gets it.

Editors. IntelliJ's HOCON plugin recognises .conf files. A Proxyfile has no extension, so map it to the HOCON file type under Settings, Editor, File Types.

The origins file and the methods file

Since 1.1 both can be written in the proxyfile: the environments under origins, the CORS settings under cors, and the methods under rpc.methods. A HOCON proxyfile that wants a separate file uses include, as examples/partial/gateway.conf does for its methods. The 1.0 way stays accepted in every 1.x release, with the same rules: origins: <file> names a JSON origins file, and --rpc-methods <file> a JSON methods file. rpc.methods and --rpc-methods together are refused, and so is cors in the proxyfile when origins names a file.

The two files are JSON. They are read with the YAML reader, so a problem in either names its line and column.

The origins file

When origins names a file, a relative path is read from the proxyfile's directory, and an absolute path as written. Written in the proxyfile, origins is instead a mapping from each environment's name to its hosts, origins and patterns, and cors is a key of its own beside it, as examples/full/gateway.yaml above shows. Every key and rule below holds in both places, with two differences. The file writes an environment's name as name, and the proxyfile as the key. A HOCON proxyfile merges an environment written twice, where the file and the YAML form report it. An origins file looks like this:

{
  "cors": {
    "allow_methods": "*",
    "allow_headers": "*",
    "expose_headers": "Content-Disposition,X-Request-Id",
    "max_age": "600"
  },
  "environments": [
    {
      "name": "live",
      "hosts": ["api.example.com", "api.example.org"],
      "origins": ["https://example.com", "https://www.example.com"],
      "patterns": ["https://*.example.com"]
    },
    {
      "name": "test",
      "hosts": ["api.test.example.com"],
      "origins": ["http://localhost:3000", "https://test.example.com"],
      "patterns": ["https://*.test.example.com"]
    },
    {
      "name": "local",
      "hosts": ["127.0.0.1", "localhost"],
      "origins": [],
      "patterns": ["http://*.example.com:*", "http://localhost:*"]
    }
  ]
}
Key Meaning Rule
cors The CORS settings every environment shares. Optional, like every key in it.
cors.allow_methods The value of Access-Control-Allow-Methods. Text.
cors.allow_headers The value of Access-Control-Allow-Headers. Text.
cors.expose_headers The value of Access-Control-Expose-Headers. Text.
cors.max_age The value of Access-Control-Max-Age: how long a browser may keep a preflight answer. A number of seconds, as text.
environments The environments, each with its hosts and the browser origins it admits. Required. A list with at least one environment.
environments[].name The environment's name. It names the environment's virtual host. Required. Not empty, and not used by another environment.
environments[].hosts The host names the environment serves, without a port. Required, not empty. Lower-case host names, such as api.example.com. No host is in two environments.
environments[].origins The browser origins admitted exactly, each scheme://host[:port]. Lower case, http or https, no path.
environments[].patterns The browser origins admitted by pattern, where * matches any run of characters, dots included. scheme://host[:port] with at least one *.

Each list is sorted in byte order and holds no value twice, so adding or removing a value changes one line.

Each environment becomes one virtual host. It serves the environment's hosts, and the port in the Host header plays no part, so a local setup may reach the gateway on any port. A browser request is admitted when:

  • it carries no Origin header, or
  • its Origin is one of the environment's own hosts, on either scheme and any port, or
  • its Origin is in the environment's origins or matches one of its patterns.

Any other browser origin is refused with 403, preflights, requests and WebSocket upgrades alike, before CORS, the auth check or any service sees it. For an admitted origin the gateway answers every preflight itself, so none reaches a service or the check. On every other answer it sets Access-Control-Allow-Origin, and Access-Control-Expose-Headers when expose_headers is written, replacing any the service sent. The max_age lets a browser keep an admitted preflight, so an origin removed from the file may keep working that long in a browser that cached its preflight.

The methods file

The methods are a list with one entry for each RPC method the gateway routes. They are the proxyfile's rpc.methods or, the 1.0 way, a JSON file that the --rpc-methods flag names. Which service a method goes to is decided by the rpc entry of routes, not by this list. This is a methods file; written as rpc.methods, it is the same list.

[
  {"service": "example.shop.v1.CartService", "method": "GetCart", "action": "browse"},
  {"service": "example.accounts.v1.ProfileService", "method": "GetProfile"},
  {"service": "example.shop.v1.CartService", "method": "AddItem", "action": "buy", "reports": ["browse"]}
]
Key Meaning Rule
service The full name of the method's service. Required. A full service name such as shop.v1.CartService.
method The method's name. Required. A name such as AddItem.
action The action the check is told for this method, in x-gateway-action. Text. Empty when not written.
reports The reports the check is told for this method, in x-gateway-reports. A list of text. No report contains a comma, because the list is sent as one value joined by commas.

A method listed twice is a problem.

The RPC table

--rpc-table writes the routes as JSON for other programs to read, for example one that answers the check. It is a JSON array with one object per line, sorted by path, and it ends with a newline. Each object has service, method, action (empty when not written), reports (empty when not written) and cluster, the cluster the call goes to. With no methods the table is []. This is the table of the methods above:

[
  {"service": "example.accounts.v1.ProfileService", "method": "GetProfile", "action": "", "reports": [], "cluster": "accounts_grpc"},
  {"service": "example.shop.v1.CartService", "method": "AddItem", "action": "buy", "reports": ["browse"], "cluster": "shop_grpc"},
  {"service": "example.shop.v1.CartService", "method": "GetCart", "action": "browse", "reports": [], "cluster": "shop_grpc"}
]

Defaults

Everything the format has no key for is the same in every gateway proxyfile writes.

  • One public listener on 0.0.0.0, so a container runtime can publish the port. Who may reach it is the network's rule, not the gateway's. Each service gets one cluster for each port it declares, named <service>_http and <service>_grpc, with no TLS to the service.
  • A proxy stands in front of the gateway (use_remote_address: false). X-Forwarded-For passes as it came, and X-Forwarded-Proto is kept when present. With no trusted hops, Envoy takes the last X-Forwarded-For entry, the one the proxy in front appended, as the client's address. A gateway that faces the internet directly needs a key that does not exist yet.
  • A browser origin that is not admitted gets 403 with the body Invalid CORS request, the answer a Spring service gives for a refused origin. Changing it needs a key that does not exist yet.
  • Every response carries x-request-id, the client's own when it sent one, so a caller can quote the id of a failed call. It is the request_id of the request log.
  • The service's own Server header passes through, and Envoy adds none of its own. The router adds no x-envoy-* header to a request or a response.
  • Vary: Origin on every response, added to a Vary the service sent, never replacing it.
  • No path rewriting. Envoy neither normalizes a path nor merges slashes, so the service's own path rules decide what a path means.
  • WebSocket is the one upgrade passed on. Envoy answers any other Upgrade to a route with 403 and an empty body.
  • A service that cannot be reached answers 502 with an empty body, where Envoy's own answer is a 503 or a 502 with a body that describes the failure.
  • Headers are removed early. Everything in remove_from_clients, and with auth the header x-envoy-auth-failure-mode-allowed, is removed before routing and before any filter. With auth, the gateway also removes from clients the two question headers and every header the check may set (each name of auth.accept), whether or not remove_from_clients lists them, because a client must not be able to forge what the gateway asks the check or what the check says. With tracing, x-envoy-downstream-service-cluster and x-envoy-downstream-service-node are removed last, each unless an entry before it covers it.
  • Retries happen only on connect-failure and reset-before-request.
  • The overload manager checks every 0.25 seconds. It exists when limits.heap or limits.connections is written.
  • The Connect bridge. Each route of the rpc entry turns a Connect call into gRPC for the service's gRPC port, and the answer back into Connect. Envoy's bridge still writes the HTTP status of an older Connect error-code table for four codes, so a small Lua filter sets the current status: canceled 499, deadline_exceeded 504, failed_precondition 400 and unimplemented 501. Both filters are off for every other route.
  • Route metadata. With auth, a plain route carries an empty action under namespace, and an RPC route carries its method's action. A route with auth: off carries none. The auth-unavailable log line reads it.
  • Three kinds of JSON log line on standard output. The request log has the fields time, route, host, method, protocol, status, flags, details, duration_ms, upstream_ms, bytes_in, bytes_out, upstream and request_id, and with auth also authz_us, how long the check took (null when none ran). The upstream failure line (event: gateway_upstream_failure) is written for each request an upstream failed. The auth-unavailable line (event: gateway_auth_unavailable) is written with auth only. No log line holds a path, query, address, user agent or referrer, because paths can carry links and tokens. With log, the request log writes every response at or above status_from, every response with a response flag, and sample of the rest, chosen by the first eight hex digits of x-request-id.
  • The order of the filters: set metadata (with auth), header mutation, the RBAC refusal of a foreign browser origin, CORS, the auth check (with auth), the Lua status filter and the Connect bridge (with an rpc entry), and the router. A foreign origin is refused before the check could be called.
Fixed names

These names never follow namespace or any other key, because other programs read them. A tool that changes a runtime value, for example, looks it up by its key.

Name What it is
public The listener, its stat_prefix and the route table.
gateway.ext_authz.enabled The runtime key that switches the auth check, written with auth. Its default comes from auth.enabled.
gateway.request_log.min_status The runtime key for the lowest status that is always logged, written with log. Its default comes from log.status_from.
gateway.request_log.sample The runtime key for the share of other requests that is logged, written with log. Its default comes from log.sample.
gateway.local_reply.origin_refused_status The runtime key for the status the Invalid CORS request answer is matched on. Its default is 403.
browser-origins The one RBAC policy of each virtual host.
x-gateway-action, x-gateway-reports The question headers of an RPC route, read by the auth check.
x-gateway-timeout-ms The check's deadline in milliseconds.

One line of the generated file is meant for a tool to switch by editing the file as text: the default of the auth check. It stays on one line in flow style for that purpose. It reads {numerator: 100, denominator: HUNDRED} when the check is on and {numerator: 0, denominator: HUNDRED} when it is off:

default_value: {numerator: 100, denominator: HUNDRED}

proxyfile check fails on an edited file, as it does on any edit, so check the file before a tool edits it. To change the setting for good, change auth.enabled and render again.

Editors

The JSON Schema of the format gives completion and checking as you type. The schema describes the YAML form only. For a HOCON proxyfile, see the editor note under "The HOCON form". Put this line first in a YAML proxyfile, for editors that use the YAML language server, such as VS Code with the YAML extension:

# yaml-language-server: $schema=https://raw.githubusercontent.com/kitecorp/proxyfile/v1.2.0/schema/proxyfile.schema.json

In a JetBrains IDE, open Settings, Languages & Frameworks, Schemas and DTDs, JSON Schema Mappings. Add a mapping with the schema URL above and a file pattern that matches your YAML proxyfiles, such as gateway.yaml.

proxyfile schema prints the same schema, and each release carries it as proxyfile.schema.json.

Licence

Apache-2.0. See LICENSE.

Directories

Path Synopsis
cmd
proxyfile command
Command proxyfile writes an Envoy configuration from a proxyfile.
Command proxyfile writes an Envoy configuration from a proxyfile.
internal
cli
Package cli is the proxyfile program: its commands, flags, messages and exit codes.
Package cli is the proxyfile program: its commands, flags, messages and exit codes.
envoy
Package envoy writes the Envoy configuration of a gateway: it fills the embedded fragments, splices them into one YAML tree and encodes that tree.
Package envoy writes the Envoy configuration of a gateway: it fills the embedded fragments, splices them into one YAML tree and encodes that tree.
format
Package format holds the one description of each input file and checks a file's tree against it.
Package format holds the one description of each input file and checks a file's tree against it.
input
Package input holds the reading step the readers of the input files share: reading a file as far as a tree its description accepts.
Package input holds the reading step the readers of the input files share: reading a file as far as a tree its description accepts.
origins
Package origins reads the browser origins: the CORS settings every environment shares and, for each environment, its hosts and the browser origins it admits.
Package origins reads the browser origins: the CORS settings every environment shares and, for each environment, its hosts and the browser origins it admits.
quote
Package quote writes text as a JSON string, the form the RPC table and the generated Envoy file both carry.
Package quote writes text as a JSON string, the form the RPC table and the generated Envoy file both carry.
read
Package read turns a proxyfile into the model, or into the problems that stop the run.
Package read turns a proxyfile into the model, or into the problems that stop the run.
render
Package render reads every input of one run and returns every output, in memory, so a caller writes nothing when any input has a problem.
Package render reads every input of one run and returns every output, in memory, so a caller writes nothing when any input has a problem.
rpc
Package rpc reads the RPC methods, from the proxyfile's rpc.methods or from a methods file, gives each method the service the proxyfile's rpc entry maps it to, and writes the RPC table: the routes as JSON, one object per line.
Package rpc reads the RPC methods, from the proxyfile's rpc.methods or from a methods file, gives each method the service the proxyfile's rpc entry maps it to, and writes the RPC table: the routes as JSON, one object per line.
testsupport
Package testsupport holds the helpers the tests of several packages share.
Package testsupport holds the helpers the tests of several packages share.
tree
Package tree is the boundary between a file's syntax and everything that reads it.
Package tree is the boundary between a file's syntax and everything that reads it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL