mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(core): stop unknown-service REST requests falling through to S3 (#1967)
* fix(core): stop unknown-service REST requests falling through to S3 REST requests whose SigV4 credential scope names a service Floci does not implement matched no JAX-RS resource and fell through to S3's path-style wildcard routes, surfacing as misleading NoSuchBucket XML and triggering SDK retry storms. Reject them with UnknownOperationException instead. The guard fires only on positive identification: a parseable SigV4 scope naming a service absent from the catalog. Unsigned, presigned, Bearer/Basic and SigV4a requests are untouched. Also declares the EKS read-only sub-resource lists the emulator does not model (ListAccessEntries, ListAddons, ListIdentityProviderConfigs, ListPodIdentityAssociations) as explicit routes, so they outrank the S3 catch-all and answer with each operation's model-exact empty result key, or ResourceNotFoundException for a missing cluster. Closes #1754 * fix(iam): normalise signing-scope aliases before IAM enforcement S3 accepts requests signed under the s3express scope, but IAM action rules, resource ARNs and condition keys are all keyed by the canonical signing name. An alias therefore resolved to no action, which IamEnforcementFilter treats as ALLOW, so policy-protected S3 operations were reachable without a policy check. Resolve the scope through the catalog before enforcement runs. Only aliases are rewritten: a service whose external key is not itself one of its credential scopes (CloudWatch Logs signs as logs) is left unchanged, as is any scope the catalog does not know. Also documents why SigV4a stays outside the unknown-service guard — its credential omits the region segment, so SigV4CredentialScope does not match it — and pins that with a test, since widening the pattern would silently start rejecting SigV4a traffic. Refs #1754 * fix(iot): declare the iot-jobs-data signing scope so its routes stay reachable The IoT Jobs Data Plane (GetPendingJobExecutions, DescribeJobExecution, StartNextPendingJobExecution, UpdateJobExecution) signs under iot-jobs-data while IotController serves its /things/{thing}/jobs routes. The scope was not in the catalog, so the unknown-service guard rejected requests to routes Floci does implement. The Go, Java and Python SDK compat suites all caught it on GetPendingJobExecutions. Audited the other sibling signing names for the same failure mode: ssmmessages, eks-auth, ecr-public, cognito-identity and aoss have no Floci routes, so rejecting those stays correct. Refs #1754 * fix(iam): scope alias normalisation to an explicit table Deriving the canonical scope from the descriptor's external key was wrong: the external key is a routing key, not an IAM namespace. SES routes under email and Bedrock Runtime under bedrock-runtime while their IAM namespaces are ses: and bedrock:, so ses, sesv2 and bedrock were rewritten onto prefixes AWS never issues. Every action would then resolve to null and enforcement would be skipped for those services — the same bypass the s3express fix closed. Replace the derivation with an explicit alias table holding the one case that genuinely shares a namespace, s3express -> s3, and sweep every scope the catalog declares in the test so any future rewrite has to be deliberate. Refs #1754 * fix(core): make the unknown-service guard configurable and verify scope coverage The guard is only as good as the catalog's scope list, and the iot-jobs-data miss showed the list can be wrong. Two changes so that is recoverable and detectable rather than a hard 404 nobody can work around. Gate the rejection behind floci.protocols.reject-unknown-service-scope, matching the other two abort paths in AwsProtocolClaimFilter, which are both already gated. It defaults to true so #1754 stays fixed out of the box; turning it off restores the previous fall-through for anyone blocked by a scope Floci has not enumerated yet. Add CredentialScopeCoverageTest, which walks botocore's models and fails when Floci routes most of a service's operations without declaring the name that service signs with. Removing iot-jobs-data from the catalog makes it fail with 'iot-jobs-data=2/3 routes served'. Thresholds are conservative because small services share generic templates, so it is a tripwire rather than a proof, and it skips where the gitignored botocore checkout is absent (CI runners). Refs #1754 * fix(iam): resolve the iot-jobs-data signing scope to the iot namespace Admitting iot-jobs-data to the catalog let the IoT Jobs Data Plane reach its routes, but IAM enforcement still saw the raw scope. Its policy actions live under iot: (iot:DescribeJobExecution and peers in the Service Authorization Reference), so the scope belongs in the alias table next to s3express. No behaviour change today: IamActionRegistry carries no iot rules at all, so every IoT request resolves to no action and is allowed through regardless. This makes the mapping correct ahead of those rules existing, rather than leaving a scope that would silently escape them. Refs #1754
This commit is contained in:
1 parent
2bea2c0aec
commit
836c162136
16 files changed
+774
-15
No files matched your search
@@ -86,6 +86,19 @@ public interface EmulatorConfig {
|
||||
*/
|
||||
@WithDefault("false")
|
||||
boolean strictClaiming();
|
||||
|
||||
/**
|
||||
* When enabled, a REST request whose SigV4 credential scope names a service
|
||||
* absent from the catalog is rejected with {@code UnknownOperationException}
|
||||
* instead of falling through JAX-RS matching into S3's path-style routes,
|
||||
* where it surfaces as a misleading {@code NoSuchBucket} (issue #1754).
|
||||
*
|
||||
* <p>On by default. Turn it off if Floci serves a route whose signing scope
|
||||
* is not yet enumerated in the catalog: the request then falls through as it
|
||||
* did before, rather than failing with a 404 that has no workaround.
|
||||
*/
|
||||
@WithDefault("true")
|
||||
boolean rejectUnknownServiceScope();
|
||||
}
|
||||
|
||||
interface DnsConfig {
|
||||
|
||||
@@ -21,6 +21,17 @@ import java.util.Optional;
|
||||
* filter (SQS queue URLs, S3 virtual hosts, Lambda URLs — default priority
|
||||
* 5000) and {@link AwsCborContentTypeFilter} (3000) has already produced the
|
||||
* final path and stashed the original content type.
|
||||
* <p>
|
||||
* Also rejects REST requests whose SigV4 credential scope names a service
|
||||
* absent from the catalog: without this they fall through JAX-RS matching
|
||||
* into S3's path-style wildcard routes and fail with misleading S3 XML
|
||||
* errors. This is not a catch-all — it fires only on positive identification
|
||||
* (a parseable SigV4 scope) of a service Floci does not enumerate; unsigned,
|
||||
* presigned, Bearer/Basic and SigV4a requests are untouched. SigV4a falls out
|
||||
* of scope because its credential omits the region segment
|
||||
* ({@code <key>/<date>/<service>/aws4_request}), which
|
||||
* {@link SigV4CredentialScope} does not match — widening that pattern would
|
||||
* silently start rejecting SigV4a traffic.
|
||||
*/
|
||||
@Provider
|
||||
@PreMatching
|
||||
@@ -32,13 +43,16 @@ public class AwsProtocolClaimFilter implements ContainerRequestFilter {
|
||||
private static final Logger LOG = Logger.getLogger(AwsProtocolClaimFilter.class);
|
||||
|
||||
private final ProtocolClaimer claimer;
|
||||
private final ResolvedServiceCatalog catalog;
|
||||
// Lazily resolved: JAX-RS providers are instantiated before runtime config
|
||||
// mappings exist (same pattern as GlobalCorsFilter).
|
||||
private final jakarta.inject.Provider<EmulatorConfig> configProvider;
|
||||
|
||||
@Inject
|
||||
public AwsProtocolClaimFilter(ProtocolClaimer claimer, jakarta.inject.Provider<EmulatorConfig> configProvider) {
|
||||
public AwsProtocolClaimFilter(ProtocolClaimer claimer, ResolvedServiceCatalog catalog,
|
||||
jakarta.inject.Provider<EmulatorConfig> configProvider) {
|
||||
this.claimer = claimer;
|
||||
this.catalog = catalog;
|
||||
this.configProvider = configProvider;
|
||||
}
|
||||
|
||||
@@ -59,6 +73,24 @@ public class AwsProtocolClaimFilter implements ContainerRequestFilter {
|
||||
|
||||
ProtocolClaim resolved = claim.get();
|
||||
ctx.setProperty(CLAIM_PROPERTY, resolved);
|
||||
if (resolved.protocol() == WireProtocol.REST) {
|
||||
Optional<String> scope = SigV4CredentialScope.serviceName(signals.authorization());
|
||||
if (scope.isPresent() && catalog.byCredentialScope(scope.get()).isEmpty()) {
|
||||
// Gated like the other rejections in this filter. The guard is only as good as
|
||||
// the catalog's scope list: if Floci serves a route whose signing scope is not
|
||||
// enumerated, rejecting is a 404 with no workaround, so leave users a switch.
|
||||
if (!configProvider.get().protocols().rejectUnknownServiceScope()) {
|
||||
LOG.debugv("Unsupported service scope {0} on {1} {2}, rejection disabled by config",
|
||||
scope.get(), signals.method(), signals.path());
|
||||
return;
|
||||
}
|
||||
LOG.infov("Rejecting request signed for unsupported service scope {0}: {1} {2}",
|
||||
scope.get(), signals.method(), signals.path());
|
||||
ctx.abortWith(unknownOperationResponse(404,
|
||||
"Unknown operation: " + signals.method() + " " + signals.path()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (resolved.protocol() == WireProtocol.RPCV2_JSON) {
|
||||
LOG.warnv("Received rpc-v2-json request for service {0} operation {1} — protocol not implemented",
|
||||
resolved.service() != null ? resolved.service().externalKey() : "unknown",
|
||||
@@ -79,6 +111,8 @@ public class AwsProtocolClaimFilter implements ContainerRequestFilter {
|
||||
return Response.status(status)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.header("x-amzn-query-error", "UnknownOperationException;Sender")
|
||||
// rest-json SDKs resolve the error code from this header before the body __type
|
||||
.header("X-Amzn-Errortype", "UnknownOperationException")
|
||||
.entity(new AwsErrorResponse("UnknownOperationException", message))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
private final IamConditionContextResolver conditionContextResolver;
|
||||
private final CloudTrailService cloudTrailService;
|
||||
private final CurrentVertxRequest currentVertxRequest;
|
||||
private final ResolvedServiceCatalog catalog;
|
||||
|
||||
@Inject
|
||||
public IamEnforcementFilter(EmulatorConfig config,
|
||||
@@ -70,7 +71,8 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
RequestContext requestContext,
|
||||
IamConditionContextResolver conditionContextResolver,
|
||||
CloudTrailService cloudTrailService,
|
||||
CurrentVertxRequest currentVertxRequest) {
|
||||
CurrentVertxRequest currentVertxRequest,
|
||||
ResolvedServiceCatalog catalog) {
|
||||
this.config = config;
|
||||
this.accountResolver = accountResolver;
|
||||
this.iamService = iamService;
|
||||
@@ -81,6 +83,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
this.conditionContextResolver = conditionContextResolver;
|
||||
this.cloudTrailService = cloudTrailService;
|
||||
this.currentVertxRequest = currentVertxRequest;
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,10 +102,14 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
|
||||
return; // root bypass
|
||||
}
|
||||
|
||||
String credentialScope = extractCredentialScope(auth);
|
||||
if (credentialScope == null) {
|
||||
String rawScope = extractCredentialScope(auth);
|
||||
if (rawScope == null) {
|
||||
return;
|
||||
}
|
||||
// Normalise signing aliases (s3express → s3) before anything keyed by scope runs:
|
||||
// action rules, ARN building and condition keys all match the canonical name, so an
|
||||
// alias would resolve to no action and be allowed through without any policy check.
|
||||
String credentialScope = catalog.canonicalCredentialScope(rawScope);
|
||||
|
||||
String action = actionRegistry.resolve(credentialScope, ctx);
|
||||
if (action == null) {
|
||||
|
||||
@@ -32,6 +32,18 @@ import java.util.Set;
|
||||
@ApplicationScoped
|
||||
public class ResolvedServiceCatalog {
|
||||
|
||||
/**
|
||||
* Signing scopes that share another service's IAM namespace. S3 Express One Zone clients sign
|
||||
* directory-bucket requests as {@code s3express} while the actions, ARNs and condition keys
|
||||
* remain {@code s3}; the IoT Jobs Data Plane signs as {@code iot-jobs-data} while its actions
|
||||
* are {@code iot:} ({@code iot:DescribeJobExecution} and peers in the Service Authorization
|
||||
* Reference). Keep this minimal: every entry suppresses a distinct IAM namespace.
|
||||
*/
|
||||
private static final java.util.Map<String, String> CREDENTIAL_SCOPE_ALIASES =
|
||||
java.util.Map.of(
|
||||
"s3express", "s3",
|
||||
"iot-jobs-data", "iot");
|
||||
|
||||
private final ServiceCatalog catalog;
|
||||
|
||||
@Inject
|
||||
@@ -51,7 +63,8 @@ public class ResolvedServiceCatalog {
|
||||
"s3", storageMode(config.storage().services().s3().mode(), config.storage().mode()),
|
||||
5000L, AwsNamespaces.S3, ServiceProtocol.REST_XML,
|
||||
protocols(ServiceProtocol.REST_XML),
|
||||
Set.of(), Set.of("s3"), Set.of(), Set.of()),
|
||||
// s3express: directory-bucket (S3 Express One Zone) clients sign with it
|
||||
Set.of(), Set.of("s3", "s3express"), Set.of(), Set.of()),
|
||||
descriptor("dynamodb", "dynamodb", config.services().dynamodb().enabled(), true,
|
||||
"dynamodb", storageMode(config.storage().services().dynamodb().mode(), config.storage().mode()),
|
||||
config.storage().services().dynamodb().flushIntervalMs(), null, ServiceProtocol.JSON,
|
||||
@@ -372,7 +385,11 @@ public class ResolvedServiceCatalog {
|
||||
descriptor("iot", "iot", config.services().iot().enabled(), true,
|
||||
"iot", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("iot", "execute-api"), Set.of(), Set.of(IotController.class)),
|
||||
// iot-jobs-data: the IoT Jobs Data Plane (GetPendingJobExecutions,
|
||||
// DescribeJobExecution, StartNextPendingJobExecution, UpdateJobExecution)
|
||||
// signs under its own name while IotController serves its /things/*/jobs routes
|
||||
Set.of(), Set.of("iot", "execute-api", "iot-jobs-data"), Set.of(),
|
||||
Set.of(IotController.class)),
|
||||
descriptor("iotdata", "iotdata", config.services().iotdata().enabled(), true,
|
||||
"iot", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
@@ -400,6 +417,23 @@ public class ResolvedServiceCatalog {
|
||||
return catalog.byCredentialScope(credentialScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonical IAM namespace for a credential scope. A service may answer requests signed
|
||||
* under more than one scope (S3 also accepts {@code s3express}), but IAM action rules,
|
||||
* resource ARNs and condition keys are all keyed by the canonical one — an alias left
|
||||
* unnormalised resolves to no action, which the enforcement filter treats as ALLOW.
|
||||
*
|
||||
* <p>Deliberately an explicit table rather than something derived from the descriptor:
|
||||
* a descriptor's external key is a routing key, not an IAM namespace. SES routes under
|
||||
* {@code email} and Bedrock Runtime under {@code bedrock-runtime}, while their IAM
|
||||
* namespaces are {@code ses:} and {@code bedrock:} — deriving from the external key would
|
||||
* rewrite valid scopes onto prefixes AWS never issues, and silently skip enforcement for
|
||||
* those services. Add an entry here only when two scopes genuinely share one namespace.
|
||||
*/
|
||||
public String canonicalCredentialScope(String credentialScope) {
|
||||
return CREDENTIAL_SCOPE_ALIASES.getOrDefault(credentialScope, credentialScope);
|
||||
}
|
||||
|
||||
public Optional<ServiceDescriptor> byResourceClass(Class<?> resourceClass) {
|
||||
return catalog.byResourceClass(resourceClass);
|
||||
}
|
||||
|
||||
@@ -128,4 +128,37 @@ public class EksController {
|
||||
FargateProfile profile = eksService.deleteFargateProfile(name, fargateProfileName);
|
||||
return Response.ok(Map.of("fargateProfile", profile)).build();
|
||||
}
|
||||
|
||||
// Read-only sub-resource lists for resources the emulator does not model. Explicit routes
|
||||
// so S3's path-style catch-all (@Path("/{bucket}/{key: .+}")) cannot swallow them
|
||||
// (issue #1754, same family as #1137): validate the cluster, then return the documented
|
||||
// empty list under each operation's model-exact result key.
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/access-entries")
|
||||
public Response listAccessEntries(@PathParam("name") String name) {
|
||||
eksService.describeCluster(name);
|
||||
return Response.ok(Map.of("accessEntries", List.of())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/addons")
|
||||
public Response listAddons(@PathParam("name") String name) {
|
||||
eksService.describeCluster(name);
|
||||
return Response.ok(Map.of("addons", List.of())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/identity-provider-configs")
|
||||
public Response listIdentityProviderConfigs(@PathParam("name") String name) {
|
||||
eksService.describeCluster(name);
|
||||
return Response.ok(Map.of("identityProviderConfigs", List.of())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/pod-identity-associations")
|
||||
public Response listPodIdentityAssociations(@PathParam("name") String name) {
|
||||
eksService.describeCluster(name);
|
||||
return Response.ok(Map.of("associations", List.of())).build();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user