Feature/secrets with complexity #1511
Open
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.
Copied from #1510
Description
this PR make sure secrets are generated with crypto rand function for optimal randomness and that they at least include a lower, upper case + decimal + special characters , which is usually a requirement for regulated context like PCI (and a good practise in general)
Key Changes
files modified pkg/splunk/common/names.go -> add more const variables for lower case, upper case, decimal and special characters
pkg/splunk/util/util.go pkg/splunk/util/util_test.go , pkg/splunk/util/secrets.go ,pkg/splunk/util/secrets_test.go
add GenerateSecretPartWithComplexity function , which choose m times a character for the SecretBytes passed as argument at a random position in the byte array (but checking it is not yet used position)
add GenerateSecretWithComplexity(n int, minlower int, minupper int, mindecimal int, minspecial int) fucntion
which for a n size secrets will :
GenerateSecret function is still there but only used for HEC
it is now using the crypto rand function also (you cant have different rand in the same file and this is more secure anyway to use the crypto version)
updated the code to call the GenerateSecretWithComplexity with 24 lentgh (as before) and 1 complexity for each type
Testing and Verification
How did you test these changes? What automated tests are added?
updated tests
added a test that verify we produce a error if ask more complexity than secrets length
manual tests
Related Issues
Yes, customer issue discussed internally
Jira tickets, GitHub issues, Support tickets...
PR Checklist