Skip to content
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(aws vault): Fix default sanitizer hashcode append logic #148

Merged
merged 8 commits into from Dec 1, 2023
Merged

fix(aws vault): Fix default sanitizer hashcode append logic #148

merged 8 commits into from Dec 1, 2023

Conversation

ghost
Copy link

@ghost ghost commented Nov 24, 2023

What this PR changes/adds

This changes the logic on how an hashcode is appended to a key after it is sanitized, during secrets manager vault store/retrieve/delete methods.

Why it does that

The current implementation of the default sanitizer strategy appends an hashcode to the secret key every time the store/retrieve/delete methods are used. While this has no impact for new secrets created by the vault, the vault fails to find existing secrets that were created previously either by AWS Console, CLI, another SDK, etc...
In such cases where the secret already exists, the sanization should have no effect in the given key.
The key should have an hashcode appended only when:

  • It was changed because illegal characters where replaced;
  • The key was shortened because it had more than 512 characters;

Further notes

The tests where also adapted to be aligned with the changed logic.

Linked Issue(s)

Closes #133

@ghost ghost changed the title Fix Secrets Manager vault default sanitizer hashcode append logic fix( Secrets Manager vault): Fix default sanitizer hashcode append logic Nov 24, 2023
@ghost ghost changed the title fix( Secrets Manager vault): Fix default sanitizer hashcode append logic fix(Secrets Manager vault): Fix default sanitizer hashcode append logic Nov 24, 2023
@ghost ghost changed the title fix(Secrets Manager vault): Fix default sanitizer hashcode append logic fix(aws-vault): Fix default sanitizer hashcode append logic Nov 24, 2023
@ghost ghost changed the title fix(aws-vault): Fix default sanitizer hashcode append logic fix(aws vault): Fix default sanitizer hashcode append logic Nov 24, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9583449) 64.54% compared to head (b414533) 64.71%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   64.54%   64.71%   +0.16%     
==========================================
  Files          26       26              
  Lines         629      632       +3     
  Branches       28       28              
==========================================
+ Hits          406      409       +3     
  Misses        218      218              
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ndr-brt ndr-brt added the bug Something isn't working label Nov 27, 2023
Comment on lines 37 to 42
if (originalKey.length() > 500) {
boolean originalKeyReplaced = false;

if (originalKey.length() > 512) {
//Substring to 500, to add the 12 char hashcode
key = originalKey.substring(0, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get this 500/512 thing, looking at the tests seems like it's a sort of size limit for the key size, eventually it could be extracted as a constant called KEY_SIZE_LIMIT or something like that.
The comment is outdated (please adapt the code to being able to talk for itself)

for (int i = 0; i < key.length(); i++) {
var c = key.charAt(i);
if (!Character.isLetterOrDigit(c) && c != '/' && c != '_' && c != '+' && c != '.' && c != '@' && c != '-') {
replacedIllegalCharacters = true;
originalKeyReplaced = true;
sb.append('-');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the documentation says _ but the code does -. Is this an error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is for replacing invalidad characters in the original key to "-". (ex: example#key, replaced to example-key)
The hashcode is appended afterwards.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, i see the question now. Yes, the documentation was off.

@ghost ghost requested a review from ndr-brt November 30, 2023 13:38
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ndr-brt ndr-brt merged commit f7a4cba into eclipse-edc:main Dec 1, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sanitation Strategy in AWS Vault extension does not resolve manually created secrets
3 participants