mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-12 04:04:26 +00:00
fix(catalog): analyzer-valid testData and explicit New() error return
The plugin catalog analyzer failed v1.0.28 with "invalid handler type: <nil>" (#151). Two defects combined. The analyzer feeds .traefik.yml testData to New() verbatim. The header values used quadruple braces on a false premise: no configuration path collapses them. Template validation rejected them, so New() failed. The testData now carries plain, valid templates. New() also returned failures through a multi-value tail call (return NewWithContext(...)). Yaegi v0.16.1 zeroes both results of that statement on the error path. The analyzer therefore saw (nil, nil) and reported the opaque handler-type message instead of the real validation error. New() now splits the return explicitly. Construction failures surface as real error messages under yaegi and in Traefik logs. The regression tests pin both fixes. README and CONFIGURATION.md now give correct escaping guidance: plain double braces everywhere; file provider users escape with a raw string. Quadruple braces do not work anywhere. Fixes #151.
This commit is contained in:
@@ -372,11 +372,11 @@ Forward identity to backends via Go templates over ID-token claims and tokens:
|
||||
```yaml
|
||||
headers:
|
||||
- name: X-User-Email
|
||||
value: "{{{{.Claims.email}}}}"
|
||||
value: "{{.Claims.email}}"
|
||||
- name: Authorization
|
||||
value: "Bearer {{{{.AccessToken}}}}"
|
||||
value: "Bearer {{.AccessToken}}"
|
||||
- name: X-User-Roles
|
||||
value: "{{{{range $i, $e := .Claims.roles}}}}{{{{if $i}}}},{{{{end}}}}{{{{$e}}}}{{{{end}}}}"
|
||||
value: "{{range $i, $e := .Claims.roles}}{{if $i}},{{end}}{{$e}}{{end}}"
|
||||
```
|
||||
|
||||
Available bindings: `.Claims.<field>`, `.AccessToken`, `.IdToken`
|
||||
@@ -397,7 +397,7 @@ allowedClaims:
|
||||
- employee_id
|
||||
headers:
|
||||
- name: X-Employee-Id
|
||||
value: "{{{{.Claims.employee_id}}}}"
|
||||
value: "{{.Claims.employee_id}}"
|
||||
```
|
||||
|
||||
Rendering the whole context (`{{.}}`, `{{$}}`), the whole claims map
|
||||
@@ -406,11 +406,16 @@ from accidentally forwarding raw tokens or unlisted claims. `range`/`with` must
|
||||
target a specific listed claim (e.g. `{{range .Claims.groups}}`); `get`/`default`
|
||||
are the only functions allowed.
|
||||
|
||||
> **Escape with quadruple braces.** If you see
|
||||
> `can't evaluate field AccessToken in type bool`, Traefik's YAML parser ate
|
||||
> your `{{ }}`. The fix that actually works is `{{{{ }}}}` — the YAML pass
|
||||
> turns it into `{{ }}` for the Go template engine. Other escaping tricks
|
||||
> (literal blocks, single quotes) do not work reliably.
|
||||
> **File-provider users: escape the braces.** Traefik's file provider runs
|
||||
> every dynamic configuration file through Go templating before the plugin
|
||||
> sees it. Plain `{{.AccessToken}}` then fails with
|
||||
> `can't evaluate field AccessToken in type bool`. Wrap the expression in a
|
||||
> raw string so the file provider emits it literally:
|
||||
> ``value: "{{`{{.Claims.email}}`}}"``. All other providers (Kubernetes CRD,
|
||||
> Docker labels, Consul, ...) pass the value through untouched — use the plain
|
||||
> form there. Quadruple braces (`{{{{ }}}}`) do not work anywhere: the file
|
||||
> provider fails to parse them, and every other path hands them to the plugin
|
||||
> verbatim, where template validation rejects them (issues #149, #151).
|
||||
|
||||
## Default downstream headers
|
||||
|
||||
@@ -438,7 +443,7 @@ section — see [docs/CONFIGURATION.md](docs/CONFIGURATION.md#security-headers).
|
||||
| `No matching public key found` | JWKS endpoint down, or `kid` mismatch. |
|
||||
| `Access denied: Your email domain is not allowed` | User's domain not in `allowedUserDomains`. |
|
||||
| `Access denied: You do not have any of the allowed roles or groups` | Claims missing or not in `allowedRolesAndGroups`. |
|
||||
| `can't evaluate field AccessToken in type bool` | Template not escaped — use `{{{{ }}}}`. |
|
||||
| `can't evaluate field AccessToken in type bool` | File provider templated your header value — escape it: ``"{{`{{.AccessToken}}`}}"`` (see "Templated headers"). |
|
||||
| `tls: failed to verify certificate: x509: certificate signed by unknown authority` | Internal CA — set `caCertPath` / `caCertPEM`. |
|
||||
| `invalid handler type: <nil>` | Env var name contains `API` — rename it. |
|
||||
| `false positive replay detected` | Multi-replica without Redis — see [Multi-replica deployments](#multi-replica-deployments). |
|
||||
|
||||
Reference in New Issue
Block a user