Skip to content

Commit 4d447cc

Browse files
authored
Merge 37cffe0 into 2147c31
2 parents 2147c31 + 37cffe0 commit 4d447cc

File tree

6 files changed

+140
-405
lines changed

6 files changed

+140
-405
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.1.3
2+
3+
## Bug Fixes
4+
- fix(base): Add additional logging to debug issue with K8SNS store type.
5+
- fix(client): Handle skip TLS flag when passed to a job.
6+
7+
## Chores:
8+
- chore(deps): Bump `Keyfactor.Logging` to `v1.1.2`
9+
- chore(deps): Bump `Keyfactor.PKI` to `v5.5.0`
10+
111
# 1.1.2
212

313
## Bug Fixes

kubernetes-orchestrator-extension/Clients/KubeClient.cs

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.Collections.Generic;
10+
using System.Configuration;
1011
using System.IO;
1112
using System.Linq;
1213
using System.Net;
@@ -84,14 +85,15 @@ private K8SConfiguration ParseKubeConfig(string kubeconfig, bool skipTLSVerify =
8485
{
8586
_logger.LogTrace("Entered ParseKubeConfig()");
8687
var k8SConfiguration = new K8SConfiguration();
87-
88+
8889
_logger.LogTrace("Checking if kubeconfig is null or empty");
8990
if (string.IsNullOrEmpty(kubeconfig))
9091
{
9192
_logger.LogError("kubeconfig is null or empty");
92-
throw new KubeConfigException("kubeconfig is null or empty, please provide a valid kubeconfig in JSON format. For more information on how to create a kubeconfig file, please visit https://github.com/Keyfactor/k8s-orchestrator/tree/main/scripts/kubernetes#example-service-account-json");
93+
throw new KubeConfigException(
94+
"kubeconfig is null or empty, please provide a valid kubeconfig in JSON format. For more information on how to create a kubeconfig file, please visit https://github.com/Keyfactor/k8s-orchestrator/tree/main/scripts/kubernetes#example-service-account-json");
9395
}
94-
96+
9597
try
9698
{
9799
// test if kubeconfig is base64 encoded
@@ -118,10 +120,11 @@ private K8SConfiguration ParseKubeConfig(string kubeconfig, bool skipTLSVerify =
118120
if (!kubeconfig.StartsWith("{"))
119121
{
120122
_logger.LogError("kubeconfig is not a JSON object");
121-
throw new KubeConfigException("kubeconfig is not a JSON object, please provide a valid kubeconfig in JSON format. For more information on how to create a kubeconfig file, please visit: https://github.com/Keyfactor/k8s-orchestrator/tree/main/scripts/kubernetes#get_service_account_credssh");
123+
throw new KubeConfigException(
124+
"kubeconfig is not a JSON object, please provide a valid kubeconfig in JSON format. For more information on how to create a kubeconfig file, please visit: https://github.com/Keyfactor/k8s-orchestrator/tree/main/scripts/kubernetes#get_service_account_credssh");
122125
// return k8SConfiguration;
123-
}
124-
126+
}
127+
125128

126129
_logger.LogDebug("Parsing kubeconfig as a dictionary of string, string");
127130

@@ -151,18 +154,21 @@ private K8SConfiguration ParseKubeConfig(string kubeconfig, bool skipTLSVerify =
151154
_logger.LogTrace("Creating Cluster object for cluster '{Name}'", clusterMetadata["name"]?.ToString());
152155
// get environment variable for skip tls verify and convert to bool
153156
var skipTlsEnvStr = Environment.GetEnvironmentVariable("KEYFACTOR_ORCHESTRATOR_SKIP_TLS_VERIFY");
154-
_logger.LogTrace("KEYFACTOR_ORCHESTRATOR_SKIP_TLS_VERIFY environment variable: {SkipTlsVerify}", skipTlsEnvStr);
155-
if (!string.IsNullOrEmpty(skipTlsEnvStr) && (bool.TryParse(skipTlsEnvStr, out var skipTlsVerifyEnv) || skipTlsEnvStr == "1"))
157+
_logger.LogTrace("KEYFACTOR_ORCHESTRATOR_SKIP_TLS_VERIFY environment variable: {SkipTlsVerify}",
158+
skipTlsEnvStr);
159+
if (!string.IsNullOrEmpty(skipTlsEnvStr) &&
160+
(bool.TryParse(skipTlsEnvStr, out var skipTlsVerifyEnv) || skipTlsEnvStr == "1"))
156161
{
157162
if (skipTlsEnvStr == "1") skipTlsVerifyEnv = true;
158163
_logger.LogDebug("Setting skip-tls-verify to {SkipTlsVerify}", skipTlsVerifyEnv);
159164
if (skipTlsVerifyEnv && !skipTLSVerify)
160165
{
161-
_logger.LogWarning("Skipping TLS verification is enabled in environment variable KEYFACTOR_ORCHESTRATOR_SKIP_TLS_VERIFY this takes the highest precedence and verification will be skipped. To disable this, set the environment variable to 'false' or remove it");
166+
_logger.LogWarning(
167+
"Skipping TLS verification is enabled in environment variable KEYFACTOR_ORCHESTRATOR_SKIP_TLS_VERIFY this takes the highest precedence and verification will be skipped. To disable this, set the environment variable to 'false' or remove it");
162168
skipTLSVerify = true;
163169
}
164170
}
165-
171+
166172
var clusterObj = new Cluster
167173
{
168174
Name = clusterMetadata["name"]?.ToString(),
@@ -173,7 +179,8 @@ private K8SConfiguration ParseKubeConfig(string kubeconfig, bool skipTLSVerify =
173179
SkipTlsVerify = skipTLSVerify
174180
}
175181
};
176-
_logger.LogTrace("Adding cluster '{Name}'({@Endpoint}) to K8SConfiguration", clusterObj.Name, clusterObj.ClusterEndpoint);
182+
_logger.LogTrace("Adding cluster '{Name}'({@Endpoint}) to K8SConfiguration", clusterObj.Name,
183+
clusterObj.ClusterEndpoint);
177184
k8SConfiguration.Clusters = new List<Cluster> { clusterObj };
178185
}
179186

@@ -220,7 +227,7 @@ private K8SConfiguration ParseKubeConfig(string kubeconfig, bool skipTLSVerify =
220227

221228
_logger.LogTrace("Finished parsing contexts");
222229
_logger.LogDebug("Finished parsing kubeconfig");
223-
230+
224231
return k8SConfiguration;
225232
}
226233

@@ -240,7 +247,7 @@ private IKubernetes GetKubeClient(string kubeconfig)
240247
_logger.LogDebug("Calling ParseKubeConfig()");
241248
var k8SConfiguration = ParseKubeConfig(kubeconfig);
242249
_logger.LogDebug("Finished calling ParseKubeConfig()");
243-
250+
244251
// use k8sConfiguration over credentialFileName
245252
KubernetesClientConfiguration config;
246253
if (k8SConfiguration != null) // Config defined in store parameters takes highest precedence
@@ -258,7 +265,9 @@ private IKubernetes GetKubeClient(string kubeconfig)
258265
config = KubernetesClientConfiguration.BuildDefaultConfig();
259266
}
260267
}
261-
else if (string.IsNullOrEmpty(credentialFileName)) // If no config defined in store parameters, use default config. This should never happen though.
268+
else if
269+
(string.IsNullOrEmpty(
270+
credentialFileName)) // If no config defined in store parameters, use default config. This should never happen though.
262271
{
263272
_logger.LogWarning(
264273
"No config defined in store parameters, using default config. This should never happen!");
@@ -1800,7 +1809,7 @@ public List<string> DiscoverSecrets(string[] allowedKeys, string secType, string
18001809
_logger.LogTrace("Client BaseUrl: {BaseUrl}", Client.BaseUri);
18011810
_logger.LogDebug("Calling CoreV1.ListNamespace()");
18021811
namespaces = Client.CoreV1.ListNamespace();
1803-
1812+
18041813
_logger.LogDebug("returned from CoreV1.ListNamespace()");
18051814
_logger.LogTrace("namespaces.Items.Count: {Count}", namespaces.Items.Count);
18061815
_logger.LogTrace("namespaces.Items: {Items}", namespaces.Items.ToString());
@@ -1816,7 +1825,8 @@ public List<string> DiscoverSecrets(string[] allowedKeys, string secType, string
18161825
if (nsLi != "all" && nsLi != nsObj.Metadata.Name)
18171826
{
18181827
_logger.LogWarning(
1819-
"Skipping namespace '{Namespace}' because it does not match the namespace filter", nsObj.Metadata.Name);
1828+
"Skipping namespace '{Namespace}' because it does not match the namespace filter",
1829+
nsObj.Metadata.Name);
18201830
continue;
18211831
}
18221832

@@ -1977,6 +1987,28 @@ public List<string> DiscoverSecrets(string[] allowedKeys, string secType, string
19771987
return locations;
19781988
}
19791989

1990+
public struct JksSecret
1991+
{
1992+
public string SecretPath;
1993+
public string SecretFieldName;
1994+
public V1Secret Secret;
1995+
public string Password;
1996+
public string PasswordPath;
1997+
public List<string> AllowedKeys;
1998+
public Dictionary<string, byte[]> Inventory;
1999+
}
2000+
2001+
public struct Pkcs12Secret
2002+
{
2003+
public string SecretPath;
2004+
public string SecretFieldName;
2005+
public V1Secret Secret;
2006+
public string Password;
2007+
public string PasswordPath;
2008+
public List<string> AllowedKeys;
2009+
public Dictionary<string, byte[]> Inventory;
2010+
}
2011+
19802012
public JksSecret GetJksSecret(string secretName, string namespaceName, string password = null,
19812013
string passwordPath = null, List<string> allowedKeys = null)
19822014
{
@@ -2170,7 +2202,7 @@ public CsrObject GenerateCertificateRequest(string name, string[] sans, IPAddres
21702202
X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature,
21712203
false));
21722204
request.CertificateExtensions.Add(
2173-
new X509EnhancedKeyUsageExtension(new OidCollection { new("1.3.6.1.5.5.7.3.1") }, false));
2205+
new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false));
21742206
request.CertificateExtensions.Add(sanBuilder.Build());
21752207
var csr = request.CreateSigningRequest();
21762208
var csrPem = "-----BEGIN CERTIFICATE REQUEST-----\r\n" +
@@ -2291,28 +2323,6 @@ public V1Secret CreateOrUpdatePkcs12Secret(Pkcs12Secret k8SData, string kubeSecr
22912323
return Client.CoreV1.ReplaceNamespacedSecret(s1, kubeSecretName, kubeNamespace);
22922324
}
22932325

2294-
public struct JksSecret
2295-
{
2296-
public string SecretPath;
2297-
public string SecretFieldName;
2298-
public V1Secret Secret;
2299-
public string Password;
2300-
public string PasswordPath;
2301-
public List<string> AllowedKeys;
2302-
public Dictionary<string, byte[]> Inventory;
2303-
}
2304-
2305-
public struct Pkcs12Secret
2306-
{
2307-
public string SecretPath;
2308-
public string SecretFieldName;
2309-
public V1Secret Secret;
2310-
public string Password;
2311-
public string PasswordPath;
2312-
public List<string> AllowedKeys;
2313-
public Dictionary<string, byte[]> Inventory;
2314-
}
2315-
23162326
public struct CsrObject
23172327
{
23182328
public string Csr;

kubernetes-orchestrator-extension/Jobs/Inventory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
5151
Logger.LogInformation("Begin INVENTORY for K8S Orchestrator Extension for job " + config.JobId);
5252
Logger.LogInformation($"Inventory for store type: {config.Capability}");
5353

54-
Logger.LogDebug($"Server: {KubeClient.GetHost()}");
55-
Logger.LogDebug($"Store Path: {StorePath}");
56-
Logger.LogDebug("KubeSecretType: " + KubeSecretType);
57-
Logger.LogDebug("KubeSecretName: " + KubeSecretName);
58-
Logger.LogDebug("KubeNamespace: " + KubeNamespace);
59-
Logger.LogDebug("Host: " + KubeClient.GetHost());
54+
Logger.LogDebug("Server: {Host}", KubeClient.GetHost());
55+
Logger.LogDebug("Store Path: {StorePath}", StorePath);
56+
Logger.LogDebug("KubeSecretType: {KubeSecretType}", KubeSecretType);
57+
Logger.LogDebug("KubeSecretName: {KubeSecretName}", KubeSecretName);
58+
Logger.LogDebug("KubeNamespace: {KubeNamespace}", KubeNamespace);
59+
Logger.LogDebug("Host: {Host}", KubeClient.GetHost());
6060

6161
Logger.LogTrace("Inventory entering switch based on KubeSecretType: " + KubeSecretType + "...");
6262

0 commit comments

Comments
 (0)