Skip to content

Commit 96fd238

Browse files
vidai-msftisra-fel
andauthored
Implement new interface IAzurePSSanitizer and ISanitizerService for secrets detection feature (#24249)
* Register IAzurePSSanitizer and ISanitizerService components and implement the functions defined in the interfaces. * Upload new localfeed and test coverage pipeline to test all scenario tests * Update live test to include sanitizer * Register IAzurePSSanitizer and ISanitizerService components and implement the functions defined in the interfaces. * Enable secrets warning on CI * Add local build of common lib * Move secrets detection related objects from common repo to Authentication * Add change log * Update config docs and fix issues * Update src/Accounts/Accounts/ChangeLog.md Co-authored-by: Yeming Liu <[email protected]> --------- Co-authored-by: Yeming Liu <[email protected]>
1 parent 2230c53 commit 96fd238

27 files changed

+1067
-26
lines changed

.azure-pipelines/powershell-core.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ variables:
2020
EnableTestCoverage: true
2121
TestCoverageLocation: $(Build.SourcesDirectory)/artifacts
2222
PowerShellPlatform: PowerShell Core
23+
AZURE_CLIENTS_SHOW_SECRETS_WARNING: true
2324

2425
trigger: none
2526

.azure-pipelines/windows-powershell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ variables:
1212
EnableTestCoverage: true
1313
TestCoverageLocation: $(Build.SourcesDirectory)/artifacts
1414
PowerShellPlatform: Windows PowerShell
15+
AZURE_CLIENTS_SHOW_SECRETS_WARNING: true
1516

1617
trigger: none
1718

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
using Microsoft.Azure.PowerShell.Common.Share.Survey;
4747
using Microsoft.Azure.Commands.Profile.Utilities;
4848
using System.Management.Automation.Runspaces;
49+
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
50+
using Microsoft.Azure.Commands.Common.Authentication.Sanitizer;
4951

5052
namespace Microsoft.Azure.Commands.Profile
5153
{
@@ -787,6 +789,7 @@ public void OnImport()
787789
AzureSession.Instance.RegisterComponent(nameof(AzureCredentialFactory), () => new AzureCredentialFactory());
788790
AzureSession.Instance.RegisterComponent(nameof(MsalAccessTokenAcquirerFactory), () => new MsalAccessTokenAcquirerFactory());
789791
AzureSession.Instance.RegisterComponent<ISshCredentialFactory>(nameof(ISshCredentialFactory), () => new SshCredentialFactory());
792+
AzureSession.Instance.RegisterComponent<IOutputSanitizer>(nameof(IOutputSanitizer), () => new OutputSanitizer());
790793
#if DEBUG || TESTCOVERAGE
791794
AzureSession.Instance.RegisterComponent<ITestCoverage>(nameof(ITestCoverage), () => new TestCoverage());
792795
#endif

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added a preview feature to detect secrets and sensitive information from the output of Azure PowerShell cmdlets to prevent leakage. Enable it by `Set-AzConfig -DisplaySecretsWarning $true`. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844
2223
* Fixed `CacheDirectory` and `CacheFile` out-of-sync issue in AzureRmContextSettings.json and the customers are not allowed to change these 2 properties.
2324
* Redirected device code login messages from warning stream to information stream if use device authentication in `Connect-AzAccount`.
2425

src/Accounts/Accounts/help/Clear-AzConfig.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Clear-AzConfig [-Force] [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
2121
### ClearByKey
2222
```
2323
Clear-AzConfig [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
24-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-CheckForUpgrade]
25-
[-DefaultSubscriptionForLogin] [-DisableErrorRecordsPersistence] [-DisplayBreakingChangeWarning]
26-
[-DisplayRegionIdentified] [-DisplaySurveyMessage] [-EnableDataCollection] [-EnableLoginByWam]
27-
[<CommonParameters>]
24+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
25+
[-CheckForUpgrade] [-DefaultSubscriptionForLogin] [-DisableErrorRecordsPersistence]
26+
[-DisplayBreakingChangeWarning] [-DisplayRegionIdentified] [-DisplaySecretsWarning]
27+
[-DisplaySurveyMessage] [-EnableDataCollection] [-EnableLoginByWam] [<CommonParameters>]
2828
```
2929

3030
## DESCRIPTION
@@ -161,6 +161,21 @@ Accept pipeline input: False
161161
Accept wildcard characters: False
162162
```
163163
164+
### -DisplaySecretsWarning
165+
When enabled, a warning message will be displayed when the cmdlet output contains secrets. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844
166+
167+
```yaml
168+
Type: System.Management.Automation.SwitchParameter
169+
Parameter Sets: ClearByKey
170+
Aliases:
171+
172+
Required: False
173+
Position: Named
174+
Default value: None
175+
Accept pipeline input: False
176+
Accept wildcard characters: False
177+
```
178+
164179
### -DisplaySurveyMessage
165180
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
166181

src/Accounts/Accounts/help/Get-AzConfig.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Gets the configs of Azure PowerShell.
1515
```
1616
Get-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
1717
[-CheckForUpgrade] [-DefaultSubscriptionForLogin] [-DisableErrorRecordsPersistence]
18-
[-DisplayBreakingChangeWarning] [-DisplayRegionIdentified] [-DisplaySurveyMessage] [-EnableDataCollection]
19-
[-EnableLoginByWam] [<CommonParameters>]
18+
[-DisplayBreakingChangeWarning] [-DisplayRegionIdentified] [-DisplaySecretsWarning]
19+
[-DisplaySurveyMessage] [-EnableDataCollection] [-EnableLoginByWam] [<CommonParameters>]
2020
```
2121

2222
## DESCRIPTION
@@ -172,6 +172,21 @@ Accept pipeline input: False
172172
Accept wildcard characters: False
173173
```
174174
175+
### -DisplaySecretsWarning
176+
When enabled, a warning message will be displayed when the cmdlet output contains secrets. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844
177+
178+
```yaml
179+
Type: System.Management.Automation.SwitchParameter
180+
Parameter Sets: (All)
181+
Aliases:
182+
183+
Required: False
184+
Position: Named
185+
Default value: None
186+
Accept pipeline input: False
187+
Accept wildcard characters: False
188+
```
189+
175190
### -DisplaySurveyMessage
176191
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
177192

src/Accounts/Accounts/help/Update-AzConfig.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Updates the configs of Azure PowerShell.
1616
Update-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
1717
[-WhatIf] [-Confirm] [-CheckForUpgrade <Boolean>] [-DefaultSubscriptionForLogin <String>]
1818
[-DisableErrorRecordsPersistence <Boolean>] [-DisplayBreakingChangeWarning <Boolean>]
19-
[-DisplayRegionIdentified <Boolean>] [-DisplaySurveyMessage <Boolean>] [-EnableDataCollection <Boolean>]
19+
[-DisplayRegionIdentified <Boolean>] [-DisplaySecretsWarning <Boolean>]
20+
[-DisplaySurveyMessage <Boolean>] [-EnableDataCollection <Boolean>]
2021
[-EnableLoginByWam <Boolean>] [<CommonParameters>]
2122
```
2223

@@ -69,6 +70,19 @@ EnableDataCollection True Az CurrentUser When enabled, Azure PowerShell
6970
Sets the "EnableDataCollection" config as "$true". This enables sending the telemetry data.
7071
Setting this config is equivalent to `Enable-AzDataCollection` and `Disable-AzDataCollection`.
7172

73+
### Example 4
74+
```powershell
75+
Update-AzConfig -DisplaySecretsWarning $true
76+
```
77+
78+
```output
79+
Key Value Applies To Scope Help Message
80+
--- ----- ---------- ----- ------------
81+
DisplaySecretsWarning True Az CurrentUser When enabled, a warning message for secrets redaction will be displ…
82+
```
83+
84+
Sets the "DisplaySecretsWarning" config as "$true". This enables the secrets detection during the cmdlet execution and displays a warning message if any secrets are found in the output.
85+
7286
## PARAMETERS
7387

7488
### -AppliesTo
@@ -184,6 +198,21 @@ Accept pipeline input: True (ByPropertyName)
184198
Accept wildcard characters: False
185199
```
186200
201+
### -DisplaySecretsWarning
202+
When enabled, a warning message will be displayed when the cmdlet output contains secrets. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844
203+
204+
```yaml
205+
Type: System.Boolean
206+
Parameter Sets: (All)
207+
Aliases:
208+
209+
Required: False
210+
Position: Named
211+
Default value: None
212+
Accept pipeline input: True (ByPropertyName)
213+
Accept wildcard characters: False
214+
```
215+
187216
### -DisplaySurveyMessage
188217
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
189218
@@ -286,10 +315,10 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
286315
287316
## INPUTS
288317
289-
### System.String
290-
291318
### System.Boolean
292319
320+
### System.String
321+
293322
## OUTPUTS
294323
295324
### Microsoft.Azure.Commands.Profile.Models.PSConfig

src/Accounts/Authentication/Config/ConfigInitializer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ private void RegisterConfigs(IConfigManager configManager)
226226
configManager.RegisterConfig(new EnableLoginByWamConfig());
227227
configManager.RegisterConfig(new EnableInterceptSurveyConfig());
228228
configManager.RegisterConfig(new DisplayBreakingChangeWarningsConfig());
229+
configManager.RegisterConfig(new SimpleTypedConfig<bool>(
230+
ConfigKeys.DisplaySecretsWarning,
231+
Resources.HelpMessageOfDisplaySecretsWarning,
232+
false,
233+
"AZURE_CLIENTS_SHOW_SECRETS_WARNING",
234+
new[] { AppliesTo.Az }));
229235
}
230236
}
231237
}

src/Accounts/Authentication/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Accounts/Authentication/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,7 @@
402402
<data name="FailedToMigrateMsalCacheWithLegayName" xml:space="preserve">
403403
<value>INITIALIZATION: Failed to migrate MSAL token cache of the legacy name with error : {0}</value>
404404
</data>
405+
<data name="HelpMessageOfDisplaySecretsWarning" xml:space="preserve">
406+
<value>When enabled, a warning message will be displayed when the cmdlet output contains secrets. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844</value>
407+
</data>
405408
</root>

0 commit comments

Comments
 (0)