-
Notifications
You must be signed in to change notification settings - Fork 221
Integrate Secret Scanning from Microsoft.Security.Utilities
#8140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c74243e
add first simple cut at detecting secrets when calling push
scbedd a3aaebe
we are calling into this thing now. time to add a test for it
scbedd b99ef92
close enough to actually cause this thing to error
scbedd e7ade6a
secret scanner not passing the proper directory
scbedd b1a552f
move away from static, handle lowconfidence matches too
scbedd 3aa8530
git status
scbedd 55a8c1d
restore this to a working version
scbedd 3aecbc8
clarify how we're going to represent a check and how it passes through
scbedd 41b7523
Have an integration test defined. Now I need to finish generating fak…
scbedd 6b917bb
we have a test that is generating a fake secret, but that fake secret…
scbedd 76ba452
we are actually exercising the push protection now
scbedd d2d1a10
working through the 'scanned blah' issues
scbedd ce9b441
spacing adjustment
scbedd 1cb18ab
update formatting of error output
scbedd 1495872
invoke secret scanning in parallel
scbedd 8d3ce0d
merge main
scbedd ed2006f
commit the fixes without testing
scbedd 80f3a05
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Console/ConsoleWrap…
scbedd d8cf94e
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Console/ConsoleWrap…
scbedd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SecretScanner.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Sdk.Tools.TestProxy.Console; | ||
| using Microsoft.Build.Tasks; | ||
| using Microsoft.Security.Utilities; | ||
|
|
||
| namespace Azure.Sdk.Tools.TestProxy.Common | ||
| { | ||
| public class SecretScanner | ||
| { | ||
| public SecretMasker SecretMasker = new SecretMasker( | ||
| WellKnownRegexPatterns.HighConfidenceMicrosoftSecurityModels.Concat(WellKnownRegexPatterns.LowConfidencePotentialSecurityKeys), | ||
| generateCorrelatingIds: true); | ||
|
|
||
| private IConsoleWrapper Console; | ||
|
|
||
| public SecretScanner(IConsoleWrapper consoleWrapper) | ||
| { | ||
| Console = consoleWrapper; | ||
| } | ||
|
|
||
| public List<Tuple<string, Detection>> DiscoverSecrets(string assetRepoRoot, IEnumerable<string> relativePaths) | ||
| { | ||
| var detectedSecrets = new ConcurrentBag<Tuple<string, Detection>>(); | ||
| var total = relativePaths.Count(); | ||
| var seen = 0; | ||
| Console.WriteLine(string.Empty); | ||
|
|
||
| var options = new ParallelOptions | ||
| { | ||
| MaxDegreeOfParallelism = Environment.ProcessorCount | ||
| }; | ||
|
|
||
| Parallel.ForEach(relativePaths, options, (filePath) => | ||
| { | ||
| var content = File.ReadAllText(Path.Combine(assetRepoRoot, filePath)); | ||
| var fileDetections = DetectSecrets(content); | ||
|
|
||
| if (fileDetections != null && fileDetections.Count > 0) | ||
| { | ||
| foreach (Detection detection in fileDetections) | ||
| { | ||
| detectedSecrets.Add(Tuple.Create(filePath, detection)); | ||
| } | ||
| } | ||
|
|
||
| Interlocked.Increment(ref seen); | ||
|
|
||
| Console.Write($"\r\u001b[2KScanned {seen}/{total}."); | ||
| }); | ||
|
|
||
| Console.WriteLine(string.Empty); | ||
|
|
||
| return detectedSecrets.ToList(); | ||
| } | ||
|
|
||
| private async Task<string> ReadFile(string filePath) | ||
| { | ||
| using (StreamReader reader = new StreamReader(filePath)) | ||
| { | ||
| return await reader.ReadToEndAsync(); | ||
| } | ||
| } | ||
|
|
||
| private ICollection<Detection> DetectSecrets(string stringContent) | ||
| { | ||
| return SecretMasker.DetectSecrets(stringContent); | ||
| } | ||
|
|
||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
tools/test-proxy/Azure.Sdk.Tools.TestProxy/Console/ConsoleWrapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| | ||
|
|
||
| using System; | ||
|
|
||
| namespace Azure.Sdk.Tools.TestProxy.Console | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tools/test-proxy/Azure.Sdk.Tools.TestProxy/Console/IConsoleWrapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.