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

Do not discard auth command if no args #4122

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGELOG

### 5.12.3

#### Bugs
* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified

### 5.12.2 (2022-04-06)
* Fix #3582: SSL truststore can be loaded in FIPS enabled environments
* Fix #3797: Implement SchemaSwap; generate CRD from model not owned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,10 @@ protected static List<String> getAuthenticatorCommandFromExecConfig(ExecConfig e
List<String> argv = new ArrayList<>(Utils.getCommandPlatformPrefix());
command = getCommandWithFullyQualifiedPath(command, systemPathValue);
List<String> args = exec.getArgs();
if (args != null) {
argv.add(command + " " + String.join( " ", args));
if (args != null && !args.isEmpty()) {
command += " " + String.join(" ", args);
}
argv.add(command);
return argv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,29 @@ void testGetAuthenticatorCommandFromExecConfig() throws IOException {
assertEquals("api-eks.example.com", commandParts.get(6));
}

@Test
void testGetAuthenticatorCommandFromExecConfigNullArgs() throws IOException {
// Given
File commandFolder = Files.createTempDirectory("test").toFile();
File commandFile = new File(commandFolder, "gke-gcloud-auth-plugin");
String systemPathValue = getTestPathValue(commandFolder);
ExecConfig execConfigNoArgs = new ExecConfigBuilder()
.withApiVersion("client.authentication.k8s.io/v1alpha1")
.withCommand(commandFile.getPath())
.build();
// Simulate "user.exec.args: null" like e.g. in the configuration for the gke-gcloud-auth-plugin.
execConfigNoArgs.setArgs(null);

// When
List<String> processBuilderArgs = Config.getAuthenticatorCommandFromExecConfig(execConfigNoArgs, null, systemPathValue);

// Then
assertNotNull(processBuilderArgs);
assertEquals(3, processBuilderArgs.size());
assertPlatformPrefixes(processBuilderArgs);
assertEquals(commandFile.getPath(), processBuilderArgs.get(2));
}

private void assertPlatformPrefixes(List<String> processBuilderArgs) {
List<String> platformArgsExpected = Utils.getCommandPlatformPrefix();
assertEquals(platformArgsExpected.get(0), processBuilderArgs.get(0));
Expand Down