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

Support alternate OIDC providers, to prepare for the switch from Keycloak to fabric8_auth #8650

Merged
merged 11 commits into from
Mar 23, 2018

Conversation

davidfestal
Copy link
Contributor

What does this PR do?

This PR allows switching to an alternate OIDC provider (provided that it emits
access tokens as JWT tokens).

This is the CHE 6 equivalent of PR #8614 that has already been created against the CHE 5 maintenance branch.

What issues does this PR fix or reference?

This is the implementation required in upstream Che, for issues
redhat-developer/rh-che#502 and
redhat-developer/rh-che#525

Changes in dependencies

This PR depends on PR eclipse-che/che-dependencies#96 and the associated CQ.

@codenvy-ci
Copy link

Can one of the admins verify this patch?

@codenvy-ci
Copy link

Can one of the admins verify this patch?

1 similar comment
@codenvy-ci
Copy link

Can one of the admins verify this patch?

@benoitf benoitf added the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Feb 7, 2018
@@ -117,3 +121,18 @@ che.keycloak.github.endpoint=NULL

# The number of seconds to tolerate for clock skew when verifying exp or nbf claims.
che.keycloak.allowed_clock_skew_sec=3

# Use the OIDC optional `nonce` feature to increase security.
che.keycloak.use_nonce=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @davidfestal , it seems it's missing properties in che.env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym ? I see them in che.env here

@@ -543,6 +543,9 @@ CHE_SINGLE_PORT=false
#CHE_KEYCLOAK_CLIENT__ID=che-public
#CHE_KEYCLOAK_ALLOWED__CLOCK__SKEW__SEC=3
#CHE_KEYCLOAK_ADMIN_REQUIRE_UPDATE_PASSWORD=true
#CHE_KEYCLOAK_USE__NONCE=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

properties should be documented as it's for user editing (while the properties file is quite hidden)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documented in the che.env file or in the docs as a separate PR ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comments in commit 4ab6687

is it what you were expecting @benoitf ?

