ory / oathkeeper

A cloud native Identity & Access Proxy / API (IAP) and Access Control Decision API that authenticates, authorizes, and mutates incoming HTTP(s) requests. Inspired by the BeyondCorp / Zero Trust white paper. Written in Go.
https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=hydra
Apache License 2.0
3.2k stars 349 forks source link

Reference to .MatchContext.RegexpCaptureGroups doesn't render in access rules authenticator config #1141

Open sunnyyip opened 7 months ago

sunnyyip commented 7 months ago

Preflight checklist

Ory Network Project

https://naughty-tesla-4oqisau3a4.projects.oryapis.com

Describe the bug

I have an access rule aiming to enforce JWT audience to match the requested domain. However .MatchContext.RegexpCaptureGroups reference, defined in the audience field, didn’t render (cause of the error) and get printed out literally in the log.

{ "id": "protected_resources", "version": "v0.40.6", "match": { "url": "<http|https>://<.*>/<playground|query|anything/header>", "methods": [ "GET", "POST" ] }, "authenticators": [ { "handler": "jwt", "config": { "target_audience": [ "{{ printIndex .MatchContext.RegexpCaptureGroups 0 }}://{{ printIndex .MatchContext.RegexpCaptureGroups 1 }}" ] } } ],

Reproducing the bug

  1. include an url with regex match group
  2. reference the match group in JWT authenticator config - e.g. audience
  3. make a request to oathkeeper
  4. observe errors in logs due to .MatchContext.RegexpCaptureGroups being treated as string literally

Relevant log output

"reason": "id=\nrid=\nerror=The request could not be authorized\nreason=Token audience [https://my.domain.com] is not intended for target audience {{ printIndex .MatchContext.RegexpCaptureGroups 0 }}://{{ printIndex .MatchContext.RegexpCaptureGroups 1 }}

Relevant configuration

{
    "id": "protected_resources",
    "version": "v0.40.6",
    "match": {
      "url": "<http|https>://<.*>/<playground|query|anything/header>",
      "methods": [
        "GET",
        "POST"
      ]
    },
    "authenticators": [
      {
        "handler": "jwt",
        "config": {
          "target_audience": [
            "{{ printIndex .MatchContext.RegexpCaptureGroups 0 }}://{{ printIndex .MatchContext.RegexpCaptureGroups 1 }}"
          ]
        }
      }
    ],

Version

v0.40.6

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Kubernetes with Helm

Additional Context

No response