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

Apply OpenShift OAuth provider #15963

Merged
merged 17 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth-openshift</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth-shared</artifactId>
Expand Down Expand Up @@ -426,6 +430,7 @@
<dep>com.h2database:h2</dep>
<dep>org.eclipse.che.core:che-core-db-vendor-mysql</dep>
<dep>org.eclipse.che.core:che-core-sql-schema</dep>
<dep>org.eclipse.che.core:che-core-api-auth-openshift</dep>
<dep>org.eclipse.che.core:che-core-api-ssh-shared</dep>
<dep>org.eclipse.che.multiuser:che-multiuser-sql-schema</dep>
<dep>org.jgroups:jgroups</dep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ che.oauth.github.authuri= https://github.com/login/oauth/authorize
che.oauth.github.tokenuri= https://github.com/login/oauth/access_token
che.oauth.github.redirecturis= http://localhost:${CHE_PORT}/api/oauth/callback

# You can setup GitHub OAuth to automate authentication to remote repositories.
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
# You need to first register this application with GitHub OAuth.
che.oauth.openshift.clientid=NULL
che.oauth.openshift.clientsecret=NULL
che.oauth.openshift.endpoint= NULL

### Internal

Expand Down
3 changes: 3 additions & 0 deletions deploy/kubernetes/helm/che/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ data:
CHE_MULTIUSER: {{ .Values.global.multiuser | quote }}
CHE_OAUTH_GITHUB_CLIENTID: {{ .Values.global.gitHubClientID | quote}}
CHE_OAUTH_GITHUB_CLIENTSECRET: {{ .Values.global.gitHubClientSecret | quote}}
CHE_OAUTH_OPENSHIFT_CLIENTID: {{ .Values.global.openShiftClientID | quote}}
CHE_OAUTH_OPENSHIFT_CLIENTSECRET: {{ .Values.global.openShiftClientSecret | quote}}
CHE_OAUTH_OPENSHIFT_ENDPOINT: {{ .Values.global.openShiftEndpoint | quote}}
JAVA_OPTS: "-XX:MaxRAMFraction=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true -Xms20m "
CHE_WORKSPACE_AUTO_START: "false"
{{- if .Values.global.tls.enabled }}
Expand Down
4 changes: 4 additions & 0 deletions deploy/kubernetes/helm/che/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ global:

gitHubClientID: ""
gitHubClientSecret: ""
openShiftClientID: ""
openShiftClientSecret: ""
openShiftAuthUri: ""
openShiftTokenUri: ""
# Possible values: common, per-workspace, unique
cheWorkspacesPVCStrategy: "common"
pvcClaim: "1Gi"
Expand Down
20 changes: 19 additions & 1 deletion deploy/openshift/templates/che-server-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ objects:
value: "${CHE_OAUTH_GITHUB_CLIENTID}"
- name: CHE_OAUTH_GITHUB_CLIENTSECRET
value: "${CHE_OAUTH_GITHUB_CLIENTSECRET}"
- name: CHE_OAUTH_OPENSHIFT_CLIENTID
value: "${CHE_OAUTH_OPENSHIFT_CLIENTID}"
- name: CHE_OAUTH_OPENSHIFT_CLIENTSECRET
value: "${CHE_OAUTH_OPENSHIFT_CLIENTSECRET}"
- name: CHE_OAUTH_OPENSHIFT_ENDPOINT
value: "${CHE_OAUTH_OPENSHIFT_ENDPOINT}"
- name: JAVA_OPTS
value: "-XX:MaxRAMFraction=2 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10
-XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90
Expand Down Expand Up @@ -341,7 +347,19 @@ parameters:
value: ''
- name: CHE_OAUTH_GITHUB_CLIENTSECRET
displayName: GitHub Client Secret
description: GitHub OAuth app client servet. Applicable to Che single user only!
description: GitHub OAuth app client secret. Applicable to Che single user only!
value: ''
- name: CHE_OAUTH_OPENSHIFT_CLIENTID
displayName: OpenShift Client ID
description: OpenShift OAuth app client ID. Applicable to Che single user only!
value: ''
- name: CHE_OAUTH_OPENSHIFT_CLIENTSECRET
displayName: OpenShift Client Secret
description: OpenShift OAuth app client secret. Applicable to Che single user only!
value: ''
- name: CHE_OAUTH_OPENSHIFT_ENDPOINT
displayName: OpenShift endpoint
description: OpenShift endpoint. Applicable to Che single user only!
value: ''
- name: CHE_WORKSPACE_PLUGIN__REGISTRY__URL
displayName: Eclipse Che plugin registry URL
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
<artifactId>che-core-api-auth-github</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth-openshift</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth-shared</artifactId>
Expand Down
59 changes: 59 additions & 0 deletions wsmaster/che-core-api-auth-openshift/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2012-2018 Red Hat, Inc.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Red Hat, Inc. - initial API and implementation

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-master-parent</artifactId>
<groupId>org.eclipse.che.core</groupId>
<version>7.9.0-SNAPSHOT</version>
</parent>
<artifactId>che-core-api-auth-openshift</artifactId>
<packaging>jar</packaging>
<name>Che Core :: API :: Authentication OpenShift</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-auth-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.security.oauth;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.eclipse.che.inject.DynaModule;

