mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cognito-idp): give resource-tag conditions the tags of the user pool a request names (#8753)
The generated request resources give Cognito user pools' userpool type the aws:ResourceTag/ key, but no service answered the cognito-idp namespace's stored tags, so a condition on a user pool's tags saw none. CognitoService now answers it: storedTags reads the pool stored under its id in the request's account, where the handlers read, in place, and matches the whole ARN, or the id for a pool stored before pools recorded their ARN, as DescribeUserPool's lookup by ARN does. Tag changes already store a new map under the pool's lock; the tags field is now volatile.
This commit is contained in:
1 parent
751aedde94
commit
948dcadae8
6 files changed
+94
-12
No files matched your search
@@ -45,9 +45,9 @@ 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); 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); 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
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
import io.floci.aws.core.common.ReservedTags;
|
||||
import io.floci.aws.core.common.SmithyValidationErrors;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.resource.ExplorerResource;
|
||||
import io.floci.aws.core.resource.ResourceProvider;
|
||||
import io.floci.aws.core.resource.SupportedResourceType;
|
||||
@@ -110,7 +111,7 @@ import java.util.regex.Pattern;
|
||||
import static io.floci.aws.core.common.ReservedTags.rejectUnknownReservedTags;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CognitoService implements ResourceProvider {
|
||||
public class CognitoService implements ResourceProvider, StoredResourceArns {
|
||||
private static final int DEFAULT_REFRESH_TOKEN_VALIDITY_DAYS = 30;
|
||||
private static final Duration MIN_ACCESS_AND_ID_TOKEN_VALIDITY = Duration.ofMinutes(5);
|
||||
private static final Duration MAX_ACCESS_AND_ID_TOKEN_VALIDITY = Duration.ofDays(1);
|
||||
@@ -1136,6 +1137,41 @@ public class CognitoService implements ResourceProvider {
|
||||
return new HashMap<>(pool.getUserPoolTags() != null ? pool.getUserPoolTags() : Map.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "cognito-idp";
|
||||
}
|
||||
|
||||
/** A request names a user pool by the id Cognito minted, which its ARN ends in, 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 user pool whose ARN is {@code arn}, in the request's account, where the handlers read: an ARN of
|
||||
* another account names none. Read in place under the pool's id, a pool stored before storage was account-aware
|
||||
* included, and matched on the whole ARN, or on the id for a pool stored before pools recorded their ARN, as
|
||||
* {@link #describeUserPoolByArn} matches it. Tag calls store a new map under the pool's lock, so the read is of
|
||||
* one whole set.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "cognito-idp")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
if (!parsed.accountId().equals(regionResolver.getAccountId()) || !parsed.resource().startsWith("userpool/")) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> tags = AccountAwareStorageBackend.readInAccount(poolStore, parsed.accountId(),
|
||||
parsed.resource().substring("userpool/".length()))
|
||||
.filter(pool -> pool.getArn() == null || arn.equals(pool.getArn()))
|
||||
.map(UserPool::getUserPoolTags)
|
||||
.orElse(Map.of());
|
||||
return new LinkedHashMap<>(tags);
|
||||
}
|
||||
|
||||
private static String extractUserPoolIdFromArn(String resourceArn) {
|
||||
if (resourceArn == null || resourceArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "ResourceArn is required", 400);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class UserPool {
|
||||
private int estimatedNumberOfUsers = 0;
|
||||
private Map<String, Object> emailConfiguration = new HashMap<>();
|
||||
private Map<String, Object> smsConfiguration = new HashMap<>();
|
||||
private Map<String, String> userPoolTags = new HashMap<>();
|
||||
private volatile Map<String, String> userPoolTags = new HashMap<>();
|
||||
private Map<String, Object> adminCreateUserConfig = new HashMap<>();
|
||||
private Map<String, Object> userPoolAddOns = new HashMap<>();
|
||||
private Map<String, Object> usernameConfiguration = new HashMap<>();
|
||||
|
||||
Reference in new issue
Block a user