@@ -43,4 +48,25 @@ public KeycloakConfigurationService(KeycloakSettings keycloakSettings) {
public Map<String, String> settings() {
return keycloakSettings.get();
}

@GET
@Path("/OIDCKeycloak.js")
Copy link
Contributor

@mshaposhnik mshaposhnik Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to make it in such way:

@Path("/{filename}")
public String javascriptAdapter(@PathParam("filename") String filename)
....
Thread.currentThread().getContextClassLoader().getResource("keycloak/" + filename);
...
if (file_not_found) 
throw NotFoundException //(to be like 404 instead of epmty file)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would left it as is. Your proposal could be dangerous.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshaposhnik what happens if I use ../ on filename ? could I get some private files ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skabashnyuk @mshaposhnik I'll leave it as is then.

Copy link
Contributor

@mshaposhnik mshaposhnik Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very unlikely. They should be under java classpath. But *.properties can be read, probably.

# URL to the Keycloak Javascript adapter we want to use.
# if set to NULL, then the default used value is
# `${che.keycloak.auth_server_url}/js/keycloak.js`,
# or `<che-server>/wsmaster/keycloak/OIDCKeycloak.js`
Copy link
Contributor

@mshaposhnik mshaposhnik Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it something like OIDC_client.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's the keycloak.js file modified to be OIDC compatible, but still the Keycloak Javascript adaper, hence this name.

# URL to the Keycloak Javascript adapter we want to use.
# if set to NULL, then the default used value is
# `${che.keycloak.auth_server_url}/js/keycloak.js`,
# or `<che-server>/wsmaster/keycloak/OIDCKeycloak.js`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no /wsmaster URL's. Correct is /api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 8951eef

@davidfestal davidfestal self-assigned this Feb 7, 2018
davidfestal added a commit to eclipse-che/che-docs that referenced this pull request Mar 19, 2018
@davidfestal
Copy link
Contributor Author

Related documentation PR is here

@davidfestal
Copy link
Contributor Author

ci-test

@Named(CLIENT_ID_SETTING) String clientId,
@Nullable @Named(OIDC_PROVIDER_SETTING) String oidcProvider,
@Named(USE_NONCE_SETTING) boolean useNonce,
@Nullable @Named(OSO_ENDPOINT_SETTING) String osoEndpoint,
@Nullable @Named(GITHUB_ENDPOINT_SETTING) String gitHubEndpoint) {

if (serverURL == null && oidcProvider == null) {
LOG.error("Either the '" + AUTH_SERVER_URL_SETTING + "' or '" + OIDC_PROVIDER_SETTING + "' property should be set");
this.settings = Collections.unmodifiableMap(new HashMap<String, String>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just throw throw new RuntimeExeception("Either the '" + AUTH_SERVER_URL_SETTING + "' or '" + OIDC_PROVIDER_SETTING + "' property should be set")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this an acceptable mode or not? maybe Collections.emptyMap()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's acceptable why log.error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit e1e4001


if (oidcProvider == null && realm == null) {
LOG.error("The '" + REALM_SETTING + "' property should be set");
this.settings = Collections.unmodifiableMap(new HashMap<String, String>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just throw throw new RuntimeExeception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit e1e4001

}

if (oidcProvider == null && realm == null) {
LOG.error("The '" + REALM_SETTING + "' property should be set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use parametrised method

@skabashnyuk
Copy link
Contributor

Docs pr?

@codenvy-ci
Copy link

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:8650
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@davidfestal
Copy link
Contributor Author

Docs pr?

@skabashnyuk see comment #8650 (comment)

Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
These are exactly the same changes as those already done / approved in
the GWT application main HTML file. 

Signed-off-by: David Festal <dfestal@redhat.com>
Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal
Copy link
Contributor Author

ci-test

@codenvy-ci
Copy link

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:8650
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@davidfestal
Copy link
Contributor Author

ci-test

@codenvy-ci
Copy link

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:8650
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@dmytro-ndp
Copy link
Contributor

dmytro-ndp commented Mar 22, 2018

@davidfestal: selenium test launcher failed to create test users because it didn't find che realm "Resource not found for url: http://localhost:8080/auth/admin/realms/che/users".
Also URL to get auth token didn't work as well:

java.io.IOException: Failed access: http://che-eclipse-che.172.30.3.246.nip.io/api/keycloak/settings/?token
...
Application is not available

The application is currently not serving requests at this endpoint. It may not have been started or is still starting.

@riuvshin
Copy link
Contributor

@davidfestal from what I see che is not able to star from your branch on ocp
http://pastebin.test.redhat.com/567786

@l0rd
Copy link
Contributor

l0rd commented Mar 22, 2018

@riuvshin David is in PTO until monday but had commented that yesterday:

It seems that the Keycloak server used to run tests has a problem
Is it expected :

18:24:06 [TEST] Creating default test user with name 'user1521649448'...
18:24:09 [WARN] There is a problem with creation of default test user in Keycloak server: ''.�[0m
18:24:09 Admin user will be used as default test user.
18:24:09 [TEST] Creating second test user with name 'user1521649449'...
18:24:10 [WARN] There is a problem with creation of second test user in Keycloak server: ''.�[0m
18:24:10 Admin user will be used as a second test user.
18:24:11 Logging into http://localhost:8080/auth as user admin of realm master
18:24:11 Resource not found for url: http://localhost:8080/auth/admin/realms/che/users? username=admin&first=0&max=2

It seems that the Keycloak server is not correctly started, so that, finally the .../keycloak/settings endpoint doesn't work correctly.

@riuvshin
Copy link
Contributor

riuvshin commented Mar 22, 2018

@l0rd I deployed it locally, KC server is OK Im able to login as admin to KC but CHE server is down due to problems on start up

in che logs:

2018-03-22 09:31:53,667[ost-startStop-1]  [ERROR] [o.a.c.c.C.[.[localhost].[/api] 4752] - Exception sending context initialized event to listener instance of class [org.eclipse.che.inject.CheBootstrap]
com.google.inject.CreationException: Unable to create injector, see the following errors:
 
1) Error injecting constructor, java.lang.RuntimeException: Exception while retrieving OpenId configuration from endpoint: http://keycloak-eclipse-che.192.168.65.2.nip.io/auth/realms/che/.well-known/openid-configuration
  at org.eclipse.che.multiuser.keycloak.server.KeycloakSettings.<init>(KeycloakSettings.java:61)
  at org.eclipse.che.multiuser.keycloak.server.KeycloakSettings.class(KeycloakSettings.java:48)
  while locating org.eclipse.che.multiuser.keycloak.server.KeycloakSettings
    for the 1st parameter of org.eclipse.che.multiuser.keycloak.server.dao.KeycloakProfileDao.<init>(KeycloakProfileDao.java:46)
  while locating org.eclipse.che.multiuser.keycloak.server.dao.KeycloakProfileDao
  while locating org.eclipse.che.api.user.server.spi.ProfileDao
    for the 2nd parameter of org.eclipse.che.multiuser.api.account.personal.PersonalAccountUserManager.<init>(PersonalAccountUserManager.java:50)
  at org.eclipse.che.multiuser.api.account.personal.PersonalAccountUserManager.class(PersonalAccountUserManager.java:50)
  while locating org.eclipse.che.multiuser.api.account.personal.PersonalAccountUserManager
  while locating org.eclipse.che.api.user.server.UserManager
Caused by: java.lang.RuntimeException: Exception while retrieving OpenId configuration from endpoint: http://keycloak-eclipse-che.192.168.65.2.nip.io/auth/realms/che/.well-known/openid-configuration
        at org.eclipse.che.multiuser.keycloak.server.KeycloakSettings.<init>(KeycloakSettings.java:95)

is that expected url http://keycloak-eclipse-che.192.168.65.2.nip.io/auth/realms/che/.well-known/openid-configuration ?

based on that I can guess that it is calling wrong url OR this PR missing some other changes related to KC

@riuvshin
Copy link
Contributor

ci-test

@codenvy-ci
Copy link

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:8650
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@artaleks9
Copy link
Contributor

Test report is OK

@davidfestal davidfestal merged commit ff3459d into master Mar 23, 2018
@davidfestal davidfestal deleted the enable_oidc_providers_che6 branch March 23, 2018 13:45
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Mar 23, 2018
@benoitf benoitf added this to the 6.3.0 milestone Mar 23, 2018
bmicklea pushed a commit to eclipse-che/che-docs that referenced this pull request Mar 23, 2018
* Add documentation for alternate OIDC providers

Documentation related to PR eclipse-che/che#8650

* small type fix
skabashnyuk pushed a commit that referenced this pull request Jan 3, 2020
…loak to `fabric8_auth` (#8650)

Allow switching to an alternate OIDC provider (provided that it emits access tokens as JWT tokens).

This is the implementation required in upstream Che, for issues
redhat-developer/rh-che#502 and
redhat-developer/rh-che#525

Signed-off-by: David Festal <dfestal@redhat.com>
skabashnyuk pushed a commit to skabashnyuk/che that referenced this pull request Mar 11, 2020
…loak to `fabric8_auth` (eclipse-che#8650)

Allow switching to an alternate OIDC provider (provided that it emits access tokens as JWT tokens).

This is the implementation required in upstream Che, for issues
redhat-developer/rh-che#502 and
redhat-developer/rh-che#525

Signed-off-by: David Festal <dfestal@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.