mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(signer): give resource-tag conditions the tags of the signing profile a request names (#8771)
The generated request resources give Signer's signing-profile type the aws:ResourceTag/ key, but no service answered the signer namespace's stored tags, so a condition on a signing profile's tags saw none. SignerService now answers it: storedTags reads the profile stored under the Region the ARN names and its name, in the request's account, where the tag handlers read, in place, and matched on the whole ARN. Tag writes already gave the profile a new map but took no lock, so two could lose one's tags; every write of a profile's tags now runs one at a time, and the tags field is volatile.
This commit is contained in:
1 parent
025009fc64
commit
1e66899a95
6 files changed
+127
-18
No files matched your search
@@ -45,10 +45,10 @@ import java.util.Optional;
|
||||
* key value store a name names and the tags of any resource it tags; ECS, for the revision a task definition
|
||||
* reference resolves to, its default cluster and the tags of a cluster, a task definition, a service, a capacity
|
||||
* provider, a task or a container instance; ACM, for the tags of a certificate; Firehose, for the tags of a delivery
|
||||
* stream; Cognito, for the tags of a user pool or an identity pool; OpenSearch, for the tags of a domain); 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>
|
||||
* stream; Cognito, for the tags of a user pool or an identity pool; OpenSearch, for the tags of a domain; Signer, for
|
||||
* the tags of a signing profile); 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
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.common.TagHandler;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
@@ -44,7 +45,7 @@ import java.util.regex.Pattern;
|
||||
* S3. Both are documented on the service page and asserted by the service tests.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SignerService implements Resettable, TagHandler {
|
||||
public class SignerService implements Resettable, TagHandler, StoredResourceArns {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SignerService.class);
|
||||
private static final String SERVICE = "signer";
|
||||
@@ -142,10 +143,11 @@ public class SignerService implements Resettable, TagHandler {
|
||||
new LinkedHashMap<>(), requestedTags, region);
|
||||
}
|
||||
|
||||
private SigningProfile applyProfile(String profileName, SignerPlatforms.Platform platform,
|
||||
String certificateArn, String[] validity, JsonNode overrides,
|
||||
Map<String, String> signingParameters,
|
||||
Map<String, String> requestedTags, String region) {
|
||||
/** Sets the tags too, so it runs one at a time with the other tag writes ({@link #tagResource}). */
|
||||
private synchronized SigningProfile applyProfile(String profileName, SignerPlatforms.Platform platform,
|
||||
String certificateArn, String[] validity, JsonNode overrides,
|
||||
Map<String, String> signingParameters,
|
||||
Map<String, String> requestedTags, String region) {
|
||||
SigningProfile profile = profiles.get(storageKey(region, profileName)).orElse(null);
|
||||
boolean created = profile == null;
|
||||
if (created) {
|
||||
@@ -233,11 +235,12 @@ public class SignerService implements Resettable, TagHandler {
|
||||
/**
|
||||
* Writes a profile record for a CloudFormation resource that was provisioned before this
|
||||
* service existed, keeping the identifiers that stack already handed out instead of minting a
|
||||
* version: the adoption a later tags-only update needs.
|
||||
* version: the adoption a later tags-only update needs. It replaces the record, tags included, so
|
||||
* it runs one at a time with the tag writes.
|
||||
*/
|
||||
public SigningProfile adoptSigningProfile(String profileName, String platformId, String version,
|
||||
String validityType, Integer validityValue,
|
||||
String region) {
|
||||
public synchronized SigningProfile adoptSigningProfile(String profileName, String platformId, String version,
|
||||
String validityType, Integer validityValue,
|
||||
String region) {
|
||||
validateProfileName(profileName);
|
||||
SignerPlatforms.Platform platform = platformOf(platformId);
|
||||
String arn = AwsArnUtils.Arn.of(SERVICE, region, profiles.accountId(),
|
||||
@@ -529,7 +532,7 @@ public class SignerService implements Resettable, TagHandler {
|
||||
* {@code Tags} property on an update that changed nothing else. Unlike {@link #tagResource}, it
|
||||
* removes the tags the caller left out.
|
||||
*/
|
||||
public void replaceTags(String profileName, Map<String, String> tags, String region) {
|
||||
public synchronized void replaceTags(String profileName, Map<String, String> tags, String region) {
|
||||
validateProfileName(profileName);
|
||||
SigningProfile profile = requireProfile(profileName, region);
|
||||
Map<String, String> resolved = tags == null ? new LinkedHashMap<>() : new LinkedHashMap<>(tags);
|
||||
@@ -548,8 +551,12 @@ public class SignerService implements Resettable, TagHandler {
|
||||
return new LinkedHashMap<>(requireProfileFromArn(region, arn).getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the profile a new map. Every write of a profile's tags runs one at a time, so none loses another's, and a
|
||||
* reader holds one whole set.
|
||||
*/
|
||||
@Override
|
||||
public void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
public synchronized void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
validateTags(tags);
|
||||
SigningProfile profile = requireProfileFromArn(region, arn);
|
||||
Map<String, String> merged = new LinkedHashMap<>(profile.getTags());
|
||||
@@ -562,7 +569,7 @@ public class SignerService implements Resettable, TagHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
public synchronized void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
SigningProfile profile = requireProfileFromArn(region, arn);
|
||||
Map<String, String> remaining = new LinkedHashMap<>(profile.getTags());
|
||||
tagKeys.forEach(remaining::remove);
|
||||
@@ -576,6 +583,40 @@ public class SignerService implements Resettable, TagHandler {
|
||||
jobs.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return SERVICE;
|
||||
}
|
||||
|
||||
/** A request names a signing profile by its name, which its ARN carries whole, so there is nothing to find. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the signing profile whose ARN is {@code arn}, in the request's account, where the tag handlers read:
|
||||
* an ARN of another account names none. Read in place under the Region the ARN names and the profile's name, a
|
||||
* profile stored before storage was account-aware included, and matched on the whole ARN. Tag writes give the
|
||||
* profile a new map, so the read is of one whole set.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, SERVICE)) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
if (!parsed.accountId().equals(profiles.accountId()) || !parsed.resource().startsWith(PROFILE_RESOURCE)) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> tags = AccountAwareStorageBackend.readInAccount(profiles, parsed.accountId(),
|
||||
storageKey(parsed.region(), parsed.resource().substring(PROFILE_RESOURCE.length())))
|
||||
.filter(profile -> arn.equals(profile.getArn()))
|
||||
.map(SigningProfile::getTags)
|
||||
.orElse(Map.of());
|
||||
return new LinkedHashMap<>(tags);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- helpers
|
||||
|
||||
private SigningProfile requireProfile(String profileName, String region) {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class SigningProfile {
|
||||
private Integer signatureValidityPeriodValue;
|
||||
private JsonNode overrides;
|
||||
private Map<String, String> signingParameters = new LinkedHashMap<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private volatile Map<String, String> tags = new LinkedHashMap<>();
|
||||
private String status;
|
||||
private String statusReason;
|
||||
private Long revocationEffectiveFrom;
|
||||
|
||||
Reference in new issue
Block a user