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

It's not possible to get access token for CHE with oAuth on OCP 3.11 #18030

Closed
3 of 5 tasks
artaleks9 opened this issue Oct 2, 2020 · 13 comments
Closed
3 of 5 tasks

It's not possible to get access token for CHE with oAuth on OCP 3.11 #18030

artaleks9 opened this issue Oct 2, 2020 · 13 comments
Labels
area/install Issues related to installation, including offline/air gap and initial setup kind/bug Outline of a bug - must adhere to the bug report template. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. severity/P2 Has a minor but important impact to the usage or development of the system.

Comments

@artaleks9
Copy link
Contributor

artaleks9 commented Oct 2, 2020

Describe the bug

  • When Che with oAuth is installed on OCP 3.11 command getting access_token returns null.
  • Thus the chectl:workspace commands can't be performed for this case.

Che version

  • latest
  • nightly
  • other: please specify

Steps to reproduce

  • Che is installed with oAuth on OCP 3.11
  • Login in the Che Dashboard (Note: it's important step, see the doc)
  • Perform commands to get access_token (see PR):
KEYCLOAK_URL="https://$(oc get routes/keycloak -n ${productNamespace} -o jsonpath='{.spec.host}')/auth"
OS_TOKEN=$(oc whoami --show-token)
AT=$(curl -k -X POST -d "client_id=che-public" -d "subject_token=${OS_TOKEN}" -d "subject_issuer=openshift-v3" --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:access_token" $KEYCLOAK_URL/realms/che/protocol/openid-connect/token | jq -r .access_token)

Actual behavior

[ashmaraiev@localhost tmp]$ KEYCLOAK_URL=https://keycloak-aleks-che-oauth-test.apps.ocp311.crw/
[ashmaraiev@localhost tmp]$ echo $KEYCLOAK_URL
https://keycloak-aleks-che-oauth-test.apps.ocp311.crw/
[ashmaraiev@localhost tmp]$ OS_TOKEN=$(oc whoami --show-token)
[ashmaraiev@localhost tmp]$ echo $OS_TOKEN 
<some token>

[ashmaraiev@localhost tmp]$ ACCESS_TOKEN=$(curl -k -X POST -d client_id=che-public -d subject_token=$OS_TOKEN -d subject_issuer=openshift-v3 --data-urlencode grant_type=urn:ietf:params:oauth:grant-type:token-exchange --data-urlencode subject_token_type=urn:ietf:params:oauth:token-type:access_token https://keycloak-aleks-che-oauth-test.apps.ocp311.crw/auth/realms/che/protocol/openid-connect/token | jq -r .access_token)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   331  100    81  100   250     88    273 --:--:-- --:--:-- --:--:--   361
[ashmaraiev@localhost tmp]$ echo $ACCESS_TOKEN 
null
[ashmaraiev@localhost tmp]$ 

Expected behavior

  • Access_token should be a string value

Runtime

  • Openshift (include output of oc version)
[ashmaraiev@localhost ~]$ oc version
Client Version: 4.5.

Installation method

  • chectl
@artaleks9 artaleks9 added kind/bug Outline of a bug - must adhere to the bug report template. severity/P1 Has a major impact to usage or development of the system. area/install Issues related to installation, including offline/air gap and initial setup labels Oct 2, 2020
@tolusha
Copy link
Contributor

tolusha commented Oct 2, 2020

Why did you use subject_issuer=openshift-v4 ?

@tolusha
Copy link
Contributor

tolusha commented Oct 2, 2020

If AT=$(curl ..) command prints null, pls provide the output the curl command itself

@tolusha tolusha added the status/info-needed More information is needed before the issue can move into the “analyzing” state for engineering. label Oct 2, 2020
@artaleks9
Copy link
Contributor Author

artaleks9 commented Oct 2, 2020

Fixed command, it was a copy / paste. Really it was used openshift-v3
We can see output of command in the 'Actual behavior' section:

[ashmaraiev@localhost tmp]$ ACCESS_TOKEN=$(curl -k -X POST -d client_id=che-public -d subject_token=$OS_TOKEN -d subject_issuer=openshift-v3 --data-urlencode grant_type=urn:ietf:params:oauth:grant-type:token-exchange --data-urlencode subject_token_type=urn:ietf:params:oauth:token-type:access_token https://keycloak-aleks-che-oauth-test.apps.ocp311.crw/auth/realms/che/protocol/openid-connect/token | jq -r .access_token)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   331  100    81  100   250     88    273 --:--:-- --:--:-- --:--:--   361

null returns 'echo $AT'

@tolusha
Copy link
Contributor

tolusha commented Oct 2, 2020

I need the output just for curl command
And what does oc whoami prints ?

@artaleks9
Copy link
Contributor Author

artaleks9 commented Oct 2, 2020

[ashmaraiev@localhost ~]$ oc whoami
admin

  • What do you exactly mean about I need the output just for curl command?
    What I can do for it?

@tolusha
Copy link
Contributor

tolusha commented Oct 2, 2020

What I can do for it?

Don't use $() and don't pipe the output to jq command

@artaleks9
Copy link
Contributor Author

Done.

[ashmaraiev@localhost ~]$ curl -k -X POST -d "client_id=che-public" -d "subject_token=${OS_TOKEN}" -d "subject_issuer=openshift-v3" --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:access_token" https://keycloak-aleks-che-oauth-test.apps.ocp311.crw/auth/realms/che/protocol/openid-connect/token
[ashmaraiev@localhost ~]$

@tolusha
Copy link
Contributor

tolusha commented Oct 2, 2020


13:51:07,423 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-4) Uncaught server error: java.lang.NullPointerException
--
  | at org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.getJsonProperty(AbstractOAuth2IdentityProvider.java:357)
  | at org.keycloak.social.openshift.OpenshiftV3IdentityProvider.extractUserContext(OpenshiftV3IdentityProvider.java:61)
  | at org.keycloak.social.openshift.OpenshiftV3IdentityProvider.extractIdentityFromProfile(OpenshiftV3IdentityProvider.java:87)
  | at org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.validateExternalTokenThroughUserInfo(AbstractOAuth2IdentityProvider.java:489)
  | at org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.exchangeExternalUserInfoValidationOnly(AbstractOAuth2IdentityProvider.java:548)
  | at org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.exchangeExternalImpl(AbstractOAuth2IdentityProvider.java:528)
  | at org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider.exchangeExternal(AbstractOAuth2IdentityProvider.java:519)
  | at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.exchangeExternalToken(TokenEndpoint.java:917)
  | at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.tokenExchange(TokenEndpoint.java:696)
  | at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.processGrantRequest(TokenEndpoint.java:194)
  | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  | at java.lang.reflect.Method.invoke(Method.java:498)


@tolusha tolusha added severity/P2 Has a minor but important impact to the usage or development of the system. and removed status/info-needed More information is needed before the issue can move into the “analyzing” state for engineering. severity/P1 Has a major impact to usage or development of the system. labels Oct 5, 2020
@tolusha tolusha changed the title It's broken getting access token for CHE with oAuth on OCP 3.11 It's not possible to get access token for CHE with oAuth on OCP 3.11 Oct 5, 2020
@tolusha
Copy link
Contributor

tolusha commented Oct 5, 2020

I would say It has never worked.
Investigation shows that there is an issue with keycloak which has been fixed in 7.0.x version.
Execution the following code [1] [2] leads to NPE since metadata field is retrieved twice in row.
It isn't the case for OpenShift 4.x since we use a patched version of identity provider [3]

[1] https://github.com/keycloak/keycloak/blob/6.0.1/services/src/main/java/org/keycloak/social/openshift/OpenshiftV3IdentityProvider.java#L87
[2] https://github.com/keycloak/keycloak/blob/6.0.1/services/src/main/java/org/keycloak/social/openshift/OpenshiftV3IdentityProvider.java#L59
[3] https://github.com/che-incubator/KEYCLOAK-10169-OpenShift4-User-Provider/blob/master/src/main/java/org/keycloak/social/openshift/OpenshiftV4IdentityProvider.java

@dmytro-ndp
Copy link
Contributor

dmytro-ndp commented Jan 22, 2021

@tolusha
Copy link
Contributor

tolusha commented Jan 22, 2021

Interesting. I will check, maybe rh-sso image has been updated since then.

@tolusha
Copy link
Contributor

tolusha commented Jan 25, 2021

Not actual for CRW deployment but it is still an issue for Eclipse Che.

@che-bot
Copy link
Contributor

che-bot commented Aug 9, 2021

Issues go stale after 180 days of inactivity. lifecycle/stale issues rot after an additional 7 days of inactivity and eventually close.

Mark the issue as fresh with /remove-lifecycle stale in a new comment.

If this issue is safe to close now please do so.

Moderators: Add lifecycle/frozen label to avoid stale mode.

@che-bot che-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 9, 2021
@che-bot che-bot closed this as completed Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/install Issues related to installation, including offline/air gap and initial setup kind/bug Outline of a bug - must adhere to the bug report template. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. severity/P2 Has a minor but important impact to the usage or development of the system.
Projects
None yet
Development

No branches or pull requests

4 participants