mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(redshift): give resource-tag conditions the tags of the resource a request names (#8685)
The generated request resources give fifteen Redshift types the aws:ResourceTag/ key, but RedshiftStoredResourceArns answered only a snapshot's key, so a condition on a Redshift resource's tags saw none. It now answers from RedshiftService.storedTags, which reads the cluster, snapshot, parameter group, subnet group, snapshot copy grant, snapshot schedule, event subscription or integration stored under the ARN in the account and Region it names, in place, matched on the whole ARN; a snapshot is found as tagging finds it, the copy kept in the Region before the snapshot itself. CreateTags and DeleteTags already put a new map in place of the held one under the service's lock; the tag fields are now volatile, so the lookup reads one whole map.
This commit is contained in:
1 parent
bab6428f78
commit
d606843c49
15 files changed
+203
-13
No files matched your search
@@ -34,9 +34,11 @@ import java.util.Optional;
|
||||
* versions and executions, and an activity; CodeBuild, for the project a build belongs to and the tags of a project or
|
||||
* a report group; Athena, for the workgroup and the data catalog a request naming none uses and the tags of a
|
||||
* workgroup or a data catalog; Redshift Serverless, for the tags of a namespace, a workgroup or a snapshot; DynamoDB,
|
||||
* for the tags of a table and its indexes; ECR, for the tags of a repository); looked up lazily by
|
||||
* {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for
|
||||
* the namespace a request or an ARN is of, so IAM never depends on that service directly.</p>
|
||||
* for the tags of a table and its indexes; ECR, for the tags of a repository; Redshift, for the key a snapshot records
|
||||
* and the tags of a cluster, a snapshot, a parameter group, a subnet group, a snapshot copy grant, a snapshot
|
||||
* schedule, an event subscription or an integration); looked up lazily by {@code ResourceArnBuilder} and
|
||||
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
|
||||
* ARN is of, so IAM never depends on that service directly.</p>
|
||||
*
|
||||
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
|
||||
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
|
||||
|
||||
@@ -424,6 +424,12 @@ public class RedshiftEventService {
|
||||
&& (values == null || values.isEmpty() || values.contains(tag.getValue())));
|
||||
}
|
||||
|
||||
/** The tags of the subscription {@code name} in an account's Region, read in place; null for none. */
|
||||
public Map<String, String> storedTags(String accountId, String region, String name) {
|
||||
return AccountAwareStorageBackend.readInAccount(subscriptions, accountId, key(region, name))
|
||||
.map(EventSubscription::getTags).orElse(null);
|
||||
}
|
||||
|
||||
private EventSubscription requireSubscription(String name) {
|
||||
if (blankToNull(name) == null) {
|
||||
throw new AwsException("InvalidParameterValue", "SubscriptionName is required", 400);
|
||||
|
||||
@@ -4073,6 +4073,73 @@ public class RedshiftService implements ManagedSecretRotator {
|
||||
return Map.copyOf(resolveTagHandle(resourceName).tags());
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the cluster, snapshot, parameter group, subnet group, snapshot copy grant, snapshot schedule,
|
||||
* event subscription or integration stored under {@code arn}, in the account and Region it names, read in place
|
||||
* and matched on the whole ARN; empty for an ARN naming nothing stored.
|
||||
*/
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "redshift")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String resource = parsed.resource();
|
||||
int sep = resource.indexOf(':');
|
||||
if (sep < 0 || !arn.equals(AwsArnUtils.Arn.of("redshift", parsed.region(), parsed.accountId(), resource)
|
||||
.toString())) {
|
||||
return Map.of();
|
||||
}
|
||||
String account = parsed.accountId();
|
||||
String region = parsed.region();
|
||||
String id = resource.substring(sep + 1);
|
||||
Map<String, String> tags = switch (resource.substring(0, sep)) {
|
||||
case "cluster" -> AccountAwareStorageBackend.readInAccount(clusters, account, id)
|
||||
.filter(cluster -> clusterRegion(cluster).equals(region)).map(Cluster::getTags).orElse(null);
|
||||
case "snapshot" -> storedSnapshot(arn, account, region, id).map(Snapshot::getTags).orElse(null);
|
||||
case "parametergroup" -> AccountAwareStorageBackend.readInAccount(parameterGroups, account,
|
||||
regionalKey(region, id)).map(ClusterParameterGroup::getTags).orElse(null);
|
||||
case "subnetgroup" -> AccountAwareStorageBackend.readInAccount(subnetGroups, account,
|
||||
regionalKey(region, id)).map(ClusterSubnetGroup::getTags).orElse(null);
|
||||
case "snapshotcopygrant" -> AccountAwareStorageBackend.readInAccount(snapshotCopyGrants, account,
|
||||
regionalKey(region, id)).map(SnapshotCopyGrant::getTags).orElse(null);
|
||||
case "snapshotschedule" -> AccountAwareStorageBackend.readInAccount(snapshotSchedules, account,
|
||||
regionalKey(region, id)).map(SnapshotSchedule::getTags).orElse(null);
|
||||
case "eventsubscription" -> events == null ? null : events.storedTags(account, region, id);
|
||||
case "integration" -> AccountAwareStorageBackend.readInAccount(integrations, account, id)
|
||||
.filter(integration -> arn.equals(integration.getIntegrationArn()))
|
||||
.map(Integration::getTags).orElse(null);
|
||||
default -> null;
|
||||
};
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
if (tags != null) {
|
||||
tags.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return held;
|
||||
}
|
||||
|
||||
/**
|
||||
* The snapshot {@code <cluster>/<name>} names in {@code account}, read in place: the copy kept in {@code region}
|
||||
* before the snapshot itself, as tagging finds it, each only when its ARN is {@code arn} (one recording none, from
|
||||
* before snapshots did, when it is of that cluster).
|
||||
*/
|
||||
private Optional<Snapshot> storedSnapshot(String arn, String account, String region, String id) {
|
||||
int slash = id.indexOf('/');
|
||||
if (slash < 0) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String cluster = id.substring(0, slash);
|
||||
String name = id.substring(slash + 1);
|
||||
Predicate<Snapshot> named = snapshot -> snapshot.getSnapshotArn() == null
|
||||
? cluster.equals(snapshot.getClusterIdentifier()) : arn.equals(snapshot.getSnapshotArn());
|
||||
return AccountAwareStorageBackend.readInAccount(snapshotCopies, account, regionalKey(region, name))
|
||||
.filter(named)
|
||||
.or(() -> AccountAwareStorageBackend.readInAccount(snapshots, account, name).filter(named));
|
||||
}
|
||||
|
||||
public synchronized void createTags(String resourceName, Map<String, String> tags) {
|
||||
String subscriptionName = eventSubscriptionTagName(resourceName);
|
||||
if (subscriptionName != null) {
|
||||
|
||||
@@ -6,11 +6,12 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks Redshift of the resources a request names: what a snapshot records as its {@code KmsKeyId}, the key a
|
||||
* restore asks KMS to decrypt with as the caller.
|
||||
* restore asks KMS to decrypt with as the caller, and the tags of the resource an ARN names.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RedshiftStoredResourceArns implements StoredResourceArns {
|
||||
@@ -40,4 +41,9 @@ public class RedshiftStoredResourceArns implements StoredResourceArns {
|
||||
}
|
||||
return redshift.findSnapshotAt(arn).map(Snapshot::getKmsKeyId).filter(key -> !key.isBlank());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
return redshift.storedTags(arn);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class Cluster {
|
||||
public int getProxyPort() { return proxyPort; }
|
||||
public void setProxyPort(int proxyPort) { this.proxyPort = proxyPort; }
|
||||
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ClusterParameterGroup {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ClusterSubnetGroup {
|
||||
private String description;
|
||||
private String vpcId;
|
||||
private List<String> subnetIds = new ArrayList<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
/** Subnet id to availability zone; null on groups persisted before zones were resolved. */
|
||||
private Map<String, String> subnetZones;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class EventSubscription {
|
||||
private List<String> eventCategoriesList = new ArrayList<>();
|
||||
private String severity;
|
||||
private boolean enabled;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public String getCustomerAwsId() { return customerAwsId; }
|
||||
public void setCustomerAwsId(String customerAwsId) { this.customerAwsId = customerAwsId; }
|
||||
|
||||
@@ -178,7 +178,7 @@ public class Snapshot {
|
||||
this.manualSnapshotRetentionPeriod = manualSnapshotRetentionPeriod;
|
||||
}
|
||||
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public Set<String> getAccountsWithRestoreAccess() { return accountsWithRestoreAccess; }
|
||||
public void setAccountsWithRestoreAccess(Set<String> value) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
public class SnapshotCopyGrant {
|
||||
private String snapshotCopyGrantName;
|
||||
private String kmsKeyId;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public SnapshotCopyGrant() {}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SnapshotSchedule {
|
||||
private String scheduleIdentifier;
|
||||
private String scheduleDescription;
|
||||
private List<String> scheduleDefinitions = new ArrayList<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
private Instant updatedAt;
|
||||
|
||||
public Instant getUpdatedAt() { return updatedAt; }
|
||||
|
||||
Reference in new issue
Block a user