Skip to content

Commit 508b8c0

Browse files
authored
Implement new interface properties IgnoredModules and IgnoredCmdlets to bypass unnecessary secrets detection (#25594)
1 parent 39db20f commit 508b8c0

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

src/Accounts/Accounts/CommonModule/AzModule.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,14 @@ public void SanitizerHandler(object sanitizingObject, string telemetryId)
368368
{
369369
if (AzureSession.Instance.TryGetComponent<IOutputSanitizer>(nameof(IOutputSanitizer), out var outputSanitizer))
370370
{
371-
if (outputSanitizer?.RequireSecretsDetection == true)
371+
_telemetry.TryGetValue(telemetryId, out var qos);
372+
if (outputSanitizer != null
373+
&& outputSanitizer.RequireSecretsDetection
374+
&& !outputSanitizer.IgnoredModules.Contains(qos?.ModuleName)
375+
&& !outputSanitizer.IgnoredCmdlets.Contains(qos?.CommandName))
372376
{
373377
outputSanitizer.Sanitize(sanitizingObject, out var telemetry);
374-
if (_telemetry.TryGetValue(telemetryId, out var qos))
375-
{
376-
qos?.SanitizerInfo?.Combine(telemetry);
377-
}
378+
qos?.SanitizerInfo?.Combine(telemetry);
378379
}
379380
}
380381
}

src/Accounts/Authentication/Sanitizer/OutputSanitizer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System;
2020
using Microsoft.Azure.Commands.Shared.Config;
2121
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Providers;
22+
using System.Linq;
2223

2324
namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer
2425
{
@@ -37,6 +38,15 @@ public bool RequireSecretsDetection
3738
}
3839
}
3940

41+
public IEnumerable<string> IgnoredModules => Enumerable.Empty<string>();
42+
43+
public IEnumerable<string> IgnoredCmdlets => new[]
44+
{
45+
"Get-AzActivityLog",
46+
"Get-AzComputeResourceSku",
47+
"Get-AzConsumptionUsageDetail",
48+
};
49+
4050
public void Sanitize(object sanitizingObject, out SanitizerTelemetry telemetry)
4151
{
4252
var watch = Stopwatch.StartNew();

src/Accounts/Authentication/Sanitizer/Providers/DefaultProviderResolver.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,7 @@ private bool IsOfTypeCustomObject(Type type)
184184

185185
private bool IsIgnoredProperty(string typeName, string propertyName)
186186
{
187-
bool ignored = false;
188-
189-
if (Service.IgnoredProperties.ContainsKey(typeName))
190-
{
191-
ignored = Service.IgnoredProperties[typeName].Contains(propertyName);
192-
}
193-
194-
return ignored;
187+
return Service.IgnoredProperties.TryGetValue(typeName, out var propertyNames) && propertyNames.Contains(propertyName);
195188
}
196189

197190
private SanitizerProviderBase CreateCustomObjectProvider(Type objType)

src/Accounts/Authentication/Sanitizer/Services/DefaultSanitizerService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
1919
{
2020
internal class DefaultSanitizerService : ISanitizerService
2121
{
22-
public Dictionary<string, IEnumerable<string>> IgnoredProperties => new Dictionary<string, IEnumerable<string>>()
22+
public IReadOnlyDictionary<string, IEnumerable<string>> IgnoredProperties => new Dictionary<string, IEnumerable<string>>()
2323
{
2424
/*
2525
* This dictionary is used to store the properties that should be ignored during sanitization.
@@ -35,9 +35,11 @@ internal class DefaultSanitizerService : ISanitizerService
3535
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare", new[] { "ShareProperties" } },
3636
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory", new[] { "ShareDirectoryProperties" } },
3737

38-
// Skip infinite recursion properties that cause performance concern
38+
// Skip large properties
39+
{ "Microsoft.Azure.Storage.Blob.CloudBlob", new[] { "ICloudBlob" } },
40+
{ "Microsoft.Azure.Storage.File.CloudFile", new[] { "CloudFile" } },
3941

40-
// Storage
42+
// Skip infinite recursion properties
4143
{ "Microsoft.Azure.Storage.Blob.CloudBlobDirectory", new[] { "Parent" } },
4244
{ "Microsoft.Azure.Storage.File.CloudFileDirectory", new[] { "Parent" } },
4345
};

src/Accounts/Authentication/Sanitizer/Services/ISanitizerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
1818
{
1919
public interface ISanitizerService
2020
{
21-
Dictionary<string, IEnumerable<string>> IgnoredProperties { get; }
21+
IReadOnlyDictionary<string, IEnumerable<string>> IgnoredProperties { get; }
2222

2323
bool TrySanitizeData(string data, out string sanitizedData);
2424
}

tools/Common.Netcore.Dependencies.targets

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
<ItemGroup>
44
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.24"/>
55
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
6-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.98-preview"/>
7-
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.98-preview"/>
8-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.98-preview"/>
9-
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.98-preview"/>
10-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.98-preview"/>
11-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.98-preview"/>
12-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.98-preview"/>
13-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.98-preview"/>
14-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.98-preview"/>
15-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.98-preview"/>
16-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.98-preview"/>
17-
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.98-preview"/>
18-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.98-preview"/>
19-
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.98-preview"/>
20-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.98-preview"/>
21-
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.98-preview"/>
6+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.99-preview"/>
7+
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.99-preview"/>
8+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.99-preview"/>
9+
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.99-preview"/>
10+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.99-preview"/>
11+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.99-preview"/>
12+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.99-preview"/>
13+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.99-preview"/>
14+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.99-preview"/>
15+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.99-preview"/>
16+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.99-preview"/>
17+
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.99-preview"/>
18+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.99-preview"/>
19+
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.99-preview"/>
20+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.99-preview"/>
21+
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.99-preview"/>
2222
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2323
</ItemGroup>
2424
<ItemGroup>
@@ -37,7 +37,7 @@
3737
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
3838
</ItemGroup>
3939
<PropertyGroup>
40-
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.98-preview\tools\</StorageToolsPath>
40+
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.99-preview\tools\</StorageToolsPath>
4141
</PropertyGroup>
4242
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
4343
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>

0 commit comments

Comments
 (0)