mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): reconcile a named secret in place on UpdateStack (#4299)
* fix(cloudformation): reconcile a named secret in place on UpdateStack SecretsManagerCfnProvisioner called CreateSecret on every provision, so an identical UpdateStack of a named AWS::SecretsManager::Secret rolled back with "A secret with the name ... already exists", the failure mode of #2134. The provisioner now adopts the prior secret: a same-named secret (or a generated name, kept stable) is reconciled where it stands, description and KMS key through UpdateSecret, tags driven to the template, an explicit SecretString that differs from the current value as a new version, and a GenerateSecretString value left alone so a no-op update does not rotate it. A changed Name is the replacement the registry schema defines. Tags and KmsKeyId now reach the create call too. CloudFormationNamedResourceIdenticalUpdateIntegrationTest runs create, an identical update and a delete for 36 resource types that carry an explicit create-only name, so a named type cannot regress this quietly; the secret was the one of the 36 that did. Closes #2134 * fix(cloudformation): generate a secret value when an update switches from SecretString to GenerateSecretString Provisioning with SecretString removed FlociSecretGenerateIdentity, so the next update could not tell a pre-upgrade record from an explicit value and skipped generation. Record "none" instead; only an absent attribute is treated as a legacy record that keeps its value. * fix(cloudformation): generate for a pre-upgrade secret switching to GenerateSecretString Records persisted before FlociSecretGenerateIdentity existed cannot say whether the prior template used SecretString. Keep the current value only when it has the shape the GenerateSecretString config produces; otherwise generate, as main did through createSecret. * fix(cloudformation): always generate for a pre-upgrade secret with GenerateSecretString The current value cannot show whether a legacy record's prior template used SecretString or a different generation policy, so the length and template-shape check could keep a value that should have been regenerated. Generate on the first update instead; main never kept such a value across an update, since it called createSecret each time.
This commit is contained in:
1 parent
09276c75dc
commit
a777879518
4 files changed
+705
-5
No files matched your search
+160
-5
@@ -12,7 +12,11 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -30,6 +34,18 @@ import java.util.Set;
|
||||
public class SecretsManagerCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
private static final String TYPE = "AWS::SecretsManager::Secret";
|
||||
/** Whether the secret's name came from the template or was generated, so a removed explicit name replaces. */
|
||||
private static final String NAME_MODE_ATTR = "FlociSecretNameMode";
|
||||
private static final String NAME_MODE_EXPLICIT = "explicit";
|
||||
private static final String NAME_MODE_GENERATED = "generated";
|
||||
/** The GenerateSecretString configuration the current value was generated from, so only a change regenerates. */
|
||||
private static final String GENERATE_IDENTITY_ATTR = "FlociSecretGenerateIdentity";
|
||||
/**
|
||||
* Recorded when the value did not come from GenerateSecretString, so a later switch to it is a
|
||||
* change that generates. An absent attribute means a record from before this was tracked.
|
||||
*/
|
||||
private static final String GENERATE_IDENTITY_NONE = "none";
|
||||
private static final int GENERATED_NAME_SUFFIX_LENGTH = 12;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SecretsManagerCfnProvisioner.class);
|
||||
|
||||
@@ -63,19 +79,158 @@ public class SecretsManagerCfnProvisioner implements CfnResourceProvisioner {
|
||||
deleteSecretSafe(physicalId, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, or on {@code UpdateStack} reconcile in place. {@code Name} is the only create-only
|
||||
* property in the registry schema, so a secret whose name is unchanged (or was generated and
|
||||
* is therefore kept stable) is updated where it stands: description, KMS key and tags are
|
||||
* driven to the template, an explicit {@code SecretString} that differs from the current
|
||||
* value becomes a new version, and a changed {@code GenerateSecretString} configuration
|
||||
* generates a new one (the registry's update handler holds {@code GetRandomPassword} for
|
||||
* exactly that), while an unchanged one leaves the value alone so a no-op update does not
|
||||
* rotate the password. A changed explicit name, or an explicit name dropped from the
|
||||
* template, is a replacement, as on AWS: a new secret is created and the engine removes the
|
||||
* displaced one.
|
||||
*/
|
||||
private void provisionSecret(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String region = ctx.region();
|
||||
String name = ctx.resolveOptional(props, "Name");
|
||||
if (name == null || name.isBlank()) {
|
||||
Secret prior = priorSecret(ctx.priorPhysicalId(), region);
|
||||
String explicitName = ctx.resolveOptional(props, "Name");
|
||||
boolean hasExplicitName = explicitName != null && !explicitName.isBlank();
|
||||
String previousNameMode = r.getAttributes().get(NAME_MODE_ATTR);
|
||||
if (previousNameMode == null && prior != null) {
|
||||
// Stacks persisted before the mode was recorded: a generated name always has the shape
|
||||
// generatePhysicalName produces, so anything else must have been explicit.
|
||||
previousNameMode = isGeneratedName(prior.getName(), ctx.stackName(), r.getLogicalId())
|
||||
? NAME_MODE_GENERATED : NAME_MODE_EXPLICIT;
|
||||
}
|
||||
boolean explicitNameRemoved = prior != null && !hasExplicitName
|
||||
&& NAME_MODE_EXPLICIT.equals(previousNameMode);
|
||||
String name;
|
||||
if (hasExplicitName) {
|
||||
name = explicitName;
|
||||
} else if (prior != null && !explicitNameRemoved) {
|
||||
name = prior.getName();
|
||||
} else {
|
||||
name = ctx.generatePhysicalName(r.getLogicalId(), 512, false);
|
||||
}
|
||||
String description = ctx.resolveOptional(props, "Description");
|
||||
String value = resolveSecretValue(props, ctx);
|
||||
Secret secret = secretsManagerService.createSecret(name, value, null, description, null,
|
||||
List.of(), region);
|
||||
String kmsKeyId = ctx.resolveOptional(props, "KmsKeyId");
|
||||
Map<String, String> tags = ctx.resolveTags(props, "Tags");
|
||||
JsonNode generate = generateSecretStringNode(props, ctx);
|
||||
String generateIdentity = generate == null ? null : generate.toString();
|
||||
|
||||
Secret secret;
|
||||
if (prior != null && name.equals(prior.getName())) {
|
||||
secret = reconcileExisting(prior, props, description, kmsKeyId, tags, generate, generateIdentity,
|
||||
r.getAttributes().get(GENERATE_IDENTITY_ATTR), ctx);
|
||||
} else {
|
||||
String value = resolveSecretValue(props, ctx);
|
||||
secret = secretsManagerService.createSecret(name, value, null, description, kmsKeyId,
|
||||
tagList(tags), region);
|
||||
}
|
||||
r.setPhysicalId(secret.getArn());
|
||||
r.getAttributes().put("Arn", secret.getArn());
|
||||
r.getAttributes().put("Name", name);
|
||||
r.getAttributes().put(NAME_MODE_ATTR, hasExplicitName ? NAME_MODE_EXPLICIT : NAME_MODE_GENERATED);
|
||||
r.getAttributes().put(GENERATE_IDENTITY_ATTR,
|
||||
generateIdentity != null ? generateIdentity : GENERATE_IDENTITY_NONE);
|
||||
}
|
||||
|
||||
/** The resolved {@code GenerateSecretString} object, or null when the template has none. */
|
||||
private static JsonNode generateSecretStringNode(JsonNode props, ProvisionContext ctx) {
|
||||
if (props == null || !props.hasNonNull("GenerateSecretString")) {
|
||||
return null;
|
||||
}
|
||||
JsonNode resolved = ctx.engine().resolveNode(props.get("GenerateSecretString"));
|
||||
return resolved == null || resolved.isNull() ? null : resolved;
|
||||
}
|
||||
|
||||
/** Whether a name has the exact shape {@code generatePhysicalName} produces for this resource. */
|
||||
private static boolean isGeneratedName(String name, String stackName, String logicalId) {
|
||||
if (name == null || name.length() < GENERATED_NAME_SUFFIX_LENGTH + 1) {
|
||||
return false;
|
||||
}
|
||||
String suffix = name.substring(name.length() - GENERATED_NAME_SUFFIX_LENGTH);
|
||||
for (int i = 0; i < suffix.length(); i++) {
|
||||
char c = suffix.charAt(i);
|
||||
boolean hex = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
|
||||
if (!hex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String prefix = name.substring(0, name.length() - GENERATED_NAME_SUFFIX_LENGTH);
|
||||
String expected = stackName + "-" + logicalId + "-";
|
||||
return prefix.equals(expected) || (expected.startsWith(prefix) && prefix.endsWith("-"));
|
||||
}
|
||||
|
||||
private Secret priorSecret(String priorPhysicalId, String region) {
|
||||
if (priorPhysicalId == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return secretsManagerService.describeSecret(priorPhysicalId, region);
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
LOG.debugv("Prior secret {0} is gone; creating it afresh", priorPhysicalId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Secret reconcileExisting(Secret prior, JsonNode props, String description, String kmsKeyId,
|
||||
Map<String, String> tags, JsonNode generate, String generateIdentity,
|
||||
String priorGenerateIdentity, ProvisionContext ctx) {
|
||||
String region = ctx.region();
|
||||
String arn = prior.getArn();
|
||||
Secret secret = secretsManagerService.updateSecret(arn, description, kmsKeyId, region);
|
||||
String secretString = ctx.resolveOptional(props, "SecretString");
|
||||
if (secretString != null && !secretString.equals(currentValue(arn, region))) {
|
||||
secretsManagerService.putSecretValue(arn, secretString, null, null, region, null);
|
||||
} else if (secretString == null && generate != null
|
||||
&& generateConfigChanged(generateIdentity, priorGenerateIdentity)) {
|
||||
secretsManagerService.putSecretValue(arn, generateSecretString(generate), null, null, region, null);
|
||||
}
|
||||
Map<String, String> current = new LinkedHashMap<>();
|
||||
if (prior.getTags() != null) {
|
||||
for (Secret.Tag tag : prior.getTags()) {
|
||||
current.put(tag.key(), tag.value());
|
||||
}
|
||||
}
|
||||
List<String> stale = ProvisionContext.staleTagKeys(current, tags);
|
||||
if (!stale.isEmpty()) {
|
||||
secretsManagerService.untagResource(arn, stale, region);
|
||||
}
|
||||
if (!tags.isEmpty() && !tags.equals(current)) {
|
||||
secretsManagerService.tagResource(arn, tagList(tags), region);
|
||||
}
|
||||
return secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the value has to be regenerated for {@code generate}. A record persisted before the
|
||||
* identity was tracked has none to compare against, and nothing in the current value shows
|
||||
* whether its prior template used {@code SecretString} or a different generation policy, so
|
||||
* it generates. Before this reconciliation every update of such a secret replaced it with a
|
||||
* newly generated value or failed outright, so no stored value was ever kept.
|
||||
*/
|
||||
private static boolean generateConfigChanged(String generateIdentity, String priorGenerateIdentity) {
|
||||
return priorGenerateIdentity == null || !Objects.equals(generateIdentity, priorGenerateIdentity);
|
||||
}
|
||||
|
||||
private String currentValue(String arn, String region) {
|
||||
try {
|
||||
return secretsManagerService.getSecretValue(arn, null, null, region).getSecretString();
|
||||
} catch (AwsException e) {
|
||||
// A secret with no current version yet has nothing to compare against.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Secret.Tag> tagList(Map<String, String> tags) {
|
||||
List<Secret.Tag> list = new ArrayList<>();
|
||||
tags.forEach((key, value) -> list.add(new Secret.Tag(key, value)));
|
||||
return list;
|
||||
}
|
||||
|
||||
private void deleteSecretSafe(String secretId, String region) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@@ -17,6 +20,52 @@ final class CfnStackWaits {
|
||||
private CfnStackWaits() {
|
||||
}
|
||||
|
||||
/** What DescribeStacks reported: the status and, when present, the StackStatusReason. */
|
||||
record StackState(String status, String reason) {
|
||||
}
|
||||
|
||||
private static final Set<String> TERMINAL = Set.of(
|
||||
"CREATE_COMPLETE", "CREATE_FAILED", "ROLLBACK_COMPLETE", "ROLLBACK_FAILED",
|
||||
"UPDATE_COMPLETE", "UPDATE_FAILED", "UPDATE_ROLLBACK_COMPLETE", "UPDATE_ROLLBACK_FAILED",
|
||||
"DELETE_COMPLETE", "DELETE_FAILED");
|
||||
|
||||
/**
|
||||
* Waits until DescribeStacks reports a terminal status for a create or update and returns
|
||||
* it, so the caller decides what counts as success. A DescribeStacks that is not 200 (the
|
||||
* stack does not exist) fails at once with the error body rather than polling the clock out;
|
||||
* ten seconds without a terminal status fails too.
|
||||
*/
|
||||
static StackState awaitTerminal(String stackName) {
|
||||
long deadline = System.currentTimeMillis() + 10_000;
|
||||
StackState last = new StackState(null, "");
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
Response response = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/");
|
||||
if (response.statusCode() != 200) {
|
||||
fail("DescribeStacks " + stackName + " answered " + response.statusCode() + ": " + response.asString());
|
||||
}
|
||||
XmlPath xml = response.xmlPath();
|
||||
String status = xml.getString("**.find { it.name() == 'StackStatus' }");
|
||||
String reason = xml.getString("**.find { it.name() == 'StackStatusReason' }");
|
||||
last = new StackState(status == null || status.isEmpty() ? null : status, reason == null ? "" : reason);
|
||||
if (last.status() != null && TERMINAL.contains(last.status())) {
|
||||
return last;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new AssertionError("Interrupted while waiting for stack " + stackName, e);
|
||||
}
|
||||
}
|
||||
fail("Stack " + stackName + " reached no terminal status within ten seconds, last: " + last);
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until DescribeStacks answers 400, which is how a missing stack is reported. Fails on
|
||||
* DELETE_FAILED or after ten seconds.
|
||||
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* #2134: a resource with an explicit, create-only name must survive an identical UpdateStack
|
||||
* (reconciled in place, never re-created into "already exists") and a DeleteStack afterwards.
|
||||
* One stack per type, each with the smallest template the type accepts; parents a type needs
|
||||
* (a bucket, a key, a pool, an API) live in the same template. Docker-backed types are not here.
|
||||
* Waits go through {@link CfnStackWaits}: the operations run on an executor.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationNamedResourceIdenticalUpdateIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/probe-role";
|
||||
|
||||
record Case(String label, String template) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
static Stream<Case> cases() {
|
||||
return Stream.of(
|
||||
single("Logs::LogGroup", "AWS::Logs::LogGroup", "\"LogGroupName\":\"/probe/%s\",\"RetentionInDays\":7"),
|
||||
single("EC2::SecurityGroup", "AWS::EC2::SecurityGroup",
|
||||
"\"GroupName\":\"probe-sg-%s\",\"GroupDescription\":\"probe\""),
|
||||
single("CloudWatch::Alarm", "AWS::CloudWatch::Alarm",
|
||||
"\"AlarmName\":\"probe-alarm-%s\",\"ComparisonOperator\":\"GreaterThanThreshold\","
|
||||
+ "\"EvaluationPeriods\":1,\"MetricName\":\"CPUUtilization\",\"Namespace\":\"AWS/EC2\","
|
||||
+ "\"Period\":60,\"Statistic\":\"Average\",\"Threshold\":90"),
|
||||
new Case("CloudTrail::Trail", """
|
||||
{"Resources":{
|
||||
"B":{"Type":"AWS::S3::Bucket","Properties":{"BucketName":"probe-trail-%s"}},
|
||||
"T":{"Type":"AWS::CloudTrail::Trail","Properties":{"TrailName":"probe-trail-%s",
|
||||
"S3BucketName":{"Ref":"B"},"IsLogging":false}}}}"""),
|
||||
single("CodeBuild::Project", "AWS::CodeBuild::Project",
|
||||
"\"Name\":\"probe-build-%s\",\"ServiceRole\":\"" + ROLE_ARN + "\","
|
||||
+ "\"Artifacts\":{\"Type\":\"NO_ARTIFACTS\"},"
|
||||
+ "\"Environment\":{\"Type\":\"LINUX_CONTAINER\",\"ComputeType\":\"BUILD_GENERAL1_SMALL\","
|
||||
+ "\"Image\":\"aws/codebuild/standard:7.0\"},"
|
||||
+ "\"Source\":{\"Type\":\"NO_SOURCE\",\"BuildSpec\":\"version: 0.2\"}"),
|
||||
single("Config::ConfigRule", "AWS::Config::ConfigRule",
|
||||
"\"ConfigRuleName\":\"probe-rule-%s\","
|
||||
+ "\"Source\":{\"Owner\":\"AWS\",\"SourceIdentifier\":\"S3_BUCKET_VERSIONING_ENABLED\"}"),
|
||||
single("ECR::Repository", "AWS::ECR::Repository", "\"RepositoryName\":\"probe-repo-%s\""),
|
||||
new Case("KinesisFirehose::DeliveryStream", """
|
||||
{"Resources":{
|
||||
"B":{"Type":"AWS::S3::Bucket","Properties":{"BucketName":"probe-firehose-%s"}},
|
||||
"D":{"Type":"AWS::KinesisFirehose::DeliveryStream","Properties":{
|
||||
"DeliveryStreamName":"probe-stream-%s","DeliveryStreamType":"DirectPut",
|
||||
"S3DestinationConfiguration":{"BucketARN":{"Fn::GetAtt":["B","Arn"]},
|
||||
"RoleARN":"arn:aws:iam::000000000000:role/probe-role"}}}}}"""),
|
||||
single("IAM::ManagedPolicy", "AWS::IAM::ManagedPolicy",
|
||||
"\"ManagedPolicyName\":\"probe-policy-%s\","
|
||||
+ "\"PolicyDocument\":{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Action\":\"s3:ListAllMyBuckets\",\"Resource\":\"*\"}]}"),
|
||||
single("IAM::Role", "AWS::IAM::Role",
|
||||
"\"RoleName\":\"probe-role-%s\","
|
||||
+ "\"AssumeRolePolicyDocument\":{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
single("IAM::User", "AWS::IAM::User", "\"UserName\":\"probe-user-%s\""),
|
||||
single("IAM::Group", "AWS::IAM::Group", "\"GroupName\":\"probe-igroup-%s\""),
|
||||
new Case("KMS::Alias", """
|
||||
{"Resources":{
|
||||
"K":{"Type":"AWS::KMS::Key","Properties":{"Description":"probe"}},
|
||||
"Al":{"Type":"AWS::KMS::Alias","Properties":{"AliasName":"alias/probe-%s","TargetKeyId":{"Ref":"K"}}}}}"""),
|
||||
new Case("Lambda::Function + Alias", """
|
||||
{"Resources":{
|
||||
"F":{"Type":"AWS::Lambda::Function","Properties":{"FunctionName":"probe-fn-%s",
|
||||
"Runtime":"python3.12","Handler":"index.handler","Role":"arn:aws:iam::000000000000:role/probe-role",
|
||||
"Code":{"ZipFile":"def handler(e, c): return 1"}}},
|
||||
"Al":{"Type":"AWS::Lambda::Alias","Properties":{"Name":"live","FunctionName":{"Ref":"F"},"FunctionVersion":"$LATEST"}}}}"""),
|
||||
single("SecretsManager::Secret", "AWS::SecretsManager::Secret",
|
||||
"\"Name\":\"probe-secret-%s\",\"SecretString\":\"x\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"a\"}]"),
|
||||
single("SSM::Parameter", "AWS::SSM::Parameter",
|
||||
"\"Name\":\"/probe/param/%s\",\"Type\":\"String\",\"Value\":\"v\""),
|
||||
single("StepFunctions::StateMachine", "AWS::StepFunctions::StateMachine",
|
||||
"\"StateMachineName\":\"probe-sm-%s\",\"RoleArn\":\"" + ROLE_ARN + "\","
|
||||
+ "\"DefinitionString\":\"{\\\"StartAt\\\":\\\"P\\\",\\\"States\\\":{\\\"P\\\":{\\\"Type\\\":\\\"Pass\\\",\\\"End\\\":true}}}\""),
|
||||
single("WAFv2::WebACL", "AWS::WAFv2::WebACL",
|
||||
"\"Name\":\"probe-acl-%s\",\"Scope\":\"REGIONAL\",\"DefaultAction\":{\"Allow\":{}},"
|
||||
+ "\"VisibilityConfig\":{\"SampledRequestsEnabled\":false,\"CloudWatchMetricsEnabled\":false,"
|
||||
+ "\"MetricName\":\"probe\"}"),
|
||||
single("DynamoDB::Table", "AWS::DynamoDB::Table",
|
||||
"\"TableName\":\"probe-table-%s\",\"BillingMode\":\"PAY_PER_REQUEST\","
|
||||
+ "\"AttributeDefinitions\":[{\"AttributeName\":\"pk\",\"AttributeType\":\"S\"}],"
|
||||
+ "\"KeySchema\":[{\"AttributeName\":\"pk\",\"KeyType\":\"HASH\"}]"),
|
||||
single("Scheduler::ScheduleGroup", "AWS::Scheduler::ScheduleGroup", "\"Name\":\"probe-group-%s\""),
|
||||
single("EC2::LaunchTemplate", "AWS::EC2::LaunchTemplate",
|
||||
"\"LaunchTemplateName\":\"probe-lt-%s\",\"LaunchTemplateData\":{\"ImageId\":\"ami-12345678\"}"),
|
||||
new Case("Cognito::UserPool + UserPoolGroup", """
|
||||
{"Resources":{
|
||||
"U":{"Type":"AWS::Cognito::UserPool","Properties":{"UserPoolName":"probe-pool-%s"}},
|
||||
"Gp":{"Type":"AWS::Cognito::UserPoolGroup","Properties":{"GroupName":"probe-group-%s","UserPoolId":{"Ref":"U"}}}}}"""),
|
||||
single("Cognito::IdentityPool", "AWS::Cognito::IdentityPool",
|
||||
"\"IdentityPoolName\":\"probe_ip_%s\",\"AllowUnauthenticatedIdentities\":false"),
|
||||
new Case("ApiGatewayV2::Api + Stage", """
|
||||
{"Resources":{
|
||||
"Api":{"Type":"AWS::ApiGatewayV2::Api","Properties":{"Name":"probe-api-%s","ProtocolType":"HTTP"}},
|
||||
"St":{"Type":"AWS::ApiGatewayV2::Stage","Properties":{"ApiId":{"Ref":"Api"},"StageName":"probe","AutoDeploy":true}}}}"""),
|
||||
single("SQS::Queue", "AWS::SQS::Queue", "\"QueueName\":\"probe-queue-%s\""),
|
||||
single("SNS::Topic", "AWS::SNS::Topic", "\"TopicName\":\"probe-topic-%s\""),
|
||||
single("S3::Bucket", "AWS::S3::Bucket", "\"BucketName\":\"probe-bucket-%s\""),
|
||||
single("ECS::Cluster", "AWS::ECS::Cluster", "\"ClusterName\":\"probe-cluster-%s\""),
|
||||
new Case("Events::EventBus + Rule", """
|
||||
{"Resources":{
|
||||
"Bus":{"Type":"AWS::Events::EventBus","Properties":{"Name":"probe-bus-%s"}},
|
||||
"Ru":{"Type":"AWS::Events::Rule","Properties":{"Name":"probe-rule-%s","EventBusName":{"Ref":"Bus"},
|
||||
"EventPattern":{"source":["probe"]},"State":"ENABLED"}}}}"""),
|
||||
single("Kinesis::Stream", "AWS::Kinesis::Stream", "\"Name\":\"probe-kstream-%s\",\"ShardCount\":1"),
|
||||
new Case("Glue::Database", """
|
||||
{"Resources":{"Db":{"Type":"AWS::Glue::Database","Properties":{"CatalogId":"000000000000",
|
||||
"DatabaseInput":{"Name":"probe_db_%s"}}}}}"""),
|
||||
single("Route53::HostedZone", "AWS::Route53::HostedZone", "\"Name\":\"probe-%s.example.\""),
|
||||
single("ServiceDiscovery::HttpNamespace", "AWS::ServiceDiscovery::HttpNamespace", "\"Name\":\"probe-ns-%s\""),
|
||||
single("AppConfig::Application", "AWS::AppConfig::Application", "\"Name\":\"probe-app-%s\""),
|
||||
single("SES::ConfigurationSet", "AWS::SES::ConfigurationSet", "\"Name\":\"probe-cs-%s\""),
|
||||
single("Batch::JobDefinition", "AWS::Batch::JobDefinition",
|
||||
"\"JobDefinitionName\":\"probe-jd-%s\",\"Type\":\"container\","
|
||||
+ "\"ContainerProperties\":{\"Image\":\"public.ecr.aws/example/job:latest\"}")
|
||||
);
|
||||
}
|
||||
|
||||
private static Case single(String label, String type, String props) {
|
||||
return new Case(label, "{\"Resources\":{\"R\":{\"Type\":\"" + type + "\",\"Properties\":{" + props + "}}}}");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("cases")
|
||||
void identicalUpdateIsANoOpAndDeleteCleansUp(Case c) {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "probe-" + suffix;
|
||||
String template = c.template().replace("%s", suffix);
|
||||
|
||||
Response create = cfn("CreateStack", stackName, template);
|
||||
if (create.statusCode() != 200) {
|
||||
fail("CREATE request rejected: " + create.asString());
|
||||
}
|
||||
expect(stackName, "CREATE_COMPLETE", "CREATE");
|
||||
|
||||
Response update = cfn("UpdateStack", stackName, template);
|
||||
boolean noUpdates = update.statusCode() == 400 && update.asString().contains("No updates");
|
||||
if (!noUpdates) {
|
||||
expect(stackName, "UPDATE_COMPLETE", "UPDATE");
|
||||
}
|
||||
|
||||
cfn("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
}
|
||||
|
||||
private static void expect(String stackName, String wanted, String phase) {
|
||||
CfnStackWaits.StackState got = CfnStackWaits.awaitTerminal(stackName);
|
||||
if (!wanted.equals(got.status())) {
|
||||
fail(phase + " ended " + got.status() + " " + got.reason() + events(stackName));
|
||||
}
|
||||
}
|
||||
|
||||
private static Response cfn(String action, String stackName, String template) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("Capabilities.member.1", "CAPABILITY_NAMED_IAM");
|
||||
if (template != null) {
|
||||
request = request.formParam("TemplateBody", template);
|
||||
}
|
||||
return request.when().post("/");
|
||||
}
|
||||
|
||||
private static String events(String stackName) {
|
||||
List<String> all = cfn("DescribeStackEvents", stackName, null).xmlPath()
|
||||
.getList("**.findAll { it.name() == 'ResourceStatusReason' }", String.class);
|
||||
List<String> reasons = new ArrayList<>();
|
||||
for (String reason : all) {
|
||||
if (reason != null && !reason.isBlank() && !reasons.contains(reason) && reasons.size() < 3) {
|
||||
reasons.add(reason);
|
||||
}
|
||||
}
|
||||
return reasons.isEmpty() ? "" : " | " + String.join(" | ", reasons);
|
||||
}
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.SecretVersion;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The secret provisioner in isolation, mocking only SecretsManagerService. The update path is the
|
||||
* #2134 case: an identical UpdateStack must reconcile the named secret in place, never create it
|
||||
* again.
|
||||
*/
|
||||
class SecretsManagerCfnProvisionerTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ARN = "arn:aws:secretsmanager:us-east-1:000000000000:secret:app/db-AbCdEf";
|
||||
|
||||
private final SecretsManagerService secrets = mock(SecretsManagerService.class);
|
||||
private final SecretsManagerCfnProvisioner provisioner = new SecretsManagerCfnProvisioner(secrets);
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private ProvisionContext ctx(String priorPhysicalId) {
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node == null || node.isMissingNode() || node.isNull() ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
return new ProvisionContext(engine, REGION, "000000000000", "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
private static StackResource resource() {
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("DbSecret");
|
||||
r.setResourceType("AWS::SecretsManager::Secret");
|
||||
r.setAttributes(new HashMap<>());
|
||||
return r;
|
||||
}
|
||||
|
||||
private static Secret secret(String name, String description, Map<String, String> tags) {
|
||||
Secret s = new Secret();
|
||||
s.setName(name);
|
||||
s.setArn(ARN);
|
||||
s.setDescription(description);
|
||||
s.setTags(tags.entrySet().stream().map(e -> new Secret.Tag(e.getKey(), e.getValue())).toList());
|
||||
return s;
|
||||
}
|
||||
|
||||
private ObjectNode props(String name, String value, Map<String, String> tags) {
|
||||
ObjectNode props = mapper.createObjectNode().put("Name", name).put("SecretString", value);
|
||||
ArrayNode tagNodes = props.putArray("Tags");
|
||||
tags.forEach((k, v) -> tagNodes.addObject().put("Key", k).put("Value", v));
|
||||
return props;
|
||||
}
|
||||
|
||||
private static SecretVersion version(String value) {
|
||||
SecretVersion v = new SecretVersion();
|
||||
v.setSecretString(value);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPassesNameValueKmsKeyAndTags() {
|
||||
when(secrets.createSecret(eq("app/db"), eq("s3cret"), isNull(), eq("db creds"), eq("alias/app"),
|
||||
anyList(), eq(REGION))).thenReturn(secret("app/db", "db creds", Map.of()));
|
||||
ObjectNode props = props("app/db", "s3cret", Map.of("team", "a")).put("Description", "db creds")
|
||||
.put("KmsKeyId", "alias/app");
|
||||
|
||||
StackResource r = resource();
|
||||
provisioner.provision(r, props, ctx(null));
|
||||
|
||||
verify(secrets).createSecret(eq("app/db"), eq("s3cret"), isNull(), eq("db creds"), eq("alias/app"),
|
||||
eq(List.of(new Secret.Tag("team", "a"))), eq(REGION));
|
||||
assertEquals(ARN, r.getPhysicalId());
|
||||
assertEquals(ARN, r.getAttributes().get("Arn"));
|
||||
assertEquals("app/db", r.getAttributes().get("Name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void identicalUpdateReconcilesInPlaceAndCreatesNothing() {
|
||||
Secret existing = secret("app/db", "db creds", Map.of("team", "a"));
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
when(secrets.getSecretValue(ARN, null, null, REGION)).thenReturn(version("s3cret"));
|
||||
ObjectNode props = props("app/db", "s3cret", Map.of("team", "a")).put("Description", "db creds");
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets, never()).createSecret(anyString(), any(), any(), any(), any(), anyList(), anyString());
|
||||
verify(secrets, never()).putSecretValue(anyString(), any(), any(), any(), anyString(), any());
|
||||
verify(secrets, never()).tagResource(anyString(), anyList(), anyString());
|
||||
verify(secrets, never()).untagResource(anyString(), anyList(), anyString());
|
||||
verify(secrets).updateSecret(ARN, "db creds", null, REGION);
|
||||
assertEquals(ARN, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateDrivesValueAndTagsToTheTemplate() {
|
||||
Secret existing = secret("app/db", "old", Map.of("team", "a", "stale", "x"));
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
when(secrets.getSecretValue(ARN, null, null, REGION)).thenReturn(version("old-value"));
|
||||
ObjectNode props = props("app/db", "new-value", Map.of("team", "b")).put("Description", "new");
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets).putSecretValue(ARN, "new-value", null, null, REGION, null);
|
||||
verify(secrets).untagResource(ARN, List.of("stale"), REGION);
|
||||
verify(secrets).tagResource(ARN, List.of(new Secret.Tag("team", "b")), REGION);
|
||||
verify(secrets, never()).createSecret(anyString(), any(), any(), any(), any(), anyList(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedNameIsKeptAcrossUpdatesAndAnUnchangedGenerateConfigDoesNotRotate() {
|
||||
Secret existing = secret("my-stack-DbSecret-a1b2c3d4e5f6", null, Map.of());
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
props.putObject("GenerateSecretString").put("PasswordLength", 16);
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
r.getAttributes().put("FlociSecretNameMode", "generated");
|
||||
r.getAttributes().put("FlociSecretGenerateIdentity", props.get("GenerateSecretString").toString());
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets, never()).createSecret(anyString(), any(), any(), any(), any(), anyList(), anyString());
|
||||
verify(secrets, never()).putSecretValue(anyString(), any(), any(), any(), anyString(), any());
|
||||
assertEquals("my-stack-DbSecret-a1b2c3d4e5f6", r.getAttributes().get("Name"));
|
||||
assertEquals("generated", r.getAttributes().get("FlociSecretNameMode"));
|
||||
}
|
||||
|
||||
/** The registry's update handler holds GetRandomPassword: a changed generation config makes a new value. */
|
||||
@Test
|
||||
void aChangedGenerateConfigGeneratesANewVersion() {
|
||||
Secret existing = secret("app/db", null, Map.of());
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
ObjectNode props = mapper.createObjectNode().put("Name", "app/db");
|
||||
props.putObject("GenerateSecretString").put("PasswordLength", 32).put("ExcludePunctuation", true);
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
r.getAttributes().put("FlociSecretGenerateIdentity", "{\"PasswordLength\":16}");
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets).putSecretValue(eq(ARN), argThat((String value) -> value != null && value.length() == 32),
|
||||
isNull(), isNull(), eq(REGION), isNull());
|
||||
assertEquals(props.get("GenerateSecretString").toString(), r.getAttributes().get("FlociSecretGenerateIdentity"));
|
||||
}
|
||||
|
||||
/** Switching from SecretString to GenerateSecretString is a change: the update generates a new value. */
|
||||
@Test
|
||||
void switchingFromSecretStringToGenerateGeneratesANewVersion() {
|
||||
Secret existing = secret("app/db", null, Map.of());
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
when(secrets.getSecretValue(ARN, null, null, REGION)).thenReturn(version("s3cret"));
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props("app/db", "s3cret", Map.of()), ctx(ARN));
|
||||
assertEquals("none", r.getAttributes().get("FlociSecretGenerateIdentity"));
|
||||
verify(secrets, never()).putSecretValue(anyString(), any(), any(), any(), anyString(), any());
|
||||
|
||||
ObjectNode props = mapper.createObjectNode().put("Name", "app/db");
|
||||
props.putObject("GenerateSecretString").put("PasswordLength", 24);
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets).putSecretValue(eq(ARN), argThat((String value) -> value != null && value.length() == 24),
|
||||
isNull(), isNull(), eq(REGION), isNull());
|
||||
assertEquals(props.get("GenerateSecretString").toString(), r.getAttributes().get("FlociSecretGenerateIdentity"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A record from before the identity was tracked cannot show whether its prior template used a
|
||||
* literal SecretString or another generation policy, so it generates even when the current
|
||||
* value already has the configured length.
|
||||
*/
|
||||
@Test
|
||||
void aLegacyRecordWithAGenerateConfigGenerates() {
|
||||
Secret existing = secret("app/db", null, Map.of());
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(existing);
|
||||
when(secrets.updateSecret(eq(ARN), any(), any(), eq(REGION))).thenReturn(existing);
|
||||
when(secrets.getSecretValue(ARN, null, null, REGION)).thenReturn(version("x".repeat(32)));
|
||||
ObjectNode props = mapper.createObjectNode().put("Name", "app/db");
|
||||
props.putObject("GenerateSecretString").put("PasswordLength", 32).put("ExcludePunctuation", true);
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets).putSecretValue(eq(ARN), argThat((String value) -> value != null && value.length() == 32),
|
||||
isNull(), isNull(), eq(REGION), isNull());
|
||||
assertEquals(props.get("GenerateSecretString").toString(), r.getAttributes().get("FlociSecretGenerateIdentity"));
|
||||
}
|
||||
|
||||
/** Name is create-only: dropping an explicit name is a replacement under a generated name, as on AWS. */
|
||||
@Test
|
||||
void droppingAnExplicitNameIsAReplacement() {
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(secret("app/db", null, Map.of()));
|
||||
Secret replacement = new Secret();
|
||||
replacement.setName("my-stack-DbSecret-0123456789ab");
|
||||
replacement.setArn(ARN.replace("app/db", "my-stack-DbSecret-0123456789ab"));
|
||||
when(secrets.createSecret(anyString(), eq("s3cret"), isNull(), isNull(), isNull(), anyList(), eq(REGION)))
|
||||
.thenReturn(replacement);
|
||||
ObjectNode props = mapper.createObjectNode().put("SecretString", "s3cret");
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
r.getAttributes().put("FlociSecretNameMode", "explicit");
|
||||
provisioner.provision(r, props, ctx(ARN));
|
||||
|
||||
verify(secrets, never()).updateSecret(anyString(), any(), any(), anyString());
|
||||
verify(secrets).createSecret(argThat((String name) -> name.startsWith("my-stack-DbSecret-")), eq("s3cret"),
|
||||
isNull(), isNull(), isNull(), anyList(), eq(REGION));
|
||||
assertEquals(replacement.getArn(), r.getPhysicalId());
|
||||
assertEquals("generated", r.getAttributes().get("FlociSecretNameMode"));
|
||||
}
|
||||
|
||||
/** A stack persisted before the mode was recorded: an explicit-looking prior name counts as explicit. */
|
||||
@Test
|
||||
void anUnrecordedPriorNameIsClassifiedByItsShape() {
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(secret("app/db", null, Map.of()));
|
||||
Secret replacement = new Secret();
|
||||
replacement.setName("my-stack-DbSecret-0123456789ab");
|
||||
replacement.setArn(ARN.replace("app/db", "my-stack-DbSecret-0123456789ab"));
|
||||
when(secrets.createSecret(anyString(), eq("s3cret"), isNull(), isNull(), isNull(), anyList(), eq(REGION)))
|
||||
.thenReturn(replacement);
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, mapper.createObjectNode().put("SecretString", "s3cret"), ctx(ARN));
|
||||
|
||||
verify(secrets, never()).updateSecret(anyString(), any(), any(), anyString());
|
||||
assertEquals(replacement.getArn(), r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChangedNameIsAReplacement() {
|
||||
when(secrets.describeSecret(ARN, REGION)).thenReturn(secret("app/db", null, Map.of()));
|
||||
Secret replacement = new Secret();
|
||||
replacement.setName("app/db-v2");
|
||||
replacement.setArn(ARN.replace("app/db", "app/db-v2"));
|
||||
when(secrets.createSecret(eq("app/db-v2"), eq("s3cret"), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(replacement);
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props("app/db-v2", "s3cret", Map.of()), ctx(ARN));
|
||||
|
||||
verify(secrets, never()).updateSecret(anyString(), any(), any(), anyString());
|
||||
assertEquals(replacement.getArn(), r.getPhysicalId());
|
||||
assertEquals("app/db-v2", r.getAttributes().get("Name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPriorSecretDeletedOutOfBandIsCreatedAfresh() {
|
||||
when(secrets.describeSecret(ARN, REGION))
|
||||
.thenThrow(new AwsException("ResourceNotFoundException", "gone", 400));
|
||||
when(secrets.createSecret(eq("app/db"), eq("s3cret"), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(secret("app/db", null, Map.of()));
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(ARN);
|
||||
provisioner.provision(r, props("app/db", "s3cret", Map.of()), ctx(ARN));
|
||||
|
||||
verify(secrets).createSecret(eq("app/db"), eq("s3cret"), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION));
|
||||
assertEquals(ARN, r.getPhysicalId());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user