proxyfile
Generates a proxy's config from a short file. Envoy first.
What proxyfile is
A proxyfile is a short YAML file that describes one gateway: the services behind it, the routes to them, an optional
external auth check, and the browser origins it admits. 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.0.0/proxyfile-linux-amd64
curl -fsSLO https://github.com/kitecorp/proxyfile/releases/download/v1.0.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.0.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.0.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
| Command |
What it does |
render |
Reads the proxyfile, the origins file it names and, with --rpc-methods, the methods file. Writes the Envoy configuration to the -o path, and with --rpc-table the RPC table too. 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. --rpc-methods is required when the proxyfile has an - rpc: entry
and refused otherwise. --rpc-table needs --rpc-methods. An output path may not be the same file as an input or as
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. 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 and the methods file are reported together. For example, a misspelled listen gives:
gateway.yaml:3:1: "listen" is required here
gateway.yaml:3:1: unknown key "liste"; known here: admin, auth, limits, listen, log, namespace, origins, remove_from_clients, routes, services, timeouts
examples/full/gateway.yaml holds every key a proxyfile can have, with invented values. 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.
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-*]
origins: origins.json
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}
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".
A proxyfile file name ends in .yaml or .yml. 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. |
origins |
The origins file, relative to this file: the CORS settings and, for each environment, its hosts and the browser origins it admits. |
Required. A file name. See the next section. |
routes |
The routes, tried in the order written. The - rpc: entry marks where the RPC routes go. |
Required. A list, not empty. See "Route rules". |
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%. |
A proxyfile also has these rules, each reported with the file and line:
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.
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 of the origins file
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 is a place in the list. It holds one route for each method 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 --rpc-methods when it has one.
| 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.
The origins file and the methods file
Both are JSON files. They are read with the YAML reader, so a problem in either names its line and column.
The origins file
The proxyfile's origins key names it. A relative path is read from the proxyfile's directory, and an absolute path as
written.
{
"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 --rpc-methods flag names it. It is a list with one entry for each RPC method the gateway routes. Which service a
method goes to is decided by the - rpc: entry of the proxyfile, not by this file.
[
{"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 file 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.
- 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. Put this line first in a 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.0.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 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.