fix(iam): check Redshift Data API requests on the cluster or workgroup they name (#7234)

Under IAM enforcement, Redshift Data API requests were checked on `*`,
so a grant scoped to a cluster or a serverless workgroup was refused
and a deny scoped to one never applied.

The Service Reference gives ExecuteStatement, BatchExecuteStatement,
DescribeTable, ListDatabases, ListSchemas and ListTables two resource
types: Redshift's `cluster:${ClusterName}`, which ClusterIdentifier
fills, and Redshift Serverless's `workgroup/${WorkgroupId}`. A
workgroup's ARN ends in the id Redshift Serverless gives it (its
workgroupId, "The unique identifier of the workgroup"; botocore's
WorkgroupNameString takes an ARN ending in workgroup/<uuid>), while a
request names it by WorkgroupName, "The serverless workgroup name or
Amazon Resource Name (ARN)". So the workgroup is a FOUND_BY type,
found by WorkgroupName.

FOUND_BY named a type by its members only where the rule had derived
a fill for the type to replace, as ResourceId fills a scalable target's
${ResourceId}. No member fills ${WorkgroupId}, so FOUND_BY now names
every FOUND_BY type the action acts on whose members the request has,
as its docstring already said. The Application Auto Scaling entries
are unchanged.

RedshiftDataResourceResolver, which resolves the target a request
runs on, now implements StoredResourceArns for redshift-data: it
gives the ARN of the workgroup a name or an ARN finds, through
RedshiftServerlessService.findWorkgroupByNameOrArn, which the
service's own name-or-ARN lookup now uses as well.

Redshift Data joins the table (12 operations, 1048 over 26
namespaces). The six operations above are checked on the cluster's
ARN or on the stored workgroup's, and on `workgroup/*` for a workgroup
there is none of; their SecretArn names neither. A request naming only
its SessionId stays on `*`, and so do CancelStatement,
DescribeStatement, GetStatementResult, GetStatementResultV2,
ListSessions and ListStatements, which the Service Reference gives no
resource type.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-01 20:57:48 -06:00
1 parent 8c32e9f6ba
commit 9bd90d6580
11 files changed
+219 -35

No files matched your search

@@ -7,10 +7,12 @@ import java.util.Optional;
* Finds the ARN a service stores a resource under, for a type of the request-resources table whose ARN carries an id
* the service mints, which only the service knows: after the name a request gives ({@code connection/<name>/<id>}),
* or as all of it, a request naming the resource by members its ARN does not hold
* ({@code scalable-target/<id>}, named by its service namespace, resource id and scalable dimension).
* ({@code scalable-target/<id>}, named by its service namespace, resource id and scalable dimension;
* {@code workgroup/<id>}, named by its name).
*
* <p>Implemented by the service that owns such resources (EventBridge, for its connections and API destinations;
* Application Auto Scaling, for its scalable targets); looked up lazily by {@code ResourceArnBuilder} through
* <p>Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
* Redshift Serverless workgroups it runs statements on); looked up lazily by {@code ResourceArnBuilder} through
* {@code Instance<StoredResourceArns>} for the namespace a request is of, so IAM never depends on that service
* directly.</p>
*/
@@ -21,8 +23,9 @@ public interface StoredResourceArns {
/**
* The ARN the caller's resource of the type in the Region is stored under, named by {@code names}, the values the
* request names it by in the order the table reads them: a connection's name, or a scalable target's service
* namespace, resource id and scalable dimension; empty when there is none, or the type is not one it finds.
* request names it by in the order the table reads them: a connection's name, a scalable target's service
* namespace, resource id and scalable dimension, or a workgroup's name or ARN; empty when there is none, or the
* type is not one it finds.
*/
Optional<String> find(String type, List<String> names, String region);
}
@@ -6,12 +6,14 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.DatabaseSecretCredentials;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.StoredResourceArns;
import io.github.hectorvent.floci.services.redshift.RedshiftCredentialBroker;
import io.github.hectorvent.floci.services.redshift.RedshiftService;
import io.github.hectorvent.floci.services.redshift.model.Cluster;
import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumSession;
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessRuntime;
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessService;
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
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;
@@ -19,8 +21,11 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.util.List;
import java.util.Optional;
@ApplicationScoped
class RedshiftDataResourceResolver {
class RedshiftDataResourceResolver implements StoredResourceArns {
private static final Logger LOG = Logger.getLogger(RedshiftDataResourceResolver.class);
@@ -46,6 +51,20 @@ class RedshiftDataResourceResolver {
this.serverlessService = serverlessService;
}
@Override
public String namespace() {
return "redshift-data";
}
/** The ARN of the serverless workgroup a request names by its name or ARN, as {@link #resolve} reads it. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
if (!"workgroup".equals(type) || names.size() != 1) {
return Optional.empty();
}
return serverlessService.findWorkgroupByNameOrArn(names.getFirst(), region).map(Workgroup::getWorkgroupArn);
}
DatabaseTarget resolve(JsonNode request, String region) {
String database = requiredText(request, "Database");
if (hasText(request, "WorkgroupName")) {
@@ -1234,14 +1234,20 @@ public class RedshiftServerlessService implements Resettable {
}
}
/** The workgroup a workgroup name or ARN names in the Region, as the Data API reads either; empty when none. */
public Optional<Workgroup> findWorkgroupByNameOrArn(String nameOrArn, String region) {
return AwsArnUtils.looksLikeArn(nameOrArn) ? workgroupByArn(nameOrArn, region)
: findWorkgroup(nameOrArn, region);
}
private Workgroup resolveWorkgroup(String nameOrArn, String region) {
if (nameOrArn == null || nameOrArn.isBlank()) {
throw ServerlessSupport.validation("workgroupName is required.");
}
if (!AwsArnUtils.looksLikeArn(nameOrArn)) {
return getWorkgroup(nameOrArn, region);
validateWorkgroupName(nameOrArn);
}
return workgroupByArn(nameOrArn, region).orElseThrow(() -> workgroupNotFound(nameOrArn));
return findWorkgroupByNameOrArn(nameOrArn, region).orElseThrow(() -> workgroupNotFound(nameOrArn));
}
/**