test: share one sidecar profile across the Redshift access enforcement classes (#8885)

SidecarS3AuthEnforcedProfile becomes SidecarAccessEnforcementProfile and
takes Spectrum's Lake Formation enforcement from
SidecarSpectrumLakeFormationProfile, which goes. Lake Formation leaves a
table to IAM while the account's Data Lake settings leave new tables to
IAM, as AWS's defaults do, so the S3 authorization classes' Spectrum
queries pass it. The Lake Formation class takes new tables away from IAM
to check its grants, so it now puts AWS's defaults back when it is done.
Its role may read the bucket it queries, so S3 authentication leaves its
reads as they were.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-18 14:31:45 -04:00
1 parent fd5f88debd
commit f1777164a3
6 files changed
+74 -43

No files matched your search

@@ -7,6 +7,7 @@ import io.floci.aws.services.lakeformation.LakeFormationService;
import io.floci.aws.services.lakeformation.model.DataLakePrincipal;
import io.floci.aws.services.lakeformation.model.DataLakeSettings;
import io.floci.aws.services.lakeformation.model.GrantPermissionsRequest;
import io.floci.aws.services.lakeformation.model.PrincipalPermissions;
import io.floci.aws.services.lakeformation.model.PutDataLakeSettingsRequest;
import io.floci.aws.services.lakeformation.model.Resource;
import io.floci.aws.services.lakeformation.model.RevokePermissionsRequest;
@@ -16,8 +17,8 @@ import io.floci.aws.services.redshift.spectrum.ExternalStatement;
import io.floci.aws.services.redshift.spectrum.ExternalStatementParser;
import io.floci.aws.services.redshift.spectrum.GlueTableBuilder;
import io.floci.aws.services.s3.S3Service;
import io.floci.aws.testing.SidecarAccessEnforcementProfile;
import io.floci.aws.testing.SidecarContainersProfile;
import io.floci.aws.testing.SidecarSpectrumLakeFormationProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -41,9 +42,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A Spectrum query is refused until the external schema's role holds a Lake Formation {@code SELECT}
* grant on the table, and a revoke stops the next query even though the table is already cached.
*
* <p>It takes new tables away from IAM in the account's Data Lake settings, and puts AWS's defaults
* back when it is done, since the other classes on {@link SidecarAccessEnforcementProfile} read
* their external tables with no Lake Formation grant.
*/
@QuarkusTest
@TestProfile(SidecarSpectrumLakeFormationProfile.class)
@TestProfile(SidecarAccessEnforcementProfile.class)
class RedshiftSpectrumLakeFormationIntegrationTest {
private static final String REGION = "us-east-1";
@@ -80,6 +85,7 @@ class RedshiftSpectrumLakeFormationIntegrationTest {
@AfterEach
void cleanUp() {
lakeFormationService.putDataLakeSettings(REGION, iamOnlyDefaults());
if (clusterId != null) {
redshiftService.deleteCluster(clusterId);
}
@@ -158,6 +164,25 @@ class RedshiftSpectrumLakeFormationIntegrationTest {
return request;
}
/** AWS's defaults for a new account, which leave new databases and tables to IAM. */
private static PutDataLakeSettingsRequest iamOnlyDefaults() {
DataLakeSettings settings = new DataLakeSettings();
settings.setCreateDatabaseDefaultPermissions(List.of(allToIamAllowedPrincipals()));
settings.setCreateTableDefaultPermissions(List.of(allToIamAllowedPrincipals()));
PutDataLakeSettingsRequest request = new PutDataLakeSettingsRequest();
request.setDataLakeSettings(settings);
return request;
}
private static PrincipalPermissions allToIamAllowedPrincipals() {
DataLakePrincipal principal = new DataLakePrincipal();
principal.setDataLakePrincipalIdentifier("IAM_ALLOWED_PRINCIPALS");
PrincipalPermissions permissions = new PrincipalPermissions();
permissions.setPrincipal(principal);
permissions.setPermissions(List.of("ALL"));
return permissions;
}
private static DataLakePrincipal principal() {
DataLakePrincipal principal = new DataLakePrincipal();
principal.setDataLakePrincipalIdentifier(ROLE_ARN);
@@ -9,8 +9,8 @@ import io.floci.aws.services.redshift.spectrum.ExternalStatementParser;
import io.floci.aws.services.redshift.spectrum.GlueTableBuilder;
import io.floci.aws.services.s3.S3Service;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.floci.aws.testing.SidecarAccessEnforcementProfile;
import io.floci.aws.testing.SidecarContainersProfile;
import io.floci.aws.testing.SidecarS3AuthEnforcedProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* role stops the next query with SQLSTATE 42501 even though the table is already cached.
*/
@QuarkusTest
@TestProfile(SidecarS3AuthEnforcedProfile.class)
@TestProfile(SidecarAccessEnforcementProfile.class)
class RedshiftSpectrumS3AuthEnforcedIntegrationTest {
private static final String ROLE_NAME = "SpectrumAuthItRole";
@@ -4,8 +4,8 @@ import io.floci.aws.services.iam.IamService;
import io.floci.aws.services.redshift.model.Cluster;
import io.floci.aws.services.s3.S3Service;
import io.floci.aws.services.s3.model.S3Object;
import io.floci.aws.testing.SidecarAccessEnforcementProfile;
import io.floci.aws.testing.SidecarContainersProfile;
import io.floci.aws.testing.SidecarS3AuthEnforcedProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -25,7 +25,7 @@ import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.*;
@QuarkusTest
@TestProfile(SidecarS3AuthEnforcedProfile.class)
@TestProfile(SidecarAccessEnforcementProfile.class)
class RedshiftUnloadParquetS3AuthIntegrationTest {
@Inject
RedshiftService redshift;
@@ -0,0 +1,43 @@
package io.floci.aws.testing;
import java.util.HashMap;
import java.util.Map;
/**
* {@link SidecarContainersProfile} with S3 request authentication and Lake Formation enforced on
* Spectrum queries, for the Redshift classes that check what a cluster's role may read and write.
* Quarkus builds the application once per distinct profile class, and keeps every one it built for
* the rest of the test JVM, so they share this one rather than each declaring their own.
*
* <p>The overrides, on top of the sidecar settings, and who relies on them:
* <ul>
* <li>{@code floci.services.s3.enforce-auth=true} makes the S3 transfers a cluster runs, the
* floci-duck transfer of a Spectrum cold load and an UNLOAD, present the role's signed session
* instead of the account-scoped development credentials.
* {@code RedshiftSpectrumS3AuthEnforcedIntegrationTest} and
* {@code RedshiftUnloadParquetS3AuthIntegrationTest} rely on it.</li>
* <li>{@code floci.services.redshift.spectrum-lake-formation-enforcement=true} lets a Spectrum
* query read an external table only when Lake Formation lets the external schema's role select
* from it. {@code RedshiftSpectrumLakeFormationIntegrationTest} relies on it.</li>
* </ul>
*
* <p>Each is inert where no class relies on it. Lake Formation leaves a table to IAM while the
* account's Data Lake settings leave new tables to IAM, as AWS's defaults do, so the Spectrum
* query of the S3 class passes it. The Lake Formation class takes new tables away from IAM to
* check its grants, and puts AWS's defaults back once it is done. Its role may read the bucket it
* queries, so the signed session it gets under S3 authentication reads the table as before. The
* UNLOAD class reads no external table.
*
* <p>A class joins if every setting here is either one it relies on or one that never reaches its
* requests, and if any setting it adds never reaches the requests of a class already here.
*/
public class SidecarAccessEnforcementProfile extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.s3.enforce-auth", "true");
overrides.put("floci.services.redshift.spectrum-lake-formation-enforcement", "true");
return overrides;
}
}
@@ -1,19 +0,0 @@
package io.floci.aws.testing;
import java.util.HashMap;
import java.util.Map;
/**
* {@link SidecarContainersProfile} with S3 authorization enforced, so the floci-duck transfer of a
* Spectrum cold load has to present a signed role session instead of the account-scoped development
* credentials.
*/
public class SidecarS3AuthEnforcedProfile extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.s3.enforce-auth", "true");
return overrides;
}
}
@@ -1,18 +0,0 @@
package io.floci.aws.testing;
import java.util.HashMap;
import java.util.Map;
/**
* {@link SidecarContainersProfile} with Lake Formation enforced on Spectrum queries, so an external
* table is readable only by a role that holds a Lake Formation {@code SELECT} grant on it.
*/
public class SidecarSpectrumLakeFormationProfile extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.redshift.spectrum-lake-formation-enforcement", "true");
return overrides;
}
}