-
Notifications
You must be signed in to change notification settings - Fork 172
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
SNOW-1660591 Remove sensitive encryption info when logging #2077
Open
sfc-gh-ext-simba-jf
wants to merge
5
commits into
master
Choose a base branch
from
SNOW-1660591-Remove-Encryption-Storage-Info-In-Logs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f49b29
Parse out sensitive encryption material before logging json
sfc-gh-ext-simba-jf 9690ef0
Fix test failure
sfc-gh-ext-simba-jf 6f9d7cf
Merge branch 'master' into SNOW-1660591-Remove-Encryption-Storage-Inf…
sfc-gh-ext-simba-jf 7f1ced4
Changed implementation to use SecretDetector, added test
sfc-gh-ext-simba-jf 364cad9
Merge branch 'master' into SNOW-1660591-Remove-Encryption-Storage-Inf…
sfc-gh-ext-simba-jf 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 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 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 |
---|---|---|
|
@@ -79,6 +79,9 @@ public class SecretDetector { | |
"(token|assertion content)" + "(['\"\\s:=]+)" + "([a-z0-9=/_\\-+]{8,})", | ||
Pattern.CASE_INSENSITIVE); | ||
|
||
private static final Pattern ENCRYPTION_MATERIAL_PATTERN = | ||
Pattern.compile("\"encryptionMaterial\"\\s*:\\s*\\{.*?\\}", Pattern.CASE_INSENSITIVE); | ||
|
||
// only attempt to find secrets in its leading 100Kb SNOW-30961 | ||
private static final int MAX_LENGTH = 100 * 1000; | ||
|
||
|
@@ -283,6 +286,23 @@ public static String filterAccessTokens(String message) { | |
return message; | ||
} | ||
|
||
/** | ||
* Filter encryption material that may be buried inside a JSON string. | ||
* | ||
* @param message the message text which may contain encryption material | ||
* @return Return filtered message | ||
*/ | ||
public static String filterEncryptionMaterial(String message) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add this function as well to the chain in maskSecrets method? |
||
Matcher matcher = | ||
ENCRYPTION_MATERIAL_PATTERN.matcher( | ||
message.length() <= MAX_LENGTH ? message : message.substring(0, MAX_LENGTH)); | ||
|
||
if (matcher.find()) { | ||
return matcher.replaceAll("\"encryptionMaterial\" : ****"); | ||
} | ||
return message; | ||
} | ||
|
||
public static JSONObject maskJsonObject(JSONObject json) { | ||
for (Map.Entry<String, Object> entry : json.entrySet()) { | ||
if (entry.getValue() instanceof String) { | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we replace that call with maskSecrets method? we want to replace any possible secrets