Skip to content

Commit a5a418c

Browse files
sbernauerlabrenbe
andauthored
docs: Document how to configure user-info-fetcher Keycloak user (#739)
* docs: Document how to configure user-info-fetcher Keycloak user * Apply suggestions from code review Co-authored-by: Benedikt Labrenz <[email protected]> --------- Co-authored-by: Benedikt Labrenz <[email protected]>
1 parent dff61f2 commit a5a418c

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Loading
Loading
Loading
Loading

docs/modules/opa/pages/usage-guide/user-info-fetcher.adoc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,69 @@ Fetch groups and extra credentials, but not roles.
7070

7171
NOTE: The OAuth2 Client in Keycloak must be given the `view-users` _Service Account Role_ for the realm that the users are in.
7272

73+
The user-info-fetcher requires a service account in Keycloak with the permissions to read user objects.
74+
To create such as user you need to take the following steps:
75+
76+
*With your user realm selected* click on `Clients` at the left side and use the `Import client` button:
77+
78+
image::keycloak-user-info-fetcher/1.png[]
79+
80+
Create a file with the following JSON object.
81+
Swap out `secret` with your desired password and potentially `redirectUris` and `webOrigins`.
82+
83+
[source,json]
84+
----
85+
{
86+
"clientId" : "user-info-fetcher",
87+
"surrogateAuthRequired" : false,
88+
"enabled" : true,
89+
"alwaysDisplayInConsole" : false,
90+
"clientAuthenticatorType" : "client-secret",
91+
"secret" : "XXX",
92+
"redirectUris" : [ "*" ],
93+
"webOrigins" : [ "*" ],
94+
"notBefore" : 0,
95+
"bearerOnly" : false,
96+
"serviceAccountsEnabled" : true,
97+
"publicClient" : false,
98+
"frontchannelLogout" : true,
99+
"protocol" : "openid-connect",
100+
"attributes" : {
101+
"oidc.ciba.grant.enabled" : "true",
102+
"oauth2.device.authorization.grant.enabled" : "false"
103+
},
104+
"authenticationFlowBindingOverrides" : { },
105+
"fullScopeAllowed" : true
106+
}
107+
----
108+
109+
Upload the file to the client importer and click on `Save`.
110+
111+
image::keycloak-user-info-fetcher/2.png[]
112+
113+
Afterwards you need to modify the created user `service-account-user-info-fetcher`.
114+
To achieve this open the user and click on the `Role mapping tab`:
115+
116+
image::keycloak-user-info-fetcher/3.png[]
117+
118+
Assign the role `view-users` as shown below.
119+
This is necessary to allow the user to read other users' information.
120+
121+
image::keycloak-user-info-fetcher/4.png[]
122+
123+
Afterwards you can store the user-info-fetcher credentials in Kubernetes in a Secret:
124+
125+
[source,yaml]
126+
----
127+
apiVersion: v1
128+
kind: Secret
129+
metadata:
130+
name: user-info-fetcher-client-credentials
131+
stringData:
132+
clientId: user-info-fetcher
133+
clientSecret: XXX # replace with your chosen password
134+
----
135+
73136
[#backend-activedirectory]
74137
=== Active Directory
75138

@@ -165,6 +228,23 @@ An example of the returned structure:
165228

166229
NOTE: The exact formats of `id` and `groups` will vary depending on the xref:#backends[backend] in use. This example is using the xref:#backend-keycloak[] backend.
167230

231+
=== Debug request
232+
233+
To debug the user-info-fetcher you can `curl` it's API for a given user.
234+
To achieve this shell into the `user-info-fetcher` container and execute
235+
236+
[source,bash]
237+
----
238+
curl --header "Content-Type: application/json" -d '{"username":"my-user"}' http://127.0.0.1:9476/user
239+
----
240+
241+
You can also use `-d '{"id":"123456"}'` to query by the user ID.
242+
243+
=== Rego rule library
244+
245+
The HTTP API exposed by the user-info-fetcher can be called directly using the rego function `http.send`.
246+
However, we provide a convenience rego rule library, which we ship with `OpaClusters` by default.
247+
168248
For example, the following rule allows access for users in the `/admin` group:
169249

170250
[source,rego]

0 commit comments

Comments
 (0)