Skip to content

Commit

Permalink
Implement new interface properties IgnoredModules and IgnoredCmdlets …
Browse files Browse the repository at this point in the history
…to bypass unnecessary secrets detection (Azure#25594)
  • Loading branch information
vidai-msft authored Jul 25, 2024
1 parent 39db20f commit 508b8c0
Show file tree
Hide file tree
Showing 6 changed files with 40 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
10 changes: 10 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,15 @@ public bool RequireSecretsDetection
}
}

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

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

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.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.99-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.99-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.3.99-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
Expand Down

0 comments on commit 508b8c0

Please sign in to comment.