Configuration file
The gateway reads a single YAML file, given with --gConfigPath (or GATEWAY_CONFIG_PATH). Keys are case sensitive and unknown keys are rejected, so a typo is reported instead of silently ignored. Run nocleye check to validate a file.
Structure
Section titled “Structure”ApiVersion: v1Beta # required
AuthMethods: {} # how tokens are validated (optional)
ExternalDependencies: {} # connections to outside systems, e.g. a Redis for shared limits (optional)
Rules: # reusable rules, defined once, referenced by name HeaderRules: {} ClientIDRules: {} UsageControlRules: {} AccessLogRules: {}
GlobalConfig: {} # default rules for every server and route (optional)
ServerConfigs: {} # backend services (at least one required)
ServerRoutes: {} # public paths mapped to servers (at least one required)| Key | Required | Description |
|---|---|---|
ApiVersion |
yes | Version of the config format. The only supported value is v1Beta. |
AuthMethods |
no | Named authentication methods. See Authentication. |
ExternalDependencies |
no | Named connections to outside systems, referenced by rules. See sharing limits between instances. |
Rules |
no | Named, reusable rules. See header rules, client ID rules, usage control and access log rules. |
GlobalConfig |
no | Rules and authentication applied to everything by default. |
ServerConfigs |
yes | Backend services, by name. See Servers and routes. |
ServerRoutes |
yes | Routes, by name. See Servers and routes. |
Referencing rules
Section titled “Referencing rules”A rule is defined once under Rules and then referenced by its name. GlobalConfig, every server and every route accept the same set of keys:
| Key | Value | Description |
|---|---|---|
HeaderRule |
rule name | Header rule to use. |
ClientIDRule |
rule name | Client ID rule to use. |
UsageControlRules |
list of rule names | Usage control rules to apply. Several can be bound at once. |
AccessLogRule |
rule name | Access log rule that decides which requests are logged. |
AuthMethod |
method name | Authentication method to use. |
RequiredScopes |
list of scopes | Scopes the caller’s token must hold. See Authentication. |
Servers and routes also accept UsageControlMode (see usage control) and ScopesMode (see Authentication).
Referring to a name that does not exist is an error.
Which scope is used
Section titled “Which scope is used”| What | Resolution |
|---|---|
HeaderRule, ClientIDRule, AccessLogRule, AuthMethod |
The closest scope wins: the route’s value, otherwise the server’s, otherwise GlobalConfig’s. Only one is used. |
UsageControlRules |
Rules from several scopes can apply at once. See usage control. |
RequiredScopes |
By default the scopes of all three levels are required together. ScopesMode: Override makes the closest level win. See Authentication. |
When no header rule applies, all request headers are forwarded. There is no default client ID rule: routes without an authentication method or a client ID rule have unidentified callers and can’t be rate limited (see client ID rules).
Complete example
Section titled “Complete example”ApiVersion: v1Beta
AuthMethods: secure-hs256-bearer: Mode: Bearer SigningMethod: HS256 KeyRef: "file:hs256.key" IdClaimName: sub
secure-hs512-raw: Mode: RawHeader SigningMethod: HS512 HeaderName: X-Auth-Token KeyRef: "env:HS512_SECRET" IdClaimName: sub
Rules: HeaderRules: allowlist-headers: Mode: Custom CustomHeadersList: [X-Request-Id, X-Trace-Id] strip-and-set: Mode: All Remove: [X-Internal] Set: X-Source: gateway preserve-host: Mode: All PreserveHost: true
ClientIDRules: client-id-header: Modes: [CustomHeader] HeaderCustomValue: "X-Customer-Id" token-or-ip: Modes: [BearerToken, IP] by-ip: Modes: [IP]
UsageControlRules: global-limit: RequestCount: 1000 WindowTime: 1m limit-a-low: RequestCount: 20 WindowTime: 1m limit-b-server: RequestCount: 50 WindowTime: 1m limit-b-route: RequestCount: 10 WindowTime: 1m
GlobalConfig: ClientIDRule: by-ip # callers without a rule of their own are counted by IP UsageControlRules: [global-limit]
ServerConfigs: svc-a: URL: "http://svc-a:9090" svc-b: URL: "https://svc-b:9090" TLS: CACertFile: "ca.pem" UsageControlRules: [limit-b-server]
ServerRoutes: a-open: TargetServer: svc-a MatchOptions: PathPattern: /a/open BeforeForwarding: RemovePathPattern: true HeaderRule: allowlist-headers
b-open: TargetServer: svc-b MatchOptions: PathPattern: /b/open BeforeForwarding: RemovePathPattern: true HeaderRule: strip-and-set
a-limited: TargetServer: svc-a MatchOptions: PathPattern: /a/limited BeforeForwarding: RemovePathPattern: true UsageControlRules: [limit-a-low]
b-limited: TargetServer: svc-b MatchOptions: PathPattern: /b/limited BeforeForwarding: RemovePathPattern: true UsageControlRules: [limit-b-route]
a-secure: TargetServer: svc-a MatchOptions: PathPattern: /a/secure BeforeForwarding: RemovePathPattern: true AuthMethod: secure-hs256-bearer
b-secure: TargetServer: svc-b MatchOptions: PathPattern: /b/secure BeforeForwarding: RemovePathPattern: true AuthMethod: secure-hs512-raw
a-clients: TargetServer: svc-a MatchOptions: PathPattern: /a/clients BeforeForwarding: RemovePathPattern: true ClientIDRule: client-id-header
a-rewrite: TargetServer: svc-a MatchOptions: PathPattern: /a/rewrite BeforeForwarding: RemovePathPattern: true AddPathPrefix: /rewritten HeaderRule: preserve-hostWith this file:
- A request to
/a/open/status/500reachessvc-aas/status/500with onlyX-Request-IdandX-Trace-Id(plus the headers the gateway always keeps) forwarded. /b/limitedis limited byglobal-limit,limit-b-serverandlimit-b-routetogether./a/securerequires a valid bearer token signed with the HS256 key.
