-
Notifications
You must be signed in to change notification settings - Fork 733
Fix erroneous removal of secret prefixes in SecretSource #2007
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
Fix erroneous removal of secret prefixes in SecretSource #2007
Conversation
This is initially WIP, with a failing test that shows the problem. |
Digging deeper, the code flow inside // if var = 'arn:aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
public String lookup(String var) {
if (var == null) {
return null;
}
final int prefixPos = var.indexOf(PREFIX_SEPARATOR); // prefixPos = 3
if (prefixPos >= 0) {
final String prefix = toKey(var.substring(0, prefixPos)); // prefix = 'arn'
final String name = var.substring(prefixPos + 1); // name = 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
final StringLookup lookup = stringLookupMap.get(prefix); // lookup = null (because there is no CasC handler for 'arn' prefixes)
String value = null;
if (lookup != null) { // statement is skipped
value = lookup.lookup(name);
}
if (value != null) { // statement is skipped
return value;
}
var = var.substring(prefixPos + 1); // var = 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
}
if (defaultStringLookup != null) {
return defaultStringLookup.lookup(var); // ...and the SecretSource implementations are asked to find 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
}
return null;
} |
The bug is located here. Yes, we could write our own string lookup. var = var.substring(prefixPos + 1); // var = 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret' |
Do you think it's worth reporting this as a bug upstream in |
(And potentially filing a PR to fix this upstream?) |
If the maintainer says it is not a bug at least a fix could also be to have lookup option to preserve prefix or remove prefix. Though I honestly think this is a bug. This should not remove the prefix! // if var = 'arn:aws:secretsmanager:eu-central-1:123456789012:secret:my-secret', preservePrefix = true
public String lookup(String var, boolean preservePrefix) {
if (var == null) {
return null;
}
final int prefixPos = var.indexOf(PREFIX_SEPARATOR); // prefixPos = 3
if (prefixPos >= 0) {
final String prefix = toKey(var.substring(0, prefixPos)); // prefix = 'arn'
final String name = var.substring(prefixPos + 1); // name = 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
final StringLookup lookup = stringLookupMap.get(prefix); // lookup = null (because there is no CasC handler for 'arn' prefixes)
String value = null;
if (lookup != null) { // statement is skipped
value = lookup.lookup(name);
}
if (value != null) { // statement is skipped
return value;
}
if (preservePrefix == false) {
var = var.substring(prefixPos + 1); // var = 'aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
}
}
if (defaultStringLookup != null) {
return defaultStringLookup.lookup(var); // ...and the SecretSource implementations are asked to find 'arn:aws:secretsmanager:eu-central-1:123456789012:secret:my-secret'
}
return null;
} |
@chriskilding I decided to implement a fix to unblock this 😅 |
We have decent test coverage that I feel comfortable with this change. @timja @oleg-nenashev WDYT |
Codecov Report
@@ Coverage Diff @@
## master #2007 +/- ##
============================================
- Coverage 80.89% 80.86% -0.03%
- Complexity 837 844 +7
============================================
Files 71 72 +1
Lines 2465 2488 +23
Branches 346 351 +5
============================================
+ Hits 1994 2012 +18
- Misses 362 365 +3
- Partials 109 111 +2
|
Only remove secret prefixes when they correspond to one of the SecretSource protocol substitutors (e.g.
base64:
,file:
). If a secret prefix is not handled by the substitutors, leave it alone.fixes #1949
Your checklist for this pull request
🚨 Please review the guidelines for contributing to this repository.