Hi there!
I’ve successfully deploy Tyk Gateway, Tyk Operator and Tyk Pump through the OSS Helm chart. I’ve also managed to protect a few APIs using JWT (integrated with Authentik working as an OAuth2/OpenID Connect identity provider) by using this in the API definition (I’m using the CRDs, btw)
jwt_signing_method: rsa
jwt_source: "https://my.authentik.domain/application/o/my-provider/jwks/"
jwt_identity_base_field: sub
But now I want to take it one step further and I can’t seem to find enough resources to make it, thus I ended up here and I hope you can help me.
For instance, my JWT payload looks like this:
{
"iss": "https://my.authentik.domain/application/o/my-application/",
"sub": "some_value",
"aud": "some_value",
"exp": 00000000,
"iat": 00000000,
"auth_time": 00000000,
"acr": "goauthentik.io/providers/oauth2/default",
"amr": [
"pwd"
],
"matricula": "0000000",
"orgao": "Não Informado",
"setor": "Não Informado",
"cpf": "00000000000",
"email": "[email protected]",
"email_verified": true,
"name": "My Name",
"given_name": "My Name",
"preferred_username": "my_nickname",
"nickname": "",
"groups": [
"group1",
"group2"
]
}
Now, I want to achieve more granular access control within Tyk. Specifically, I need to:
- Grant Access Based on Groups: I want to restrict access to certain APIs and even specific endpoints based on the user’s group membership (
groups
claim in the JWT). For example, users ingroup1
should have access to certain APIs, whilegroup2
members might have access to different ones. - Granular Endpoint Control: Within a single API, I need to allow access to only specific endpoints for certain groups. For instance, members of
group1
might only access/api/v1/resource1
, whilegroup2
can access/api/v1/resource2
.
I’m using the Tyk CRDs (ApiDefinition
and SecurityPolicy
) to define these configurations, but I’m struggling with how to properly set up the policies and API definitions to enforce these access controls.
Questions:
- How can I configure the
SecurityPolicy
CRD to enforce access controls based on thegroups
claim in the JWT? - What’s the best way to structure the
ApiDefinition
CRDs to ensure that group-based access restrictions are applied at both the API and endpoint levels? - Are there any specific examples or documentation that can guide me through this setup?
Any guidance or examples from those who have implemented similar setups would be incredibly helpful. Thanks in advance for your assistance!