Skip to content

Commit

Permalink
Treat blank CA Cert data as null
Browse files Browse the repository at this point in the history
The Kubernetes Client appears to treat these differently. If using a null cert it appears it willm either fall back to trusting all certs or (more likely) using an auto-configured cert it finds within the pod from the service account auto mount files.

Currently there are weird inconsistencies as after you edit the config or restart the server it can set an empty string which starts causing validation failures talking to the API.
  • Loading branch information
chadlwilson committed Jan 6, 2024
1 parent b76ec96 commit d0981f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String getSecurityToken() {
}

public String getClusterCACertData() {
return clusterCACertData;
return clusterCACertData != null && clusterCACertData.isBlank() ? null : clusterCACertData;
}

public String getNamespace() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cd.go.contrib.secrets.kubernetes.models;

import cd.go.plugin.base.GsonTransformer;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class SecretConfigTest {

@Test
public void shouldConsiderBlankCertAsNull() {
final Map<String, Object> settings = new HashMap<>();
settings.put("kubernetes_cluster_ca_cert", " ");

SecretConfig config = GsonTransformer.fromJson(GsonTransformer.toJson(settings), SecretConfig.class);

assertThat(config.getClusterCACertData()).isNull();
}
}

0 comments on commit d0981f8

Please sign in to comment.