JWT token without `sub` not accepted by AuthorizationPolicy (`request_principals`)
Is this the right place to submit this?
- This is not a security vulnerability or a crashing bug
- This is not a question about how to use Istio
Bug Description
We recently ran into issues with JWT tokens not carrying a sub (subject) field being rejected by an AuthorizationPolicy not actually containing any /<SUB> (https://istio.io/latest/docs/reference/config/security/authorization-policy/#Source-request_principals):
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: my-jwt-policy
namespace: my-namespace
spec:
action: ALLOW
rules:
- from:
- source:
requestPrincipals:
- https://REDACTED/*
to:
- operation:
paths:
- /api
selector:
matchLabels:
app: myapp
version: 1.2.3Previously working requests where now ending up with:
response_code: 401
response_code_details: rbac_access_denied_matched_policy[none]
The sub field in the tokens was removed due to the migration to lightweight tokens now being issued by Keycloak 26. They introduced this in 25.x, see https://www.keycloak.org/docs/latest/release_notes/index.html#lightweight-access-token-to-be-even-more-lightweight. sub and auth_time are now part of the basic scope, see https://www.keycloak.org/docs/26.5.6/upgrading/#new-default-client-scope-basic. After adding the basic scope to the client, all requests worked as before.
This is how the tokens compare ...
broken:
{
"exp": 1773152607,
"iat": 1773152007,
"jti": "onrtrt:65206701-d27a-5c59-9706-bf59836f0611",
"iss": "https://REDACTED",
"typ": "Bearer",
"azp": "REDACTED",
"sid": "c7ec5b32-351b-42a7-afe9-b85d54952263",
"allowed-origins": [
"https://REDACTED"
],
"scope": "openid email created opt-ins profile",
[...]working:
{
"exp": 1773161419,
"iat": 1773160819,
"auth_time": 1773151582,
"jti": "onrtac:97a73d62-b361-4c59-e6de-baa18e8fa1da",
"iss": "https://REDACTED",
"sub": "f:f280c01d-a124-4f68-be5d-123456:1234567",
"typ": "Bearer",
"azp": "REDACTED",
"sid": "-i6mX8ra3lu0EwqfLyAeo1F5",
"allowed-origins": [
"https://REDACTED"
],
"scope": "openid email created opt-ins profile",
[...]I then looked at the actual Envoy filters created by Istio based on the AuthorizationPolicy:
[...]
"principals": [
{
"and_ids": {
"ids": [
{
"and_ids": {
"ids": [
{
"metadata": {
"filter": "envoy.filters.http.jwt_authn",
"path": [
{
"key": "payload"
},
{
"key": "iss"
}
],
"value": {
"string_match": {
"exact": "https://REDACTED"
}
}
}
},
{
"metadata": {
"filter": "envoy.filters.http.jwt_authn",
"path": [
{
"key": "payload"
},
{
"key": "sub"
}
],
"value": {
"string_match": {
"safe_regex": {
"regex": ".+"
}
}
}
}
}
]
}
}
]
]
[...]So there actually is a matcher on the non existing sub payload, even though it's an intended any, it expects data to be there.
This likely is the source code creating this piece of the filter: https://github.com/istio/istio/blob/c733733e7f2f87b26df12f191ab83c247f4dba06/pilot/pkg/security/authz/model/generator.go#L266-L273
at least according to https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 the sub field is OPTIONAL,
even though it's rather expected / required in the context of OpenID Connect - https://openid.net/specs/openid-connect-core-1_0.html.
But to come back to this bug report, I believe a field not configured as a condition should not exist in the filter at all. So to me this seems the most obvious fix:
"Be liberal in what you accept" (if it was not part of the policy in the first place).
Version
$ istioctl version
client version: 1.29.1
control plane version: 1.29.1
data plane version: 1.29.1 (218 proxies)
$ kubectl version
Client Version: v1.35.2
Kustomize Version: v5.7.1
Server Version: v1.34.4-eks-3a10415Additional Information
No response
Source: istio/istio