/**
* Setup OpenShiftOAuthAuthenticator in guice container.
*
* @author Igor Vinokur
*/
@DynaModule
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
public class OpenShiftModule extends AbstractModule {
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
@Override
protected void configure() {
Multibinder<OAuthAuthenticator> oAuthAuthenticators =
Multibinder.newSetBinder(binder(), OAuthAuthenticator.class);
oAuthAuthenticators.addBinding().to(OpenShiftOAuthAuthenticator.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.security.oauth;

import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.client.util.store.MemoryDataStoreFactory;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.auth.shared.dto.OAuthToken;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.security.oauth.shared.User;

/**
* OAuth authentication for OpenShift.
*
* @author Igor Vinokur
*/
@Singleton
public class OpenShiftOAuthAuthenticator extends OAuthAuthenticator {
private final String openshiftEndpoint;

@Inject
public OpenShiftOAuthAuthenticator(
@Nullable @Named("che.oauth.openshift.clientid") String clientId,
@Nullable @Named("che.oauth.openshift.clientsecret") String clientSecret,
@Nullable @Named("che.oauth.openshift.endpoint") String openshiftEndpoint,
@Named("che.api") String apiEndpoint)
throws IOException {
openshiftEndpoint =
openshiftEndpoint.endsWith("/") ? openshiftEndpoint : openshiftEndpoint + "/";
this.openshiftEndpoint = openshiftEndpoint;
String[] redirectUrl = {apiEndpoint + "/oauth/callback"};
if (!isNullOrEmpty(clientId)
&& !isNullOrEmpty(clientSecret)
&& !isNullOrEmpty(openshiftEndpoint)) {
configure(
clientId,
clientSecret,
redirectUrl,
openshiftEndpoint + "oauth/authorize",
openshiftEndpoint + "oauth/token",
new MemoryDataStoreFactory());
}
}

@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
throw new OAuthAuthenticationException("not supported");
}

@Override
public final String getOAuthProvider() {
return "openshift";
}

@Override
public OAuthToken getToken(String userId) throws IOException {
final OAuthToken token = super.getToken(userId);
// Check if the token is valid for requests.
if (!(token == null || token.getToken() == null || token.getToken().isEmpty())) {
String tokenVerifyUrl = this.openshiftEndpoint + "oapi/v1/projects";
vinokurig marked this conversation as resolved.
Show resolved Hide resolved
HttpURLConnection http = null;
try {
http = (HttpURLConnection) new URL(tokenVerifyUrl).openConnection();
http.setInstanceFollowRedirects(false);
http.setRequestMethod("GET");
http.setRequestProperty("Authorization", "Bearer " + token.getToken());
http.setRequestProperty("Accept", "application/json");

if (http.getResponseCode() == 401) {
return null;
}
} finally {
if (http != null) {
http.disconnect();
}
}

return token;
}
return null;
}
}
1 change: 1 addition & 0 deletions wsmaster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<module>che-core-api-auth-shared</module>
<module>che-core-api-auth</module>
<module>che-core-api-auth-github</module>
<module>che-core-api-auth-openshift</module>
<module>che-core-api-workspace-shared</module>
<module>che-core-api-workspace</module>
<module>che-core-api-workspace-activity</module>
Expand Down