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

Add check and test for invalid DEK rotation expiry #2801

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,21 @@ protected KekInfo getKek(RuleContext ctx, String kekName) throws RuleException {
return kek;
}

private int getDekExpiryDays(RuleContext ctx) {
private int getDekExpiryDays(RuleContext ctx) throws RuleException {
String expiryStr = ctx.getParameter(ENCRYPT_DEK_EXPIRY_DAYS);
if (expiryStr == null || expiryStr.isEmpty()) {
return 0;
}
int dekExpiryDays;
try {
return Integer.parseInt(expiryStr);
dekExpiryDays = Integer.parseInt(expiryStr);
} catch (NumberFormatException e) {
return 0;
throw new RuleException("Invalid value for " + ENCRYPT_DEK_EXPIRY_DAYS + ": " + expiryStr);
}
if (dekExpiryDays < 0) {
throw new RuleException("Invalid value for " + ENCRYPT_DEK_EXPIRY_DAYS + ": " + expiryStr);
}
return dekExpiryDays;
}

private KekInfo retrieveKekFromRegistry(RuleContext ctx, KekId key) throws RuleException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,23 @@ record = (GenericRecord) avroDeserializer.deserialize(topic, headers, bytes);
assertEquals(3, dek.getVersion());
}

@Test(expected = SerializationException.class)
public void testKafkaAvroDekRotationInvalidExpiry() throws Exception {
IndexedRecord avroRecord = createUserRecord();
AvroSchema avroSchema = new AvroSchema(createUserSchema());
Rule rule = new Rule("rule1", null, null, null,
FieldEncryptionExecutor.TYPE, ImmutableSortedSet.of("PII"),
ImmutableMap.of("encrypt.dek.expiry.days", "-1", "preserve.source.fields", "true"),
null, null, null, false);
RuleSet ruleSet = new RuleSet(Collections.emptyList(), ImmutableList.of(rule));
Metadata metadata = getMetadata("kek1");
avroSchema = avroSchema.copy(metadata, ruleSet);
schemaRegistry.register(topic + "-value", avroSchema);

RecordHeaders headers = new RecordHeaders();
avroSerializer.serialize(topic, headers, avroRecord);
}

@Test
public void testKafkaAvroSerializerWithAlgorithm() throws Exception {
IndexedRecord avroRecord = createUserRecord();
Expand Down