agreeable-apartment-50592
04/05/2024, 3:17 PMchilly-king-10285
04/05/2024, 3:17 PMchilly-king-10285
04/05/2024, 3:18 PMheader
mutator to add session data to the HTTP headers, or the id_token
mutator to generate a JWT with session information. Here is an example of a header
mutator in an access rule: json { "id": "some-id", "upstream": { "url": "<http://my-backend-service>" }, "match": { "url": "<http://my-app/api/<.*>>", "methods": ["GET"] }, "authenticators": [ { "handler": "anonymous" } ], "authorizer": { "handler": "allow" }, "mutators": [ { "handler": "header", "config": { "headers": { "X-User": "{{ print .Subject }}", "X-Some-Arbitrary-Data": "{{ print .Extra.some.arbitrary.data }}" } } } ] }
In this example, the header
mutator adds the X-User
and X-Some-Arbitrary-Data
headers to the HTTP request. The values of these headers are extracted from the session data. However, please note that the session data is usually provided by an authenticator. If there is no user, the session data might not contain any meaningful information. In this case, you might want to use the anonymous
authenticator to handle requests from non-users. For more information, please refer to the [Ory Oathkeeper documentation](https://www.ory.sh/docs/oathkeeper/pipeline/mutator#header-access-rule-example).agreeable-apartment-50592
04/05/2024, 3:23 PMchilly-king-10285
04/05/2024, 3:23 PMchilly-king-10285
04/05/2024, 3:24 PMcookie_session
authenticator in your configuration is responsible for forwarding the request method, path, and headers to a session store (in this case, the Kratos public endpoint /sessions/whoami
). If the session store returns a 200 OK
response with a body containing a subject
field, the authenticator will set the subject appropriately. In your configuration, the subject_from
field is set to identity.id
, which means the subject will be set to the value of identity.id
from the session store's response. Here is the relevant part of your configuration: yaml cookie_session: enabled: true config: check_session_url: <http://kratos-public:80/sessions/whoami> preserve_path: true extra_from: "@this" subject_from: "identity.id"
So, even without a specific part in the authenticator, the subject_from
field in the configuration of the cookie_session
authenticator instructs it on how to extract the subject from the session data. For more information, please refer to the [Ory Oathkeeper documentation](https://www.ory.sh/docs/oathkeeper/pipeline/authn#cookie_session).icy-manchester-83109
04/06/2024, 1:04 AMagreeable-apartment-50592
04/08/2024, 9:57 AMicy-manchester-83109
04/08/2024, 10:07 AM{{ with .Extra.identity }}{{ .metadata_public.user_id }}{{ else }} whatever {{ end }}
icy-manchester-83109
04/08/2024, 10:26 AMagreeable-apartment-50592
04/09/2024, 10:31 AM