Skip to content

Support an unencrypted encryption scheme#766

Closed
SamBarker wants to merge 3 commits intokroxylicious:mainfrom
SamBarker:selectEnccryptionScheme
Closed

Support an unencrypted encryption scheme#766
SamBarker wants to merge 3 commits intokroxylicious:mainfrom
SamBarker:selectEnccryptionScheme

Conversation

@SamBarker
Copy link
Copy Markdown
Member

Type of change

Select the type of your PR

  • Bugfix
  • Enhancement / new feature

Description

Changes the kekSelection contract so that the KekSelector can mark a record as un-encrypted.

Additional Context

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Write tests
  • Make sure all tests pass
  • Review performance test results. Ensure that any degradations to performance numbers are understood and justified.
  • Make sure all Sonar-Lint warnings are addressed or are justifiably ignored.
  • Update documentation
  • Reference relevant issue(s) and close them after merging
  • For user facing changes, update CHANGELOG.md (remember to include changes affecting the API of the test artefacts too).

Signed-off-by: Sam Barker <[email protected]>

rh-pre-commit.version: 2.0.1
rh-pre-commit.check-secrets: ENABLED
Signed-off-by: Sam Barker <[email protected]>

rh-pre-commit.version: 2.0.1
rh-pre-commit.check-secrets: ENABLED
})
.thenApply(kekId -> new Pair<>(topicName, kekId)))
.toList();
return EnvelopeEncryptionFilter.join(collect).thenApply(list -> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This change means we stop having a meaningful null value.

*/
public abstract @NonNull CompletionStage<Map<String, K>> selectKek(@NonNull Set<String> topicNames);
}
public abstract @NonNull CompletionStage<Map<String, EncryptionScheme<K>>> selectKek(@NonNull Set<String> topicNames);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this really means the class/interface should be renamed from KekSelector to EncryptionSchemeSelector or something else which implies more than just selecting Kek's.

Objects.requireNonNull(recordFields);
}

public static <K> EncryptionScheme<K> unencryptedScheme(K kekId) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The existence of this factory implies we should also have
RecordScheme(K kekId) and RecordAndHeadersScheme(K kekId)

Which feels strange to say the least.

So maybe instead of/as well as giving meaning to the empty set we should expand RecordField it include None?

cc: @tombentley

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So maybe instead of/as well as giving meaning to the empty set we should expand RecordField it include None?

How would you disallow meaningless combinations Set.of(NONE,RECORD_VALUE)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How would you disallow meaningless combinations Set.of(NONE,RECORD_VALUE)?

On the one hand I ask why do we need to disallow it? Just because it doesn't have obvious value to us doesn't mean it should be banned. Maybe there is a some future usage where that could be useful. Also looking at our current usage there is no reason to ban the combination as we pick specific types to operate on.

On the other hand your right as an API it does invite people to setup strange and potentially contradictory instructions.

public CompletionStage<Map<String, EncryptionScheme<K>>> selectKek(@NonNull Set<String> topicNames) {
return CompletableFuture.completedFuture(encryptionSchemesByTopicName.entrySet()
.stream()
.filter(entry -> topicNames.contains(entry.getKey()))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The lack of this filer was leading to my original issue however it was much harder to fix with a semantically valid null.

@NonNull
CompletionStage<K> resolveAlias(@NonNull String alias);

K unEncryptedKekId();
Copy link
Copy Markdown
Member

@k-wall k-wall Dec 1, 2023

Choose a reason for hiding this comment

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

Please add Javadoc. @nullable? The camelisation of the method name is unusual too.
Is this a sentinel value that represents the the unencrypted case? I think that might be awkward for KMSs that use string values for key names. An empty string doesn't seem like a great choice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that capitalisation is definitely odd, I'll update.

Is this a sentinel value that represents the the unencrypted case?
Yes, its a function of having the KekId as a generic type rather than an interface that the implementations provide.

I think that might be awkward for KMSs that use string values for key names. An empty string doesn't seem like a great choice.

Yes it is awkward for String keys, but they are free to pick anything including __UNENCRYPTERD__ or **PLAINTESXT** which would probably work quite well if it showed up in logs.

Signed-off-by: Sam Barker <[email protected]>

rh-pre-commit.version: 2.0.1
rh-pre-commit.check-secrets: ENABLED
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.4% 94.4% Coverage
0.0% 0.0% Duplication

Copy link
Copy Markdown
Member

@k-wall k-wall left a comment

Choose a reason for hiding this comment

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

lgtm

@SamBarker
Copy link
Copy Markdown
Member Author

I think the output of the conversations around #774 is that 774 represents a better starting point for fixing the null handling but a version of this idea could be the final solution to conveying the state.

@SamBarker SamBarker closed this Dec 12, 2023
@SamBarker SamBarker deleted the selectEnccryptionScheme branch August 16, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants