feat(firehose): add StartDeliveryStreamEncryption and StopDeliveryStreamEncryption (#2583)

* feat(firehose): add Start/StopDeliveryStreamEncryption

Models DeliveryStreamEncryptionConfiguration on the stream description so
the encryption state set by Start is visible to Describe and cleared by Stop.
Limitations documented in docs/services/firehose.md.

* fix(firehose): keep the key identity on StopDeliveryStreamEncryption and reject Start without an encryption input

- Stopping customer-managed encryption now preserves KeyType and KeyARN with
  Status DISABLED, matching what DescribeDeliveryStream reports on real AWS.
- Streams persisted before the encryption field existed deserialize to the
  AWS-shaped DISABLED default instead of null via a field-level initializer.
- StartDeliveryStreamEncryption without DeliveryStreamEncryptionConfigurationInput
  is now rejected with InvalidArgumentException instead of silently defaulting.

* fix(firehose): reject a KeyARN that is not a KMS key ARN

StartDeliveryStreamEncryption stored DeliveryStreamEncryptionConfigurationInput's
KeyARN verbatim, so a bare key id or an alias ARN was accepted and then reported
back by DescribeDeliveryStream as the stream's encryption key. botocore pins
AWSKMSKeyARNForSSE to arn:.*:kms:<region>:<12-digit account>:key/<id> with a
512-character cap; anything else is an InvalidArgumentException on real AWS.

* fix(firehose): enforce the modeled input constraints on the pre-existing operations

DeliveryStreamType is now checked against the modeled enum, and Tags,
Records and TagKeys against their modeled list bounds (1-50, 1-500,
1-50), all answering InvalidArgumentException as the operations model.
Previously all four were accepted verbatim. Included here because this
PR already carries wire-shape hardening for the same handler; found by
a model-grounded constraint sweep.

* fix(firehose): treat StartDeliveryStreamEncryption input as optional

DeliveryStreamEncryptionConfigurationInput is Required: No in the model; omitting
it is the documented way to enable SSE with the service-owned key and defaults
KeyType to AWS_OWNED_CMK. The prior null-input rejection regressed that path -
inverted the pinning test to assert the 200/AWS_OWNED_CMK behavior.
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-08-27 16:48:12 -04:00
1 parent 20ecb89155
commit 4affa05cea
6 files changed
+458 -8

No files matched your search

@@ -0,0 +1,102 @@
package io.github.hectorvent.floci.services.firehose;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/**
* Wire-level enforcement of the input constraints the 2015-08-04 model pins on
* the pre-existing Firehose operations: the DeliveryStreamType enum, and the
* list bounds on Tags (1-50), Records (1-500) and TagKeys (1-50). All of these
* were previously accepted verbatim.
*/
@QuarkusTest
class FirehoseInputConstraintConsumerTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
private static final String TARGET_PREFIX = "Firehose_20150804.";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private static Response call(String action, String body) {
return given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + action)
.body(body)
.when()
.post("/");
}
private static void createStream(String name) {
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"" + name + "\"}")
.then().statusCode(200);
}
private static String tagArray(int n) {
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(',');
}
sb.append("{\"Key\":\"k").append(i).append("\",\"Value\":\"v\"}");
}
return sb.append(']').toString();
}
@Test
void createDeliveryStream_unknownType_returnsInvalidArgument() {
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"ab-badtype\","
+ "\"DeliveryStreamType\":\"CarrierPigeon\"}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
}
@Test
void createDeliveryStream_tooManyTags_returnsInvalidArgument() {
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"ab-manytags\","
+ "\"Tags\":" + tagArray(51) + "}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
}
@Test
void putRecordBatch_emptyRecords_returnsInvalidArgument() {
createStream("ab-batch-empty");
call("PutRecordBatch", "{\"DeliveryStreamName\":\"ab-batch-empty\",\"Records\":[]}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
}
@Test
void tagDeliveryStream_emptyAndOversizedTags_returnInvalidArgument() {
createStream("ab-tag-bounds");
call("TagDeliveryStream", "{\"DeliveryStreamName\":\"ab-tag-bounds\",\"Tags\":[]}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
call("TagDeliveryStream", "{\"DeliveryStreamName\":\"ab-tag-bounds\",\"Tags\":" + tagArray(51) + "}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
}
@Test
void untagDeliveryStream_emptyTagKeys_returnsInvalidArgument() {
createStream("ab-untag-bounds");
call("UntagDeliveryStream", "{\"DeliveryStreamName\":\"ab-untag-bounds\",\"TagKeys\":[]}")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
}
}
@@ -127,6 +127,213 @@ class FirehoseIntegrationTest {
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(6)
void startAndStopDeliveryStreamEncryption() {
String encryptionStream = "encryption-stream-" + System.currentTimeMillis();
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
String keyArn = "arn:aws:kms:us-east-1:123456789012:key/test-key";
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": { \"KeyType\": \"CUSTOMER_MANAGED_CMK\", \"KeyARN\": \""
+ keyArn + "\" } }")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
equalTo("CUSTOMER_MANAGED_CMK"))
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyARN",
equalTo(keyArn))
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
equalTo("ENABLED"));
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.StopDeliveryStreamEncryption")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
equalTo("DISABLED"))
// Disabling must not erase the key identity: real AWS keeps reporting the
// stopped stream's KeyType and customer KeyARN.
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
equalTo("CUSTOMER_MANAGED_CMK"))
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyARN",
equalTo("arn:aws:kms:us-east-1:123456789012:key/test-key"));
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
@Order(8)
void startDeliveryStreamEncryptionWithoutInputDefaultsToAwsOwnedCmk() {
// DeliveryStreamEncryptionConfigurationInput is optional (Required: No) - omitting
// it is the documented way to enable SSE with the service-owned key, not an error.
String encryptionStream = "encryption-noinput-" + System.currentTimeMillis();
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
equalTo("ENABLED"))
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
equalTo("AWS_OWNED_CMK"));
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
@Order(7)
void startDeliveryStreamEncryptionWithoutCustomerKeyReturnsInvalidArgument() {
String encryptionStream = "encryption-validation-" + System.currentTimeMillis();
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": { \"KeyType\": \"CUSTOMER_MANAGED_CMK\" } }")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
@Order(9)
void startDeliveryStreamEncryptionWithMalformedKeyArnReturnsInvalidArgument() {
String encryptionStream = "encryption-badarn-" + System.currentTimeMillis();
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
// botocore pins AWSKMSKeyARNForSSE to
// arn:.*:kms:<region>:<12-digit account>:key/<id> — a bare key id is not a KeyARN,
// and storing it would make DescribeDeliveryStream report a key that cannot exist.
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": "
+ "{ \"KeyType\": \"CUSTOMER_MANAGED_CMK\", \"KeyARN\": \"not-an-arn\" } }")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"));
// The rejected call must not have enabled encryption on the stream.
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
equalTo("DISABLED"));
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
@Order(16)
void describeDeliveryStreamReturnsKinesisSourceConfiguration() {