Include connector UserID in ID Token
The JWT sub is being strangely encoded. I expect it to be equal to the UserID attribute set by the connector.
Looks like the result of https://github.com/coreos/dex/blob/master/server/oauth2.go#L269-L278
Because different backends can clash, we combined the UserID returned by the connector and combine it with the connector ID. This also gives us a consistent ID to track things like refresh tokens.
Why do you need the UserID? Could we possibly map it to a different scope?
For example, if I wanted to map permissions on the user account in Kubernetes via RBAC, it would be pretty tedious and difficult to track if sub is a base64 encoded string.
If any, I think we should encode it into a human-readable format or yes, create another claim with the concatenated information (or both).
So I think we should add a scope which adds this to claims. E.g. if you provide the uid scope, you get a claim like dex.coreos.com/uid returned. How does that sound?
cc @rithujohn191 @squat
I think that would suffice for the Kubernetes use-case. But I could imagine some OIDC consumers would have sub hardcoded into its logic and/or expect the value to be backed by LDAP or otherwise. As a consumer, I'd also expect the uid to be present in the JWT payload without having to explicitly request it.
Perhaps we could automatically include a dex.coreos.com/connector_id scope and make the behavior of the sub scope configurable.
What would the output in the API server logs be? We'd just like to be able to search logs for usernames, preferably by username in the ldap userSearch.
For what it's worth, what auth0 does is they just concat the connectorID + | + userIDFromConnector. No base64 encoding.
I would strongly encourage we add an additional scope (or set of scopes) and surface this as a claim. Please don't rely on the sub field's encoding.
And also, the regular userID for the given connection is in some non-standard claims: identities and userID like so:
Ex:
"sub": "google-oauth2|110272483197731336751",
"user_id": "google-oauth2|110272483197731336751",
"identities": [
{
"provider": "google-oauth2",
"user_id": "110272483197731336751",
"connection": "google-oauth2",
"isSocial": true
},
{
"profileData": {
"email": "[email protected]",
"email_verified": true
},
"user_id": "593f4610f8a34140059a5c95",
"provider": "auth0",
"connection": "Username-Password-Authentication",
"isSocial": false
}
],
The sub here could be auth0|593f4610f8a34140059a5c95 or google-oauth2|110272483197731336751. The value used is whichever the first userID was before the identities were merged within auth0.
The auth0 token also has a user_id claim which is the same value as sub, which is the same idea as @ericchiang's dex.coreos.com/uid.
Ok sounds good. Should we automatically include the uid claim or make it a request-able scope?
@Calpicow I think the uid should be included by default. I'm working on a Meteor app which uses the LDAP connector and currently I can only guess the uid from the email.
A more general feature request was added here: https://github.com/coreos/dex/issues/552
Ideally any solution to this would address the larger issue of mapping arbitrary LDAP attributes into the ID token claims. If this is scope based, it should be optional, but it could also be part of the LDAP connector configuration. I don't like the idea of just always including the dn because other use cases may demand other attributes.
Or maybe we just always include the upstream ID? That'd pair well with returning the upstream connector https://github.com/coreos/dex/issues/831
For anyone who wants to tackle this, the next step is a concrete proposal. We're not working on this directly yet.
Made a first stab with #970. I think the UID issue and LDAP attributes should be handled separately.
Is there still interest to make this happen?
We still definitely want this.
Okay, I've created a PR #1176.
It implements a new scope id_provider that adds a new claim id_provider to the ID token. The claim has the following format:
"id_provider": {
"connector_id": "github",
"user_id": "110272483197731336751"
}
This will make searching through logs so much nicer, thanks!
Closed via https://github.com/coreos/dex/pull/1176