mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(auth): one home for the legacy test/test credential pair (#7858)
SigV4RequestValidator now exposes LEGACY_ACCESS_KEY_ID and LEGACY_SECRET_KEY, and every site that honors the local-dev test/test pair reads it from there instead of keeping its own private constant or "test".equals(...) literal. No behaviour change.
This commit is contained in:
1 parent
4d9c5faf56
commit
6e6d4eaf53
12 files changed
+42
-34
No files matched your search
@@ -58,6 +58,8 @@ import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
|
||||
/**
|
||||
* JAX-RS filter that enforces IAM policies on every incoming request when
|
||||
* {@code floci.services.iam.enforcement-enabled = true}
|
||||
@@ -390,7 +392,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
}
|
||||
|
||||
String akid = accountResolver.extractAccessKeyId(auth);
|
||||
if ("test".equals(akid)) {
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(akid)) {
|
||||
return; // root bypass
|
||||
}
|
||||
|
||||
@@ -1455,7 +1457,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
return;
|
||||
}
|
||||
String akid = accountResolver.extractAccessKeyId(authorizationHeader);
|
||||
if (akid == null || "test".equals(akid)) {
|
||||
if (akid == null || LEGACY_ACCESS_KEY_ID.equals(akid)) {
|
||||
return;
|
||||
}
|
||||
String rawScope = extractCredentialScope(authorizationHeader);
|
||||
@@ -1550,7 +1552,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
public Optional<String> statementRefusal(String operation, String statement, Map<String, String> names,
|
||||
boolean partitioned) {
|
||||
String akid = requestContext.getAccessKeyId();
|
||||
if (!config.services().iam().enforcementEnabled() || akid == null || "test".equals(akid)) {
|
||||
if (!config.services().iam().enforcementEnabled() || akid == null || LEGACY_ACCESS_KEY_ID.equals(akid)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String accountId = requestContext.getAccountId();
|
||||
|
||||
@@ -47,6 +47,9 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* Verifies header and query SigV4 signatures on every request outside S3
|
||||
* when {@code floci.auth.validate-signatures} is enabled, so a request signed with the wrong
|
||||
@@ -116,10 +119,6 @@ public class SigV4HeaderSignatureFilter implements ContainerRequestFilter {
|
||||
/** REST-XML resources the catalog does not list: S3 Control answers in S3's XML. */
|
||||
private static final Set<Class<?>> UNCATALOGUED_REST_XML = Set.of(S3ControlController.class);
|
||||
|
||||
/** The well-known local-dev pair, honoured as every other SigV4 check in Floci honours it. */
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
|
||||
private static final String MISMATCH_MESSAGE = "The request signature we calculated does not match "
|
||||
+ "the signature you provided. Check your AWS Secret Access Key and signing method. "
|
||||
+ "Consult the service documentation for details.";
|
||||
|
||||
@@ -42,12 +42,12 @@ public final class SigV4RequestValidator {
|
||||
|
||||
/**
|
||||
* Well-known local-dev credential pair used pervasively by default AWS SDK clients
|
||||
* (AwsBasicCredentials.create("test", "test")) against this emulator, mirrored from the
|
||||
* identical fallback in S3Service/PreSignedUrlFilter. Deliberately not a fallback for any
|
||||
* other unregistered access key, only this exact, already-public pair is honored.
|
||||
* (AwsBasicCredentials.create("test", "test")) against this emulator. Every site that honors it
|
||||
* reads it from here. Deliberately not a fallback for any other unregistered access key, only
|
||||
* this exact, already-public pair is honored.
|
||||
*/
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
public static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
public static final String LEGACY_SECRET_KEY = "test";
|
||||
|
||||
private final IamService iamService;
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ import org.jboss.logging.Logger;
|
||||
import java.net.URI;
|
||||
import java.time.Instant;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* Verifies the SigV4 signature on an execute-api data-plane request, so a route or method whose
|
||||
* {@code authorizationType} is {@code AWS_IAM} actually requires a signed caller instead of merely
|
||||
@@ -58,9 +61,6 @@ public class ExecuteApiSigV4Authorizer {
|
||||
/** Where a temporary credential's session token rides: a header, or a presigned query parameter. */
|
||||
private static final String SECURITY_TOKEN = "X-Amz-Security-Token";
|
||||
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
|
||||
private final IamService iamService;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* Verifies the SigV4 signature on an AppSync GraphQL data-plane request, so {@code AWS_IAM} auth
|
||||
* actually requires a signed caller rather than merely a well-formed {@code Credential=} value.
|
||||
@@ -57,8 +60,6 @@ public class IamAuthValidator {
|
||||
private static final String SIGNATURE_MISMATCH = "The request signature we calculated does not match the signature"
|
||||
+ " you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation"
|
||||
+ " for details.";
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
private static final String SECURITY_TOKEN = "X-Amz-Security-Token";
|
||||
|
||||
private final IamService iamService;
|
||||
@@ -317,7 +318,7 @@ public class IamAuthValidator {
|
||||
}
|
||||
|
||||
static boolean isEmulatorAllow(String accessKeyId) {
|
||||
return "test".equals(accessKeyId);
|
||||
return LEGACY_ACCESS_KEY_ID.equals(accessKeyId);
|
||||
}
|
||||
|
||||
static String requestArn(String region, String accountId, String apiId) {
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CloudTrailService implements StoredResourceArns {
|
||||
|
||||
@@ -1086,7 +1088,7 @@ public class CloudTrailService implements StoredResourceArns {
|
||||
ObjectNode identity = mapper.createObjectNode();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
|
||||
if (accessKeyId == null || "test".equals(accessKeyId)) {
|
||||
if (accessKeyId == null || LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
identity.put("type", "IAMUser");
|
||||
identity.put("principalId", "AIDA" + repeat('A', 17));
|
||||
identity.put("arn", regionResolver.buildGlobalArn("iam", accountId, "root"));
|
||||
|
||||
+3
-3
@@ -37,6 +37,9 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* The EC2 Instance Connect Endpoint data plane: {@code wss://<endpoint DnsName>/openTunnel}, the
|
||||
* SigV4-presigned WebSocket the AWS CLI opens for {@code aws ec2-instance-connect open-tunnel} and
|
||||
@@ -72,9 +75,6 @@ public class InstanceConnectTunnelHandler {
|
||||
/** AWS's limit, and the CLI's default, for {@code maxTunnelDuration}. */
|
||||
static final int MAX_TUNNEL_SECONDS = 3600;
|
||||
private static final int CONNECT_TIMEOUT_MILLIS = 10_000;
|
||||
/** The well-known local-dev pair, honoured as every other SigV4 check in Floci honours it. */
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
|
||||
private final Ec2Service ec2Service;
|
||||
private final Vertx vertx;
|
||||
|
||||
@@ -44,6 +44,9 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* The checks an {@code IamAuth} endpoint makes before a request reaches the function: a SigV4
|
||||
* signature for the service {@code lambda} in the endpoint's region, or a SigV4a one whose region
|
||||
@@ -63,7 +66,6 @@ public class LambdaWebIamAuth {
|
||||
private static final String SERVICE = "lambda";
|
||||
private static final String SECURITY_TOKEN = "X-Amz-Security-Token";
|
||||
private static final String REGION_SET = "X-Amz-Region-Set";
|
||||
private static final String TEST_ACCESS_KEY = "test";
|
||||
private static final String CLOUDFRONT_SOURCE_ARN = "lambda-web-cloudfront-source-arn";
|
||||
private static final String CLOUDFRONT_KEY = "lambda-web-cloudfront-key";
|
||||
|
||||
@@ -274,8 +276,8 @@ public class LambdaWebIamAuth {
|
||||
* signs with {@code test}.
|
||||
*/
|
||||
private String secretKey(String accessKeyId, String sessionToken) {
|
||||
if (TEST_ACCESS_KEY.equals(accessKeyId)) {
|
||||
return TEST_ACCESS_KEY;
|
||||
if (LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
return LEGACY_SECRET_KEY;
|
||||
}
|
||||
if (SessionTokenCheck.of(iamService, accessKeyId, sessionToken) != SessionTokenCheck.VALID) {
|
||||
return null;
|
||||
@@ -286,7 +288,7 @@ public class LambdaWebIamAuth {
|
||||
}
|
||||
|
||||
private boolean authorize(String accessKeyId, WebFunctionTarget target) {
|
||||
if (!config.services().iam().enforcementEnabled() || TEST_ACCESS_KEY.equals(accessKeyId)) {
|
||||
if (!config.services().iam().enforcementEnabled() || LEGACY_ACCESS_KEY_ID.equals(accessKeyId)) {
|
||||
return true;
|
||||
}
|
||||
Optional<String> callerAccount = iamService.resolveAccountId(accessKeyId);
|
||||
|
||||
@@ -33,13 +33,14 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
@Provider
|
||||
@Priority(Priorities.AUTHENTICATION)
|
||||
public class PreSignedUrlFilter implements ContainerRequestFilter {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PreSignedUrlFilter.class);
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String LEGACY_SECRET_KEY = "test";
|
||||
private static final Set<String> PRESIGNED_AUTH_SIGNALS = Set.of(
|
||||
"X-Amz-Algorithm",
|
||||
"X-Amz-Credential",
|
||||
|
||||
@@ -11,6 +11,9 @@ import java.time.format.ResolverStyle;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_SECRET_KEY;
|
||||
|
||||
/**
|
||||
* SigV4 verification for presigned POST policy documents. Mirrors the credential/secret-key
|
||||
* resolution and signing-key derivation in {@link PreSignedUrlFilter}'s query-string presigned
|
||||
@@ -19,9 +22,6 @@ import java.util.Optional;
|
||||
*/
|
||||
final class S3PostPolicySigner {
|
||||
|
||||
static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
static final String LEGACY_SECRET_KEY = "test";
|
||||
|
||||
/** S3's error list: {@code ExpiredToken}, 400 Bad Request. */
|
||||
static final String EXPIRED_TOKEN_MESSAGE = "The provided token has expired.";
|
||||
|
||||
|
||||
@@ -109,6 +109,8 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.floci.aws.core.common.auth.SigV4RequestValidator.LEGACY_ACCESS_KEY_ID;
|
||||
|
||||
@ApplicationScoped
|
||||
public class S3Service implements Resettable, ResourceProvider {
|
||||
private static final int MAX_LIST_BUCKETS = 10000;
|
||||
@@ -138,7 +140,6 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
public static final String TABLE_WAREHOUSE_BUCKET_SUFFIX = "--table-s3";
|
||||
private static final String AUTHENTICATED_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers";
|
||||
private static final String LOG_DELIVERY_GROUP_URI = "http://acs.amazonaws.com/groups/s3/LogDelivery";
|
||||
private static final String LEGACY_ACCESS_KEY_ID = "test";
|
||||
private static final String S3_XML_SCHEMA_ERROR =
|
||||
"The XML you provided was not well-formed or did not validate against our published schema.";
|
||||
private static final Set<String> OBJECT_OWNERSHIP_VALUES = Set.of(
|
||||
|
||||
Reference in new issue
Block a user