mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 08:55:17 -05:00
feat(rds): DescribeCertificates, ModifyCertificates and an instance's CA certificate (#6106)
* feat(rds): DescribeCertificates, ModifyCertificates and an instance's CA certificate DescribeCertificates lists the Region's RDS certificate authorities with the thumbprint and validity AWS reports, vendored from the certificate bundles AWS publishes by tools/aws/regen_rds_ca_certificates.py, and pages them. ModifyCertificates sets or removes the account's default for new instances. CreateDBInstance, ModifyDBInstance, the two instance restores and CreateDBInstanceReadReplica take CACertificateIdentifier, and instances report it with CertificateDetails. AWS::RDS::DBInstance takes the property and resolves the two CertificateDetails attributes. The identifier is metadata: the auth proxy keeps presenting Floci's own CA. Closes #5806 * fix(rds): follow the user guide on CAs and leave a blank CA alone - An instance stored without a CA reports rds-ca-rsa2048-g1, since an override applies only to instances created after it. - ap-south-1, ap-southeast-4, ca-west-1, eu-central-2, eu-south-2 and il-central-1 offer only rds-ca-rsa2048-g1, as the user guide says. - A blank CACertificateIdentifier on modify leaves the instance's CA. - --download skips a Region only on 403 or 404 and exits 1 on other failures. - Reuse regionFromArn, add a createDbInstance stub helper and import Executable in the tests.
This commit is contained in:
1 parent
3438a00daf
commit
ec21cf38c7
21 files changed
+1917
-54
No files matched your search
+12
-2
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.rds.RdsService;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbCluster;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbClusterParameterGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbInstance;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbInstanceSettings;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxy;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
@@ -349,12 +350,15 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
DbInstance instance = sameNameExistingResource(priorPhysicalId, id, rdsService::getDbInstance);
|
||||
boolean created = instance == null;
|
||||
String caCertificate = resolveOptional(props, "CACertificateIdentifier", engine);
|
||||
if (instance != null) {
|
||||
// A null region keeps the default-region lookup sameNameExistingResource made.
|
||||
instance = rdsService.modifyDbInstance(
|
||||
id,
|
||||
resolveDynamicReferences(resolveOptionalWithoutDynamicReferences(props, "MasterUserPassword", engine), region, true),
|
||||
parseBoolProp(props, "EnableIAMDatabaseAuthentication", engine),
|
||||
resolveOptional(props, "DBSubnetGroupName", engine));
|
||||
resolveOptional(props, "DBSubnetGroupName", engine), null, null, null, null,
|
||||
DbInstanceSettings.unchanged().withCaCertificateIdentifier(caCertificate));
|
||||
} else {
|
||||
instance = rdsService.createDbInstance(
|
||||
id,
|
||||
@@ -369,7 +373,8 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
resolveOptional(props, "DBParameterGroupName", engine),
|
||||
resolveOptional(props, "DBSubnetGroupName", engine),
|
||||
resolveOptional(props, "DBClusterIdentifier", engine),
|
||||
null, false, false, null, Map.of(), region);
|
||||
null, false, false, null, Map.of(), List.of(), null, region, true,
|
||||
DbInstanceSettings.defaults().withCaCertificateIdentifier(caCertificate));
|
||||
}
|
||||
// The roles go on before a renamed instance's predecessor is deleted, so a refused list
|
||||
// deletes only the new instance and the stack still has the old one to roll back to.
|
||||
@@ -389,6 +394,11 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (instance.getDbiResourceId() != null) {
|
||||
r.getAttributes().put("DbiResourceId", instance.getDbiResourceId());
|
||||
}
|
||||
RdsService.InstanceCertificate ca = rdsService.instanceCertificate(instance);
|
||||
r.getAttributes().put("CertificateDetails.CAIdentifier", ca.caIdentifier());
|
||||
if (ca.validTill() != null) {
|
||||
r.getAttributes().put("CertificateDetails.ValidTill", ca.validTill().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.VendoredResources;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Each Region's RDS certificate authorities as {@code DescribeCertificates} reports them, vendored in
|
||||
* {@code aws/rds-ca-certificates.json} by {@code tools/aws/regen_rds_ca_certificates.py} from the
|
||||
* certificate bundles AWS publishes. A Region with no vendored entry, such as a custom one, uses
|
||||
* us-east-1's.
|
||||
*/
|
||||
final class RdsCaCertificates {
|
||||
|
||||
/** The CA AWS gives a new instance when the account sets no override. */
|
||||
static final String DEFAULT_FOR_NEW_LAUNCHES = "rds-ca-rsa2048-g1";
|
||||
// The vendored file always has this entry (parse refuses one without it).
|
||||
private static final String FALLBACK_REGION = "us-east-1"; // partition-literal: a key into the vendored data
|
||||
private static final Map<String, List<CaCertificate>> BY_REGION = VendoredResources.read(
|
||||
"aws/rds-ca-certificates.json", "RDS CA certificates", in -> parse(new ObjectMapper().readTree(in)));
|
||||
|
||||
record CaCertificate(String identifier, String thumbprint, Instant validFrom, Instant validTill) {}
|
||||
|
||||
private RdsCaCertificates() {
|
||||
}
|
||||
|
||||
/** The Region's CAs in identifier order. */
|
||||
static List<CaCertificate> forRegion(String region) {
|
||||
List<CaCertificate> certificates = BY_REGION.get(region);
|
||||
return certificates != null ? certificates : BY_REGION.get(FALLBACK_REGION);
|
||||
}
|
||||
|
||||
/** The Region's CA named {@code identifier}, which AWS matches without regard to case. */
|
||||
static Optional<CaCertificate> find(String region, String identifier) {
|
||||
return forRegion(region).stream()
|
||||
.filter(certificate -> certificate.identifier().equalsIgnoreCase(identifier))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private static Map<String, List<CaCertificate>> parse(JsonNode doc) {
|
||||
Map<String, List<CaCertificate>> byRegion = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, JsonNode> region : doc.path("regions").properties()) {
|
||||
List<CaCertificate> certificates = new ArrayList<>();
|
||||
for (JsonNode certificate : region.getValue()) {
|
||||
certificates.add(new CaCertificate(certificate.path("certificateIdentifier").asText(),
|
||||
certificate.path("thumbprint").asText(),
|
||||
Instant.parse(certificate.path("validFrom").asText()),
|
||||
Instant.parse(certificate.path("validTill").asText())));
|
||||
}
|
||||
byRegion.put(region.getKey(), List.copyOf(certificates));
|
||||
}
|
||||
if (!byRegion.containsKey(FALLBACK_REGION)) {
|
||||
throw new IllegalStateException("aws/rds-ca-certificates.json has no " + FALLBACK_REGION + " entry");
|
||||
}
|
||||
return Map.copyOf(byRegion);
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,8 @@ public class RdsQueryHandler {
|
||||
case "DescribeValidDBInstanceModifications" -> handleDescribeValidDbInstanceModifications(params, region);
|
||||
case "DescribeOrderableDBInstanceOptions" -> handleDescribeOrderableDbInstanceOptions(params);
|
||||
case "DescribeEvents" -> handleDescribeEvents(params, region);
|
||||
case "DescribeCertificates" -> handleDescribeCertificates(params, region);
|
||||
case "ModifyCertificates" -> handleModifyCertificates(params, region);
|
||||
case "CreateEventSubscription" -> handleCreateEventSubscription(params, region);
|
||||
case "DescribeEventSubscriptions" -> handleDescribeEventSubscriptions(params, region);
|
||||
case "ModifyEventSubscription" -> handleModifyEventSubscription(params, region);
|
||||
@@ -624,6 +626,45 @@ public class RdsQueryHandler {
|
||||
return xml.end("EventSubscription").build();
|
||||
}
|
||||
|
||||
private Response handleDescribeCertificates(MultivaluedMap<String, String> params, String region) {
|
||||
RdsService.CertificatePage page = service.describeCertificates(region, params.getFirst("CertificateIdentifier"),
|
||||
parseOptionalInt(params.getFirst("MaxRecords")), params.getFirst("Marker"));
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("DefaultCertificateForNewLaunches", page.defaultForNewLaunches())
|
||||
.start("Certificates");
|
||||
for (RdsService.Certificate certificate : page.certificates()) {
|
||||
certificateXml(xml, certificate);
|
||||
}
|
||||
xml.end("Certificates");
|
||||
if (page.marker() != null) {
|
||||
xml.elem("Marker", page.marker());
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeCertificates", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleModifyCertificates(MultivaluedMap<String, String> params, String region) {
|
||||
RdsService.Certificate certificate = service.modifyCertificates(region,
|
||||
params.getFirst("CertificateIdentifier"), parseOptionalBoolean(params, "RemoveCustomerOverride"));
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
certificateXml(xml, certificate);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyCertificates", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
private static void certificateXml(XmlBuilder xml, RdsService.Certificate certificate) {
|
||||
xml.start("Certificate")
|
||||
.elem("CertificateIdentifier", certificate.certificateIdentifier())
|
||||
.elem("CertificateType", "CA")
|
||||
.elem("Thumbprint", certificate.thumbprint())
|
||||
.elem("ValidFrom", certificate.validFrom().toString())
|
||||
.elem("ValidTill", certificate.validTill().toString())
|
||||
.elem("CertificateArn", certificate.certificateArn())
|
||||
.elem("CustomerOverride", certificate.customerOverride());
|
||||
if (certificate.customerOverrideValidTill() != null) {
|
||||
xml.elem("CustomerOverrideValidTill", certificate.customerOverrideValidTill().toString());
|
||||
}
|
||||
xml.end("Certificate");
|
||||
}
|
||||
|
||||
private Response handleDescribeEvents(MultivaluedMap<String, String> params, String region) {
|
||||
String sourceIdentifier = params.getFirst("SourceIdentifier");
|
||||
String sourceType = params.getFirst("SourceType");
|
||||
@@ -812,7 +853,8 @@ public class RdsQueryHandler {
|
||||
includeEncryption ? cloudwatchLogsExports(params) : null,
|
||||
includeEncryption ? null : cloudwatchLogsExportChanges(params),
|
||||
optionalInt(params.getFirst("MaxAllocatedStorage")),
|
||||
params.getFirst("StorageType"));
|
||||
params.getFirst("StorageType"),
|
||||
params.getFirst("CACertificateIdentifier"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1175,7 +1217,7 @@ public class RdsQueryHandler {
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
|
||||
optionalInt(params.getFirst("AllocatedStorage")),
|
||||
params.getFirst("ReplicaMode"),
|
||||
parseTags(params), params.getFirst("StorageType"));
|
||||
parseTags(params), params.getFirst("StorageType"), params.getFirst("CACertificateIdentifier"));
|
||||
DbInstance replica = service.createDbInstanceReadReplica(request, region);
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"CreateDBInstanceReadReplica", AwsNamespaces.RDS, dbInstanceXml(replica))).build();
|
||||
@@ -1991,7 +2033,8 @@ public class RdsQueryHandler {
|
||||
DbInstance instance = service.restoreDbInstanceFromDbSnapshot(instanceId, snapshotId,
|
||||
dbInstanceClass, availabilityZone, multiAz, dbSubnetGroupName,
|
||||
vpcSecurityGroupIds, tags, region, requestedPort,
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"), params.getFirst("StorageType"));
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"), params.getFirst("StorageType"),
|
||||
params.getFirst("CACertificateIdentifier"));
|
||||
String result = dbInstanceXml(instance);
|
||||
return Response.ok(AwsQueryResponse.envelope("RestoreDBInstanceFromDBSnapshot", AwsNamespaces.RDS, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -2770,7 +2813,7 @@ public class RdsQueryHandler {
|
||||
parseIntegerParam(params, "BackupRetentionPeriod"),
|
||||
params.getFirst("PreferredBackupWindow"),
|
||||
parseOptionalBoolean(params, "DeletionProtection"),
|
||||
parseTags(params), params.getFirst("StorageType"));
|
||||
parseTags(params), params.getFirst("StorageType"), params.getFirst("CACertificateIdentifier"));
|
||||
DbInstance instance = service.restoreDbInstanceToPointInTime(request, region);
|
||||
return Response.ok(AwsQueryResponse.envelope(
|
||||
"RestoreDBInstanceToPointInTime", AwsNamespaces.RDS, dbInstanceXml(instance))).build();
|
||||
@@ -2963,6 +3006,13 @@ public class RdsQueryHandler {
|
||||
.elem("Port", ep.port())
|
||||
.end("Endpoint");
|
||||
}
|
||||
RdsService.InstanceCertificate ca = service.instanceCertificate(i);
|
||||
xml.elem("CACertificateIdentifier", ca.caIdentifier())
|
||||
.start("CertificateDetails").elem("CAIdentifier", ca.caIdentifier());
|
||||
if (ca.validTill() != null) {
|
||||
xml.elem("ValidTill", ca.validTill().toString());
|
||||
}
|
||||
xml.end("CertificateDetails");
|
||||
xml.elem("IAMDatabaseAuthenticationEnabled", i.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", i.isMultiAz())
|
||||
.elem("AutoMinorVersionUpgrade", i.isAutoMinorVersionUpgrade())
|
||||
|
||||
@@ -183,6 +183,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
private StorageBackend<String, RdsEvent> events = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, EventSubscription> eventSubscriptions;
|
||||
private final StorageBackend<String, DbClusterEndpoint> clusterEndpoints;
|
||||
/** The account's ModifyCertificates override per Region, by CA identifier. */
|
||||
private final StorageBackend<String, String> certificateOverrides;
|
||||
private final StorageBackend<String, DbProxyEndpoint> proxyEndpoints;
|
||||
private final RdsContainerManager containerManager;
|
||||
private final RdsProxyManager proxyManager;
|
||||
@@ -285,6 +287,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
new TypeReference<Map<String, String>>() {});
|
||||
this.events = storageFactory.create("rds", "rds-events.json",
|
||||
new TypeReference<Map<String, RdsEvent>>() {});
|
||||
this.certificateOverrides = storageFactory.create("rds", "rds-certificate-overrides.json",
|
||||
new TypeReference<Map<String, String>>() {});
|
||||
}
|
||||
|
||||
RdsService(RdsContainerManager containerManager,
|
||||
@@ -422,6 +426,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
this.clusterSnapshots = new InMemoryStorage<>();
|
||||
this.snapshotData = new io.github.hectorvent.floci.core.storage.InMemoryStorage<>();
|
||||
this.eventSubscriptions = new InMemoryStorage<>();
|
||||
this.certificateOverrides = new InMemoryStorage<>();
|
||||
this.clusterEndpoints = new InMemoryStorage<>();
|
||||
this.proxyEndpoints = new InMemoryStorage<>();
|
||||
}
|
||||
@@ -743,6 +748,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
DbInstanceSettings.validateMonitoringPairOnCreate(
|
||||
settings.monitoringInterval(), settings.monitoringRoleArn());
|
||||
resolvedSettings = resolvedSettings.withCaCertificateIdentifier(
|
||||
resolveCaCertificate(settings.caCertificateIdentifier(), effectiveRegion));
|
||||
boolean mock = config.services().rds().mock();
|
||||
if (masterUsername == null || masterUsername.isBlank()) {
|
||||
masterUsername = "root";
|
||||
@@ -1247,6 +1254,17 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Map<String, String> tags, String region,
|
||||
Integer requestedPort, Boolean iamEnabled, String storageType) {
|
||||
return restoreDbInstanceFromDbSnapshot(instanceId, snapshotId, dbInstanceClass, availabilityZone,
|
||||
multiAz, dbSubnetGroupName, vpcSecurityGroupIds, tags, region, requestedPort, iamEnabled,
|
||||
storageType, null);
|
||||
}
|
||||
|
||||
public DbInstance restoreDbInstanceFromDbSnapshot(String instanceId, String snapshotId, String dbInstanceClass,
|
||||
String availabilityZone, boolean multiAz, String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Map<String, String> tags, String region,
|
||||
Integer requestedPort, Boolean iamEnabled, String storageType,
|
||||
String caCertificateIdentifier) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
DbSnapshot snapshot = Optional.ofNullable(findSnapshotForScope(currentAccountId(), effectiveRegion, snapshotId))
|
||||
.orElseThrow(() -> new AwsException("DBSnapshotNotFound", "DBSnapshot " + snapshotId + " not found.", 404));
|
||||
@@ -1261,7 +1279,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
// Use the parameters from the snapshot
|
||||
DbInstanceSettings restoreSettings = new DbInstanceSettings(
|
||||
snapshot.isStorageEncrypted(), snapshot.getKmsKeyId(), null, null, null, null)
|
||||
.withStorageType(storageType != null ? storageType : snapshot.getStorageType());
|
||||
.withStorageType(storageType != null ? storageType : snapshot.getStorageType())
|
||||
.withCaCertificateIdentifier(caCertificateIdentifier);
|
||||
DbInstance instance = createDbInstance(instanceId, snapshot.getEngine().name().toLowerCase(), snapshot.getEngineVersion(),
|
||||
snapshot.getMasterUsername(), snapshot.getMasterPassword(),
|
||||
snapshot.getDbName(), targetClass, snapshot.getAllocatedStorage(), Boolean.TRUE.equals(iamEnabled),
|
||||
@@ -1363,7 +1382,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
source.isStorageEncrypted() ? source.getKmsKeyId() : null,
|
||||
request.backupRetentionPeriod(), request.preferredBackupWindow(), null,
|
||||
request.copyTagsToSnapshot()).withStorageType(
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType());
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType())
|
||||
.withCaCertificateIdentifier(request.caCertificateIdentifier());
|
||||
DbInstance instance = createDbInstance(targetId, engineParam, source.getEngineVersion(),
|
||||
source.getMasterUsername(), source.getMasterPassword(), dbName,
|
||||
firstNonBlank(request.dbInstanceClass(), source.getDbInstanceClass()),
|
||||
@@ -1571,7 +1591,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
source.isStorageEncrypted() && sameRegion ? source.getKmsKeyId() : null,
|
||||
0, source.getPreferredBackupWindow(), source.getPreferredMaintenanceWindow(),
|
||||
copyTagsToSnapshot).withStorageType(
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType());
|
||||
request.storageType() != null ? request.storageType() : source.getStorageType())
|
||||
.withCaCertificateIdentifier(request.caCertificateIdentifier());
|
||||
Map<String, String> tags = request.tags() != null ? request.tags() : Map.of();
|
||||
|
||||
DbInstance replica = createDbInstance(id, engineParam, source.getEngineVersion(),
|
||||
@@ -3149,6 +3170,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
effective = effective.withStorageType(null);
|
||||
}
|
||||
validateAutoscalingMinimum(instance, effective.maxAllocatedStorage());
|
||||
if (!isBlank(settings.caCertificateIdentifier())) {
|
||||
effective = effective.withCaCertificateIdentifier(
|
||||
resolveCaCertificate(settings.caCertificateIdentifier(), effectiveRegion));
|
||||
}
|
||||
boolean changesParameterGroup = dbParameterGroupName != null && !dbParameterGroupName.isBlank();
|
||||
if (changesParameterGroup) {
|
||||
validateInstanceParameterGroup(dbParameterGroupName, engineName(instance),
|
||||
@@ -6541,6 +6566,104 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
LOG.infov("DB proxy {0} deleted", name);
|
||||
}
|
||||
|
||||
// ── Certificates ──────────────────────────────────────────────────────────
|
||||
|
||||
/** A certificate authority as DescribeCertificates and ModifyCertificates report it. */
|
||||
public record Certificate(String certificateIdentifier, String thumbprint, Instant validFrom,
|
||||
Instant validTill, String certificateArn, boolean customerOverride,
|
||||
Instant customerOverrideValidTill) {}
|
||||
|
||||
public record CertificatePage(List<Certificate> certificates, String defaultForNewLaunches, String marker) {}
|
||||
|
||||
/** The CA an instance reports and the end of its validity. */
|
||||
public record InstanceCertificate(String caIdentifier, Instant validTill) {}
|
||||
|
||||
/**
|
||||
* The Region's certificate authorities in identifier order, or the one named, with the CA a new
|
||||
* instance gets. {@code Filters} is not taken: the API reference says it isn't supported.
|
||||
*/
|
||||
public synchronized CertificatePage describeCertificates(String region, String certificateIdentifier,
|
||||
Integer maxRecords, String marker) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
requireValidMaxRecords(maxRecords);
|
||||
String override = certificateOverrides.get(effectiveRegion).orElse(null);
|
||||
List<Certificate> matching = new ArrayList<>();
|
||||
for (RdsCaCertificates.CaCertificate ca : RdsCaCertificates.forRegion(effectiveRegion)) {
|
||||
if (isBlank(certificateIdentifier) || ca.identifier().equalsIgnoreCase(certificateIdentifier)) {
|
||||
matching.add(certificate(ca, effectiveRegion, ca.identifier().equals(override)));
|
||||
}
|
||||
}
|
||||
if (!isBlank(certificateIdentifier) && matching.isEmpty()) {
|
||||
throw certificateNotFound(certificateIdentifier);
|
||||
}
|
||||
OffsetPage<Certificate> page = offsetPage(matching, maxRecords, marker);
|
||||
return new CertificatePage(page.items(), defaultCaCertificate(effectiveRegion), page.marker());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CA new instances in the Region get, or with {@code removeCustomerOverride} puts back
|
||||
* RDS's default. The answer is the CA set, or after a removal the one that was overridden.
|
||||
*/
|
||||
public synchronized Certificate modifyCertificates(String region, String certificateIdentifier,
|
||||
Boolean removeCustomerOverride) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
boolean remove = Boolean.TRUE.equals(removeCustomerOverride);
|
||||
if (remove == !isBlank(certificateIdentifier)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"Specify either CertificateIdentifier or RemoveCustomerOverride, but not both.", 400);
|
||||
}
|
||||
if (remove) {
|
||||
String previous = certificateOverrides.get(effectiveRegion)
|
||||
.orElse(RdsCaCertificates.DEFAULT_FOR_NEW_LAUNCHES);
|
||||
certificateOverrides.delete(effectiveRegion);
|
||||
return certificate(RdsCaCertificates.find(effectiveRegion, previous)
|
||||
.orElseThrow(() -> certificateNotFound(previous)), effectiveRegion, false);
|
||||
}
|
||||
RdsCaCertificates.CaCertificate ca = RdsCaCertificates.find(effectiveRegion, certificateIdentifier)
|
||||
.orElseThrow(() -> certificateNotFound(certificateIdentifier));
|
||||
certificateOverrides.put(effectiveRegion, ca.identifier());
|
||||
return certificate(ca, effectiveRegion, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The CA an instance reports. One stored before CAs were recorded reports RDS's default, since an
|
||||
* override applies only to instances created after it.
|
||||
*/
|
||||
public InstanceCertificate instanceCertificate(DbInstance instance) {
|
||||
String region = regionFromArn(instance.getDbInstanceArn());
|
||||
String identifier = instance.getCaCertificateIdentifier() != null
|
||||
? instance.getCaCertificateIdentifier() : RdsCaCertificates.DEFAULT_FOR_NEW_LAUNCHES;
|
||||
return RdsCaCertificates.find(region, identifier)
|
||||
.map(ca -> new InstanceCertificate(ca.identifier(), ca.validTill()))
|
||||
.orElse(new InstanceCertificate(identifier, null));
|
||||
}
|
||||
|
||||
/** The account's override for the Region, else RDS's default. */
|
||||
private String defaultCaCertificate(String region) {
|
||||
return certificateOverrides.get(region).orElse(RdsCaCertificates.DEFAULT_FOR_NEW_LAUNCHES);
|
||||
}
|
||||
|
||||
/** The requested CA in its canonical case, or the Region's default when none is requested. */
|
||||
private String resolveCaCertificate(String requested, String region) {
|
||||
if (isBlank(requested)) {
|
||||
return defaultCaCertificate(region);
|
||||
}
|
||||
return RdsCaCertificates.find(region, requested)
|
||||
.map(RdsCaCertificates.CaCertificate::identifier)
|
||||
.orElseThrow(() -> certificateNotFound(requested));
|
||||
}
|
||||
|
||||
private Certificate certificate(RdsCaCertificates.CaCertificate ca, String region, boolean override) {
|
||||
String arn = new AwsArnUtils.Arn(regionResolver.partitionForRegion(region), "rds", region, "",
|
||||
"cert:" + ca.identifier()).toString();
|
||||
return new Certificate(ca.identifier(), ca.thumbprint(), ca.validFrom(), ca.validTill(), arn, override,
|
||||
override ? ca.validTill() : null);
|
||||
}
|
||||
|
||||
private static AwsException certificateNotFound(String identifier) {
|
||||
return new AwsException("CertificateNotFound", "Certificate " + identifier + " not found.", 404);
|
||||
}
|
||||
|
||||
// ── DB Proxy endpoints ────────────────────────────────────────────────────
|
||||
|
||||
/** AWS's limit on the endpoints a caller adds to one proxy, besides its default endpoint. */
|
||||
|
||||
@@ -26,6 +26,8 @@ public class DbInstance {
|
||||
private String dbInstanceClass;
|
||||
private int allocatedStorage;
|
||||
private String storageType;
|
||||
/** The RDS certificate authority for the instance; null on one stored before it was recorded. */
|
||||
private String caCertificateIdentifier;
|
||||
private DbInstanceStatus status;
|
||||
private DbEndpoint endpoint;
|
||||
private boolean iamDatabaseAuthenticationEnabled;
|
||||
@@ -137,6 +139,11 @@ public class DbInstance {
|
||||
public String getStorageType() { return storageType != null ? storageType : DEFAULT_STORAGE_TYPE; }
|
||||
public void setStorageType(String storageType) { this.storageType = storageType; }
|
||||
|
||||
public String getCaCertificateIdentifier() { return caCertificateIdentifier; }
|
||||
public void setCaCertificateIdentifier(String caCertificateIdentifier) {
|
||||
this.caCertificateIdentifier = caCertificateIdentifier;
|
||||
}
|
||||
|
||||
public int getAllocatedStorage() { return allocatedStorage; }
|
||||
public void setAllocatedStorage(int allocatedStorage) { this.allocatedStorage = allocatedStorage; }
|
||||
|
||||
|
||||
+33
-4
@@ -27,7 +27,20 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
List<String> enabledCloudwatchLogsExports,
|
||||
LogExportChanges logExportChanges,
|
||||
Integer maxAllocatedStorage,
|
||||
String storageType) {
|
||||
String storageType,
|
||||
String caCertificateIdentifier) {
|
||||
public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow, String preferredMaintenanceWindow,
|
||||
Boolean copyTagsToSnapshot, Integer monitoringInterval, String monitoringRoleArn,
|
||||
Boolean performanceInsightsEnabled, Integer performanceInsightsRetentionPeriod,
|
||||
String engineLifecycleSupport, List<String> enabledCloudwatchLogsExports,
|
||||
LogExportChanges logExportChanges, Integer maxAllocatedStorage, String storageType) {
|
||||
this(storageEncrypted, kmsKeyId, backupRetentionPeriod, preferredBackupWindow,
|
||||
preferredMaintenanceWindow, copyTagsToSnapshot, monitoringInterval, monitoringRoleArn,
|
||||
performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType, null);
|
||||
}
|
||||
|
||||
|
||||
public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow, String preferredMaintenanceWindow,
|
||||
@@ -187,7 +200,8 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
backupWindow, maintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType);
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
|
||||
caCertificateIdentifier);
|
||||
}
|
||||
|
||||
public DbInstanceSettings withKmsKeyId(String resolvedKmsKeyId) {
|
||||
@@ -195,7 +209,8 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType);
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
|
||||
caCertificateIdentifier);
|
||||
}
|
||||
|
||||
public DbInstanceSettings withStorageType(String resolvedStorageType) {
|
||||
@@ -203,7 +218,18 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, resolvedStorageType);
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, resolvedStorageType,
|
||||
caCertificateIdentifier);
|
||||
}
|
||||
|
||||
/** The same settings with the CA certificate the service resolved. */
|
||||
public DbInstanceSettings withCaCertificateIdentifier(String resolvedCaCertificateIdentifier) {
|
||||
return new DbInstanceSettings(storageEncrypted, kmsKeyId, backupRetentionPeriod,
|
||||
preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,
|
||||
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
|
||||
performanceInsightsRetentionPeriod, engineLifecycleSupport,
|
||||
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
|
||||
resolvedCaCertificateIdentifier);
|
||||
}
|
||||
|
||||
public void validateStorageType() {
|
||||
@@ -261,5 +287,8 @@ public record DbInstanceSettings(Boolean storageEncrypted,
|
||||
if (maxAllocatedStorage != null) {
|
||||
instance.setMaxAllocatedStorage(maxAllocatedStorage);
|
||||
}
|
||||
if (caCertificateIdentifier != null && !caCertificateIdentifier.isBlank()) {
|
||||
instance.setCaCertificateIdentifier(caCertificateIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
-2
@@ -36,7 +36,40 @@ public record PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
String preferredBackupWindow,
|
||||
Boolean deletionProtection,
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
String storageType,
|
||||
String caCertificateIdentifier) {
|
||||
public PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
String sourceDbiResourceId,
|
||||
String sourceDbInstanceAutomatedBackupsArn,
|
||||
Instant restoreTime,
|
||||
Boolean useLatestRestorableTime,
|
||||
String dbInstanceClass,
|
||||
Integer port,
|
||||
String availabilityZone,
|
||||
Boolean multiAz,
|
||||
Boolean autoMinorVersionUpgrade,
|
||||
String dbName,
|
||||
String optionGroupName,
|
||||
String dbParameterGroupName,
|
||||
Boolean publiclyAccessible,
|
||||
String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Boolean copyTagsToSnapshot,
|
||||
Boolean iamDatabaseAuthenticationEnabled,
|
||||
Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow,
|
||||
Boolean deletionProtection,
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
this(targetDbInstanceIdentifier, sourceDbInstanceIdentifier, sourceDbiResourceId,
|
||||
sourceDbInstanceAutomatedBackupsArn, restoreTime, useLatestRestorableTime, dbInstanceClass,
|
||||
port, availabilityZone, multiAz, autoMinorVersionUpgrade, dbName, optionGroupName,
|
||||
dbParameterGroupName, publiclyAccessible, dbSubnetGroupName, vpcSecurityGroupIds,
|
||||
copyTagsToSnapshot, iamDatabaseAuthenticationEnabled, backupRetentionPeriod,
|
||||
preferredBackupWindow, deletionProtection, tags, storageType, null);
|
||||
}
|
||||
|
||||
|
||||
public PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
@@ -66,6 +99,6 @@ public record PointInTimeRestoreRequest(String targetDbInstanceIdentifier,
|
||||
port, availabilityZone, multiAz, autoMinorVersionUpgrade, dbName, optionGroupName,
|
||||
dbParameterGroupName, publiclyAccessible, dbSubnetGroupName, vpcSecurityGroupIds,
|
||||
copyTagsToSnapshot, iamDatabaseAuthenticationEnabled, backupRetentionPeriod,
|
||||
preferredBackupWindow, deletionProtection, tags, null);
|
||||
preferredBackupWindow, deletionProtection, tags, null, null);
|
||||
}
|
||||
}
|
||||
+26
-2
@@ -27,7 +27,31 @@ public record ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
Integer allocatedStorage,
|
||||
String replicaMode,
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
String storageType,
|
||||
String caCertificateIdentifier) {
|
||||
|
||||
public ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
String dbInstanceClass,
|
||||
String availabilityZone,
|
||||
Boolean multiAz,
|
||||
Boolean autoMinorVersionUpgrade,
|
||||
String optionGroupName,
|
||||
String dbParameterGroupName,
|
||||
Boolean publiclyAccessible,
|
||||
String dbSubnetGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Boolean copyTagsToSnapshot,
|
||||
Boolean iamDatabaseAuthenticationEnabled,
|
||||
Integer allocatedStorage,
|
||||
String replicaMode,
|
||||
Map<String, String> tags,
|
||||
String storageType) {
|
||||
this(dbInstanceIdentifier, sourceDbInstanceIdentifier, dbInstanceClass, availabilityZone, multiAz,
|
||||
autoMinorVersionUpgrade, optionGroupName, dbParameterGroupName, publiclyAccessible,
|
||||
dbSubnetGroupName, vpcSecurityGroupIds, copyTagsToSnapshot, iamDatabaseAuthenticationEnabled,
|
||||
allocatedStorage, replicaMode, tags, storageType, null);
|
||||
}
|
||||
|
||||
public ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
String sourceDbInstanceIdentifier,
|
||||
@@ -48,6 +72,6 @@ public record ReadReplicaRequest(String dbInstanceIdentifier,
|
||||
this(dbInstanceIdentifier, sourceDbInstanceIdentifier, dbInstanceClass, availabilityZone, multiAz,
|
||||
autoMinorVersionUpgrade, optionGroupName, dbParameterGroupName, publiclyAccessible,
|
||||
dbSubnetGroupName, vpcSecurityGroupIds, copyTagsToSnapshot, iamDatabaseAuthenticationEnabled,
|
||||
allocatedStorage, replicaMode, tags, null);
|
||||
allocatedStorage, replicaMode, tags, null, null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user