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

Adding support for OpenShift Username/Password auth strategy #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions teamcity-kubernetes-plugin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<kubernetes-client.version>4.7.0</kubernetes-client.version>
<openshift-client.version>4.7.0</openshift-client.version>
</properties>
<parent>
<artifactId>teamcity-kubernetes-plugin</artifactId>
Expand Down Expand Up @@ -130,6 +131,18 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>${openshift-client.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class KubeAuthStrategyProviderImpl implements KubeAuthStrategyProvider {

public KubeAuthStrategyProviderImpl(@NotNull TimeService timeService) {
registerStrategy(new UserPasswdAuthStrategy());
registerStrategy(new OpenShiftUserPasswdAuthStrategy());
registerStrategy(new DefaultServiceAccountAuthStrategy());
registerStrategy(new UnauthorizedAccessStrategy());
registerStrategy(new ClientCertificateAuthStrategy());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2020 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package jetbrains.buildServer.clouds.kubernetes.auth;

import io.fabric8.kubernetes.client.ConfigBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import jetbrains.buildServer.clouds.kubernetes.connector.KubeApiConnection;
import jetbrains.buildServer.serverSide.InvalidProperty;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static jetbrains.buildServer.clouds.kubernetes.KubeParametersConstants.*;

/**
* Created by ekoshkin ([email protected]) on 14.06.17.
*/
public class OpenShiftUserPasswdAuthStrategy implements KubeAuthStrategy {
public static final String ID = "openshift-user-passwd";

@NotNull
@Override
public String getId() {
return ID;
}

@NotNull
@Override
public String getDisplayName() {
return "OpenShift Username / Password";
}

@Nullable
@Override
public String getDescription() {
return "User OpenShift Username and Password authentication";
}

@NotNull
@Override
public ConfigBuilder apply(@NotNull ConfigBuilder clientConfig, @NotNull KubeApiConnection connection) {
String username = connection.getCustomParameter(USERNAME);
String password = connection.getCustomParameter(SECURE_PREFIX+PASSWORD);
return clientConfig.withUsername(username).withPassword(password);
}

@Override
public Collection<InvalidProperty> process(final Map<String, String> properties) {
Collection<InvalidProperty> retval = new ArrayList<>();
if (StringUtil.isEmpty(properties.get(USERNAME))){
retval.add(new InvalidProperty(USERNAME, "Username is required"));
}
if (StringUtil.isEmpty(properties.get(SECURE_PREFIX+ PASSWORD))){
retval.add(new InvalidProperty(PASSWORD, "Username is required"));
}
return retval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public KubeApiConnectorImpl(@NotNull String profileId, @NotNull KubeApiConnecti
myProfileId = profileId;
myConnectionSettings = connectionSettings;
myAuthStrategy = authStrategy;
myKubernetesClient = createClient(createConfig(myConnectionSettings, myAuthStrategy));
if(myAuthStrategy.getId().equalsIgnoreCase("openshift-user-passwd")) {
LOG.info("Creating OpenShift Client for User / Password Authentication");
myKubernetesClient = createClient(createConfig(myConnectionSettings, myAuthStrategy)).adapt(OpenShiftClient.class);
}
else {
LOG.info("Defaulting to kubernetes client for auth strategy");
myKubernetesClient = createClient(createConfig(myConnectionSettings, myAuthStrategy));
}

}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@
<span class="smallNote">Password of an authorized Kubernetes user</span>
</td>
</tr>
<tr class="hidden openshift-user-passwd auth-ui">
<th><label for="${cons.username}">Username:<l:star/></label></th>
<td><props:textProperty name="${cons.username}" className="longField"/>
<span id="error_${cons.username}" class="error"></span>
<span class="smallNote">Username of an authorized Kubernetes user</span>
</td>
</tr>
<tr class="hidden openshift-user-passwd auth-ui">
<th><label for="secure:${cons.password}">Password:<l:star/></label></th>
<td><props:passwordProperty name="secure:${cons.password}" className="longField"/>
<span id="error_secure:${cons.password}" class="error"></span>
<span class="smallNote">Password of an authorized Kubernetes user</span>
</td>
</tr>
<tr class="hidden client-cert auth-ui">
<th><label for="${cons.clientCertData}">Client certificate:<l:star/></label></th>
<td><props:multilineProperty name="secure:${cons.clientCertData}"
Expand Down