Skip to content

Commit af66466

Browse files
committed
fix(client): Handle buddy secrets that don't have the expected password field in the k8s secret data.
1 parent 1928fcc commit af66466

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

kubernetes-orchestrator-extension/Jobs/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private Dictionary<string, List<string>> HandleJKSSecret(JobConfiguration config
323323
KubeNamespace + " and key " + keyName);
324324
var keyPassword = getK8SStorePassword(k8sData.Secret);
325325
var passwordHash = GetSHA256Hash(keyPassword);
326-
Logger.LogTrace("Password hash for '{Secret}/{Key}': {Hash}", KubeSecretName, keyName, passwordHash);
326+
// Logger.LogTrace("Password hash for '{Secret}/{Key}': {Hash}", KubeSecretName, keyName, passwordHash);
327327
var keyAlias = keyName;
328328
Logger.LogTrace("Key alias: {Alias}", keyAlias);
329329
Logger.LogDebug("Attempting to deserialize JKS store '{Secret}/{Key}'", KubeSecretName, keyName);

kubernetes-orchestrator-extension/Jobs/JobBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,17 @@ protected string getK8SStorePassword(V1Secret certData)
12371237

12381238
Logger.LogDebug("Attempting to read K8S buddy secret");
12391239
var k8sPasswordObj = KubeClient.ReadBuddyPass(passwordSecretName, passwordNamespace);
1240-
storePasswordBytes = k8sPasswordObj.Data[PasswordFieldName];
1240+
Logger.LogTrace("Secret response fields: {Keys}", k8sPasswordObj.Data.Keys);
1241+
1242+
if (!k8sPasswordObj.Data.TryGetValue(PasswordFieldName, out storePasswordBytes) ||
1243+
storePasswordBytes == null)
1244+
{
1245+
Logger.LogError("Unable to find password field {FieldName}", PasswordFieldName);
1246+
throw new InvalidK8SSecretException(
1247+
$"Unable to find password field '{PasswordFieldName}' in secret '{passwordSecretName}' in namespace '{passwordNamespace}'"
1248+
);
1249+
}
1250+
12411251
// var passwordHash = GetSHA256Hash(Encoding.UTF8.GetString(storePasswordBytes));
12421252
// Logger.LogTrace("Password hash: {Pwd}", passwordHash);
12431253
if (storePasswordBytes == null)

kubernetes-orchestrator-extension/Jobs/Management.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ private V1Secret HandleJksSecret(ManagementJobConfiguration config, bool remove
230230
Logger.LogDebug("StorePassword is not null or empty so setting StorePassword to config.CertificateStoreDetails.StorePassword");
231231
StorePassword = config.CertificateStoreDetails.StorePassword;
232232
var hashedStorePassword = GetSHA256Hash(StorePassword);
233-
Logger.LogTrace("hashedStorePassword: {Hash}", hashedStorePassword);
233+
// Logger.LogTrace("hashedStorePassword: {Hash}", hashedStorePassword);
234234
}
235235
Logger.LogDebug("Getting store password");
236236
var sPass = getK8SStorePassword(k8sData.Secret);
237237
var hashedSPass = GetSHA256Hash(sPass);
238-
Logger.LogTrace("hashedStorePassword: {Hash}", hashedSPass);
238+
// Logger.LogTrace("hashedStorePassword: {Hash}", hashedSPass);
239239
Logger.LogDebug("Calling CreateOrUpdateJks()...");
240240
try
241241
{

0 commit comments

Comments
 (0)