Skip to content

Commit 4a9ca8f

Browse files
committed
fix(logging): report only top exception message to avoid error truncation;
remove logging of sensitive info;
1 parent 104b008 commit 4a9ca8f

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

aws-acm-orchestrator/Jobs/Inventory.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ public Inventory(IPAMSecretResolver pam, ILogger<Inventory> logger)
5151
public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitInventoryUpdate submitInventoryUpdate)
5252
{
5353
Logger.MethodEntry();
54-
Logger.LogTrace($"Deserializing Cert Store Properties: {jobConfiguration.CertificateStoreDetails.Properties}");
54+
55+
Logger.LogTrace("Deserializing Store Properties to AuthCustomFieldParameters object.");
5556
AuthCustomFieldParameters customFields = JsonConvert.DeserializeObject<AuthCustomFieldParameters>(jobConfiguration.CertificateStoreDetails.Properties,
5657
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Populate });
57-
//
58-
// TODO: Prevent logging of credentials, changes to custom fields in this release means logging this object (AND Properties above) logs credentials!!
59-
//
60-
Logger.LogTrace($"Populated ACMCustomFields: {JsonConvert.SerializeObject(customFields)}");
58+
Logger.LogTrace("Deserialized Store Properties.");
6159

6260
AuthenticationParameters authParams = new AuthenticationParameters
6361
{
@@ -67,9 +65,23 @@ public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitIn
6765
};
6866

6967
Logger.LogTrace("Resolving AWS Credentials object.");
70-
AwsExtensionCredential providedCredentials = AuthUtilities.GetCredentials(authParams);
71-
68+
AwsExtensionCredential providedCredentials;
69+
try
70+
{
71+
providedCredentials = AuthUtilities.GetCredentials(authParams);
72+
}
73+
catch (Exception ex)
74+
{
75+
Logger.LogError("An error occurred while trying to get AWS Credentials.");
76+
return new JobResult
77+
{
78+
Result = OrchestratorJobStatusJobResult.Failure,
79+
JobHistoryId = jobConfiguration.JobHistoryId,
80+
FailureMessage = ex.Message
81+
};
82+
}
7283
Logger.LogTrace("AWS Credentials resolved. Performing Inventory.");
84+
7385
return PerformInventory(providedCredentials, jobConfiguration, submitInventoryUpdate);
7486
}
7587

aws-acm-orchestrator/Jobs/Management.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ public Management(IPAMSecretResolver pam, ILogger<Management> logger)
6363
public JobResult ProcessJob(ManagementJobConfiguration jobConfiguration)
6464
{
6565
Logger.MethodEntry();
66-
Logger.LogTrace($"Deserializing Cert Store Properties: {jobConfiguration.CertificateStoreDetails.Properties}");
66+
67+
Logger.LogTrace("Deserializing Store Properties to AuthCustomFieldParameters object.");
6768
AuthCustomFieldParameters customFields = JsonConvert.DeserializeObject<AuthCustomFieldParameters>(jobConfiguration.CertificateStoreDetails.Properties,
6869
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Populate });
69-
//
70-
// TODO: Prevent logging of credentials, changes to custom fields in this release means logging this object (AND Properties above) logs credentials!!
71-
//
72-
Logger.LogTrace($"Populated ACMCustomFields: {JsonConvert.SerializeObject(customFields)}");
70+
Logger.LogTrace("Deserialized Store Properties.");
7371

7472
AuthenticationParameters authParams = new AuthenticationParameters
7573
{
@@ -79,7 +77,21 @@ public JobResult ProcessJob(ManagementJobConfiguration jobConfiguration)
7977
};
8078

8179
Logger.LogTrace("Resolving AWS Credentials object.");
82-
AwsExtensionCredential providedCredentials = AuthUtilities.GetCredentials(authParams);
80+
AwsExtensionCredential providedCredentials;
81+
try
82+
{
83+
providedCredentials = AuthUtilities.GetCredentials(authParams);
84+
}
85+
catch (Exception ex)
86+
{
87+
Logger.LogError("An error occurred while trying to get AWS Credentials.");
88+
return new JobResult
89+
{
90+
Result = OrchestratorJobStatusJobResult.Failure,
91+
JobHistoryId = jobConfiguration.JobHistoryId,
92+
FailureMessage = ex.Message
93+
};
94+
}
8395
Logger.LogTrace("AWS Credentials resolved.");
8496

8597
// perform add or remove

0 commit comments

Comments
 (0)