Skip to content

Commit

Permalink
Add new properties IgnoredModules and IgnoredCmdlets to bypass unnece…
Browse files Browse the repository at this point in the history
…ssary secrets detection
  • Loading branch information
vidai-msft committed Jul 19, 2024
1 parent 426f0de commit 21fbd01
Show file tree
Hide file tree
Showing 38 changed files with 41 additions and 34 deletions.
11 changes: 6 additions & 5 deletions src/Accounts/Accounts/CommonModule/AzModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,14 @@ public void SanitizerHandler(object sanitizingObject, string telemetryId)
{
if (AzureSession.Instance.TryGetComponent<IOutputSanitizer>(nameof(IOutputSanitizer), out var outputSanitizer))
{
if (outputSanitizer?.RequireSecretsDetection == true)
_telemetry.TryGetValue(telemetryId, out var qos);
if (outputSanitizer != null
&& outputSanitizer.RequireSecretsDetection
&& !outputSanitizer.IgnoredModules.Contains(qos?.ModuleName)
&& !outputSanitizer.IgnoredCmdlets.Contains(qos?.CommandName))
{
outputSanitizer.Sanitize(sanitizingObject, out var telemetry);
if (_telemetry.TryGetValue(telemetryId, out var qos))
{
qos?.SanitizerInfo?.Combine(telemetry);
}
qos?.SanitizerInfo?.Combine(telemetry);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Accounts/Authentication/Sanitizer/OutputSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using Microsoft.Azure.Commands.Shared.Config;
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Providers;
using System.Linq;

namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer
{
Expand All @@ -37,6 +38,16 @@ public bool RequireSecretsDetection
}
}

public IEnumerable<string> IgnoredModules => Enumerable.Empty<string>();

public IEnumerable<string> IgnoredCmdlets => new[]
{
"Get-AzActivityLog",
"Get-AzComputeResourceSku",
"Get-AzConsumptionUsageDetail",
"Get-AzDeployment",
};

public void Sanitize(object sanitizingObject, out SanitizerTelemetry telemetry)
{
var watch = Stopwatch.StartNew();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,7 @@ private bool IsOfTypeCustomObject(Type type)

private bool IsIgnoredProperty(string typeName, string propertyName)
{
bool ignored = false;

if (Service.IgnoredProperties.ContainsKey(typeName))
{
ignored = Service.IgnoredProperties[typeName].Contains(propertyName);
}

return ignored;
return Service.IgnoredProperties.TryGetValue(typeName, out var propertyNames) && propertyNames.Contains(propertyName);
}

private SanitizerProviderBase CreateCustomObjectProvider(Type objType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
{
internal class DefaultSanitizerService : ISanitizerService
{
public Dictionary<string, IEnumerable<string>> IgnoredProperties => new Dictionary<string, IEnumerable<string>>()
public IReadOnlyDictionary<string, IEnumerable<string>> IgnoredProperties => new Dictionary<string, IEnumerable<string>>()
{
/*
* This dictionary is used to store the properties that should be ignored during sanitization.
Expand All @@ -35,9 +35,11 @@ internal class DefaultSanitizerService : ISanitizerService
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare", new[] { "ShareProperties" } },
{ "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory", new[] { "ShareDirectoryProperties" } },

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

// Storage
// Skip infinite recursion properties
{ "Microsoft.Azure.Storage.Blob.CloudBlobDirectory", new[] { "Parent" } },
{ "Microsoft.Azure.Storage.File.CloudFileDirectory", new[] { "Parent" } },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
{
public interface ISanitizerService
{
Dictionary<string, IEnumerable<string>> IgnoredProperties { get; }
IReadOnlyDictionary<string, IEnumerable<string>> IgnoredProperties { get; }

bool TrySanitizeData(string data, out string sanitizedData);
}
Expand Down
34 changes: 17 additions & 17 deletions tools/Common.Netcore.Dependencies.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.24"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.98-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
Expand All @@ -37,7 +37,7 @@
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.98-preview\tools\</StorageToolsPath>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.0.0-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 21fbd01

Please sign in to comment.