Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAY_TOKEN cookie rejected because userprofile exceeds 4096 chars #4448

Closed
mariusingjer opened this issue Mar 18, 2022 · 9 comments
Closed
Assignees
Labels
bug Bug report product PR or Issue related to the DataHub UI/UX

Comments

@mariusingjer
Copy link

Describe the bug

The datahub page just keeps refreshing after enabling OIDC

Docker logs from the frontend is just repeating:

ERROR auth.sso.oidc.OidcCallbackLogic - Unable to renew the session. The session store may not support this feature

Config:

'AUTH_OIDC_ENABLED': 'true',
'AUTH_OIDC_CLIENT_ID': ...,
'AUTH_OIDC_CLIENT_SECRET': ....
'AUTH_OIDC_DISCOVERY_URI': 'https://cognito-idp.xxx.amazonaws.com/xxx/.well-known/openid-configuration',
'AUTH_OIDC_BASE_URL': 'https://...',
'AUTH_OIDC_USER_NAME_CLAIM': 'email',
'AUTH_OIDC_USER_NAME_CLAIM_REGEX': '([^@]+)',
'AUTH_OIDC_SCOPE': 'email openid profile'

Frontend container version:

linkedin/datahub-frontend-react:11f809a

datahub_network_oidc_error

.well-known:

{
  "authorization_endpoint": "https://xxxxxxxxx/oauth2/authorize",
  "id_token_signing_alg_values_supported": [
    "RS256"
  ],
  "issuer": "https://cognito-idp.xxxxxx.amazonaws.com/xxxxxx",
  "jwks_uri": "https://cognito-idp.xxxxxx.amazonaws.com/xxxxxx/.well-known/jwks.json",
  "response_types_supported": [
    "code",
    "token"
  ],
  "scopes_supported": [
    "openid",
    "email",
    "phone",
    "profile"
  ],
  "subject_types_supported": [
    "public"
  ],
  "token_endpoint": "https://xxxxxx.amazoncognito.com/oauth2/token",
  "token_endpoint_auth_methods_supported": [
    "client_secret_basic",
    "client_secret_post"
  ],
  "userinfo_endpoint": "https://xxxxxx.amazoncognito.com/oauth2/userInfo"
}
@mariusingjer mariusingjer added the bug Bug report label Mar 18, 2022
@HagunKim
Copy link

I'm not sure if this is helpful. In my case, the same issue occured since the response cookie size was larger than 4096 bytes. To reduce the size, I reduced the number of claims on OIDC.

@mariusingjer
Copy link
Author

The PLAY_SESSION token is 984 bytes, I can also mention that the user who opens the DataHub frontpage is automatically provisioned in the database (he/she appears in metadata_aspect_v2;), so the OIDC integration is working up until that point.

@mariusingjer
Copy link
Author

mariusingjer commented Mar 21, 2022

This is the code which is complaining btw:

https://github.com/pac4j/pac4j/blob/master/pac4j-core/src/main/java/org/pac4j/core/engine/DefaultCallbackLogic.java

protected void renewSession(final WebContext context, final SessionStore sessionStore, final Config config) {
        final var oldSessionId = sessionStore.getSessionId(context, true).get();
        final var renewed = sessionStore.renewSession(context);
        if (renewed) {
            final var newSessionId = sessionStore.getSessionId(context, true).get();
            LOGGER.debug("Renewing session: {} -> {}", oldSessionId, newSessionId);
            final var clients = config.getClients();
            if (clients != null) {
                final var clientList = clients.getClients();
                for (final var client : clientList) {
                    final var baseClient = (BaseClient) client;
                    baseClient.notifySessionRenewal(oldSessionId, context, sessionStore);
                }
            }
        } else {
            LOGGER.error("Unable to renew the session. The session store may not support this feature");
        }
    }

and the token in the PLAY_SESSION looks like this (which is wrong btw, this is the datahub user not the user logging in):

{
  "actorType": "USER",
  "actorId": "datahub",
  "type": "SESSION",
  "version": "1",
  "exp": 1647690589,
  "jti": "xxxxxxxxxxxxx",
  "sub": "datahub",
  "iss": "datahub-metadata-service"
}

@mariusingjer
Copy link
Author

..and I found the problem. The cookie returned after completing the oidc flow is indeed greater than 4096 characters and thus rejected by the browser. I've peeked at the id and auth token returned from cognito and they are pretty slim, same goes for the user-information returned by the userinfo endpoint. The "pac4j_pac4jUserProfiles" part in the PLAY_SESSION is however "gigantic" (3972 chars). Its not base64 encoded, so I can't peek into it.

Does anyone know the encoding on the pac4juserProfiles part, or if there are any others ways of trimming the userprofile than trimming the id/access token?

@mariusingjer mariusingjer changed the title OIDC Authentication not working with AWS cognito PLAY_TOKEN cookie rejected because userprofile exceeds 4096 chars Mar 21, 2022
@mariusingjer
Copy link
Author

For others: I had requested 3 claims:

'AUTH_OIDC_SCOPE': 'email openid profile'

I removed the profile claim, this trimmed the PLAY_TOKEN < 4096 chars

@mariusingjer
Copy link
Author

I have to reopen this. We have multiple users who are rejected because they have too many claims. We provision groups in datahub based on claims and we have a oauth server which passes along active directory group membership as claims, so we get into this situation quite quickly. Is there any way to further trim the PLAY_TOKEN?

@jjoyce0510
Copy link
Collaborator

Hi @mariusingjer - We need to understand whether we can slim down the Pac4j profile - perhaps there's a way to limit the profile map to only store specific claims, or to avoid storing the profile in the cookie altogether (I think that's what is happening). After login we do not extract claims from the Pac4j profile so I feel like we can probably clean it up.. I've not had too much time to dig into this yet - have you found anything?

@neojunjie
Copy link
Contributor

Hi @jjoyce0510 submitted 1 PR to resolve this issue (#5114)

@maggiehays maggiehays added the product PR or Issue related to the DataHub UI/UX label Jul 8, 2022
@jjoyce0510
Copy link
Collaborator

Hi folks,

We've recently submitted a fix to address this which uses a server-side cache for storing the session state. This comes with some caveats - you are not able to scale datahub-frontend beyond a single pod (which is fine for most deployments).

See this PR, which is present in the latest release (v0.8.40): #5114

In the future, some work can still be completed to reduce the attributes which are cached from the OIDC profile, to only those required to make auth work.

Because there is a deployed solution, going to close out the issue.

Thanks
John

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report product PR or Issue related to the DataHub UI/UX
Projects
None yet
Development

No branches or pull requests

5 participants