diff --git a/pom.xml b/pom.xml index e0b6c65e40..660cc57df7 100644 --- a/pom.xml +++ b/pom.xml @@ -140,19 +140,6 @@ bcpkix-jdk18on ${bouncycastle.version} - - com.microsoft.azure - adal4j - 1.6.7 - true - - - - net.minidev - json-smart - 2.5.1 - true - com.amazonaws aws-java-sdk-sts diff --git a/util/pom.xml b/util/pom.xml index dc00ead12c..e88295ac2f 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -57,10 +57,6 @@ org.bouncycastle bcpkix-jdk18on - - com.microsoft.azure - adal4j - com.amazonaws aws-java-sdk-sts diff --git a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java index c8fb6c9aa9..f588f470f5 100644 --- a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java +++ b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java @@ -18,7 +18,6 @@ import com.google.gson.JsonParser; import io.kubernetes.client.persister.ConfigPersister; import io.kubernetes.client.util.authenticators.Authenticator; -import io.kubernetes.client.util.authenticators.AzureActiveDirectoryAuthenticator; import io.kubernetes.client.util.authenticators.GCPAuthenticator; import io.kubernetes.client.util.authenticators.OpenIDConnectAuthenticator; import java.io.File; @@ -79,7 +78,6 @@ public static void registerAuthenticator(Authenticator auth) { static { registerAuthenticator(new GCPAuthenticator()); - registerAuthenticator(new AzureActiveDirectoryAuthenticator()); registerAuthenticator(new OpenIDConnectAuthenticator()); } diff --git a/util/src/main/java/io/kubernetes/client/util/authenticators/AzureActiveDirectoryAuthenticator.java b/util/src/main/java/io/kubernetes/client/util/authenticators/AzureActiveDirectoryAuthenticator.java deleted file mode 100644 index bfedca2687..0000000000 --- a/util/src/main/java/io/kubernetes/client/util/authenticators/AzureActiveDirectoryAuthenticator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. -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 io.kubernetes.client.util.authenticators; - -import com.microsoft.aad.adal4j.AuthenticationContext; -import com.microsoft.aad.adal4j.AuthenticationResult; -import io.kubernetes.client.util.KubeConfig; -import java.net.MalformedURLException; -import java.util.Date; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -/** - * The Authenticator interface represents a plugin that can handle a specific type of authentication - * information (e.g. 'azure') - */ -public class AzureActiveDirectoryAuthenticator implements Authenticator { - static { - KubeConfig.registerAuthenticator(new AzureActiveDirectoryAuthenticator()); - } - - private static final String ACCESS_TOKEN = "access-token"; - private static final String EXPIRES_ON = "expires-on"; - private static final String TENANT_ID = "tenant-id"; - private static final String CLIENT_ID = "client-id"; - private static final String REFRESH_TOKEN = "refresh-token"; - - @Override - public String getName() { - return "azure"; - } - - @Override - public String getToken(Map config) { - return (String) config.get(ACCESS_TOKEN); - } - - @Override - public boolean isExpired(Map config) { - String expiresOn = (String) config.get(EXPIRES_ON); - if (expiresOn == null || expiresOn.length() == 0) { - return true; - } - Date expiry = new Date(Long.parseLong(expiresOn) * 1000); - return expiry.compareTo(new Date()) <= 0; - } - - @Override - public Map refresh(Map config) { - // TODO: Support national clouds! - String cloud = "https://login.microsoftonline.com"; - String tenantId = (String) config.get(TENANT_ID); - String authority = cloud + "/" + tenantId; - String clientId = (String) config.get(CLIENT_ID); - String refreshToken = (String) config.get(REFRESH_TOKEN); - - try { - AuthenticationContext context = - new AuthenticationContext(authority, true, Executors.newSingleThreadExecutor()); - Future resultFuture = - context.acquireTokenByRefreshToken(refreshToken, clientId, null); - AuthenticationResult result = resultFuture.get(); - config.put(ACCESS_TOKEN, result.getAccessToken()); - config.put(REFRESH_TOKEN, result.getRefreshToken()); - - return config; - - } catch (InterruptedException | MalformedURLException | ExecutionException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java b/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java index d3cfb10ee3..d855283de0 100644 --- a/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java +++ b/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java @@ -17,7 +17,6 @@ import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.GoogleCredentials; import io.kubernetes.client.util.authenticators.Authenticator; -import io.kubernetes.client.util.authenticators.AzureActiveDirectoryAuthenticator; import io.kubernetes.client.util.authenticators.GCPAuthenticator; import java.io.ByteArrayInputStream; import java.io.FileReader; @@ -210,30 +209,6 @@ void gcpAuthProviderExpiredTokenWithoutGCloud() { assertThat(kc.getCredentials()).containsEntry(KubeConfig.CRED_TOKEN_KEY, fakeToken); } - @Test - void azureAuthProvider() { - KubeConfig.registerAuthenticator(new AzureActiveDirectoryAuthenticator()); - String azureConfig = - "apiVersion: v1\n" - + "contexts:\n" - + "- context:\n" - + " user: aks-cluster\n" - + " name: foo-context\n" - + "current-context: foo-context\n" - + "users:\n" - + "- name: aks-cluster\n" - + " user:\n" - + " auth-provider:\n" - + " config:\n" - + " access-token: fake-azure-token\n" - + " expires-on: \"1841569394\"\n" - + " expiry-key: '{.credential.token_expiry}'\n" - + " token-key: '{.credential.access_token}'\n" - + " name: azure\n"; - KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(azureConfig)); - assertThat(kc.getCredentials()).containsEntry(KubeConfig.CRED_TOKEN_KEY, "fake-azure-token"); - } - @Test void namespace() { KubeConfig config = KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_TOKEN));