feat(cloudfront): sign requests to a Lambda Web Function origin under OAC (#6037)

* feat(cloudfront): sign requests to a Lambda Web Function origin under OAC

CreateOriginAccessControl now takes always-amz-auth for the lambda origin
type and sigv4a for s3 and lambda, with the AWS validation messages.
Distributions check the origin access control of a Lambda origin as AWS
does, and refuse a Lambda@Edge origin trigger in front of an origin signed
with always-amz-auth or sigv4a.

Under always-amz-auth, CloudFront signs its requests to a Web Function
endpoint of this Floci for the distribution. An IamAuth endpoint lets them
through, or under IAM enforcement evaluates the function policy for
cloudfront.amazonaws.com with aws:SourceArn and aws:SourceAccount.

* fix(cloudfront): refuse unknown and in-use OAC changes as AWS does

A distribution naming an origin access control that does not exist is
InvalidOriginAccessControl. A control an origin uses can no longer change
its origin type, its signing protocol, or whether it is always-amz-auth,
which AWS answers with IllegalUpdate.

* fix(cloudfront): match a Lambda origin by the end of its hostname

CloudFront takes a Lambda origin only from a hostname under on.aws, and it matches the fixed labels case sensitively. Floci also takes one under its own host.

The CloudFront check and the caller check now share the endpoint condition keys. The docs say when CloudFront forwards the viewer Authorization.

* fix(cloudfront): read the Floci host for Lambda origins from the authority

URI.getHost is null for a host with an underscore, such as a Compose service name, which broke CloudFront at startup. The Web Function endpoints are named from the authority, so the match reads it the same way.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-20 08:26:11 -04:00
1 parent 1a598b7f0c
commit 8bff1ba0f3
9 files changed
+673 -68

No files matched your search

@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.config.LocalStackParity;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.CloudFrontEdgeDomain;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -34,6 +35,7 @@ import io.github.hectorvent.floci.services.iam.ServerCertificateReferenceProvide
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.net.URI;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.ArrayList;
@@ -51,6 +53,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ApplicationScoped
@@ -60,10 +63,12 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
private static final int MAX_CUSTOM_RESPONSE_HEADERS_POLICIES = 20;
private static final int MAX_DISTRIBUTIONS_PER_RESPONSE_HEADERS_POLICY = 100;
private static final SecureRandom RANDOM = new SecureRandom();
private static final Set<String> OAC_ORIGIN_TYPES =
Set.of("s3", "mediastore", "mediapackagev2", "lambda");
private static final Set<String> OAC_SIGNING_BEHAVIORS =
Set.of("always", "never", "no-override");
/** The enum values in the order AWS lists them. */
private static final List<String> OAC_ORIGIN_TYPES =
List.of("s3", "execute-api", "lambda", "mediastore", "mediapackagev2");
private static final List<String> OAC_SIGNING_PROTOCOLS = List.of("sigv4", "sigv4a");
private static final List<String> OAC_SIGNING_BEHAVIORS =
List.of("always-amz-auth", "never", "always", "no-override");
private static final Set<String> FUNCTION_RUNTIMES = Set.of("cloudfront-js-1.0", "cloudfront-js-2.0");
private static final int MAX_ORIGIN_CUSTOM_HEADERS = 30;
private static final int MAX_CUSTOM_HEADER_NAME_LENGTH = 256;
@@ -139,6 +144,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
* certificate, so a signed URL for either can be downloaded over HTTPS.
*/
private final List<String> localDeliverySuffixes;
private final Pattern lambdaOriginHost;
public CloudFrontService(StorageFactory factory, EmulatorConfig config, RegionResolver regionResolver) {
this(factory, config, regionResolver, null);
@@ -186,6 +192,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
this.regionResolver = regionResolver;
this.configuredDomainSuffix = config.services().cloudfront().domainSuffix().orElse(null);
this.localDeliverySuffixes = localDeliverySuffixes(config);
this.lambdaOriginHost = lambdaOriginHost(config);
}
// ── Distributions ─────────────────────────────────────────────────────────
@@ -195,6 +202,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
validateOriginCustomHeaders(dist.getConfig());
validateResponseHeadersPolicyReferences(dist.getConfig(), null);
validateTrustedKeyGroups(dist.getConfig());
validateOriginAccessControls(dist.getConfig());
return whileCertificatesHeld(dist.getConfig(), () -> {
validateViewerCertificate(dist.getConfig());
String id = generateDistributionId();
@@ -228,6 +236,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
validateOriginCustomHeaders(updated.getConfig());
validateResponseHeadersPolicyReferences(updated.getConfig(), id);
validateTrustedKeyGroups(updated.getConfig());
validateOriginAccessControls(updated.getConfig());
return whileCertificatesHeld(updated.getConfig(), () -> {
validateViewerCertificate(updated.getConfig());
updated.setId(id);
@@ -1132,6 +1141,9 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
"The If-Match version is missing or not valid for the resource.", 400);
}
validateOriginAccessControl(updated);
if (changesHowItSigns(existing, updated) && originAccessControlInUse(id)) {
throw new AwsException("IllegalUpdate", "Cannot update origin type when associated to origins.", 400);
}
updated.setId(id);
updated.setEtag(UUID.randomUUID().toString());
updated.setLastModifiedTime(Instant.now());
@@ -1222,29 +1234,166 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
throw new AwsException("InvalidArgument",
"The origin access control configuration is required.", 400);
}
if (oac.getName() == null || oac.getName().isBlank()) {
throw new AwsException("InvalidArgument", "The parameter Name is required.", 400);
List<String> violations = new ArrayList<>();
addEnumViolation(violations, "originAccessControlOriginType", oac.getOriginAccessControlOriginType(),
OAC_ORIGIN_TYPES);
addEnumViolation(violations, "signingProtocol", oac.getSigningProtocol(), OAC_SIGNING_PROTOCOLS);
addEnumViolation(violations, "signingBehavior", oac.getSigningBehavior(), OAC_SIGNING_BEHAVIORS);
if (oac.getName() == null) {
violations.add(nullViolation("name"));
}
if (!violations.isEmpty()) {
throw SmithyValidationErrors.exception("MalformedXML", violations);
}
if (oac.getName().isEmpty()) {
throw new AwsException("InvalidArgument", "The parameter Name is too small or empty.", 400);
}
if (oac.getName().length() > 64) {
throw new AwsException("InvalidArgument",
"The parameter Name must be 64 characters or fewer.", 400);
throw new AwsException("InvalidArgument", "The parameter Name is too big.", 400);
}
if (!"sigv4".equals(oac.getSigningProtocol())) {
String originType = oac.getOriginAccessControlOriginType();
if ("always-amz-auth".equals(oac.getSigningBehavior()) && !"lambda".equals(originType)) {
throw new AwsException("InvalidArgument",
"The parameter SigningProtocol must be sigv4.", 400);
"The parameter SigningBehavior always-amz-auth is only supported with lambda origin type.", 400);
}
if (oac.getSigningBehavior() == null
|| !OAC_SIGNING_BEHAVIORS.contains(oac.getSigningBehavior())) {
if ("sigv4a".equals(oac.getSigningProtocol()) && !"s3".equals(originType) && !"lambda".equals(originType)) {
throw new AwsException("InvalidArgument",
"The parameter SigningBehavior must be one of always, never, or no-override.",
400);
"The parameter OriginType sigv4a is only supported with s3 or lambda origin types.", 400);
}
if (oac.getOriginAccessControlOriginType() == null
|| !OAC_ORIGIN_TYPES.contains(oac.getOriginAccessControlOriginType())) {
throw new AwsException("InvalidArgument",
"The parameter OriginAccessControlOriginType must be one of s3, mediastore, "
+ "mediapackagev2, or lambda.",
400);
if ("execute-api".equals(originType)) {
// AWS lists this origin type but refuses it.
throw new AwsException("AccessDenied", "Access Denied.", 403);
}
}
/** What an origin access control may not change while an origin uses it. */
private static boolean changesHowItSigns(OriginAccessControl existing, OriginAccessControl updated) {
return !Objects.equals(existing.getOriginAccessControlOriginType(), updated.getOriginAccessControlOriginType())
|| !Objects.equals(existing.getSigningProtocol(), updated.getSigningProtocol())
|| "always-amz-auth".equals(existing.getSigningBehavior())
!= "always-amz-auth".equals(updated.getSigningBehavior());
}
private static void addEnumViolation(List<String> violations, String member, String value, List<String> values) {
if (value == null) {
violations.add(nullViolation(member));
} else if (!values.contains(value)) {
violations.add("Value '" + value + "' at 'originAccessControlConfig." + member
+ "' failed to satisfy constraint: Member must satisfy enum value set: ["
+ String.join(", ", values) + "]");
}
}
private static String nullViolation(String member) {
return "Value null at 'originAccessControlConfig." + member
+ "' failed to satisfy constraint: Member must not be null";
}
/** The kinds of Lambda origin CloudFront tells apart. */
private enum LambdaOrigin { NONE, FUNCTION_URL, WEB_FUNCTION, GLOBAL_WEB_FUNCTION }
/**
* CloudFront knows a Lambda origin by its hostname alone, case sensitively. The endpoints of this
* Floci end in its own host instead of {@code on.aws}.
*/
private static Pattern lambdaOriginHost(EmulatorConfig config) {
String authority = URI.create(config.effectiveBaseUrl()).getAuthority();
String flociHost = Pattern.quote(authority.replaceFirst(":\\d+$", "")) + "(?::\\d+)?";
return Pattern.compile(".+\\.(lambda-web|lambda-url)\\.(global|[a-z]{2,4}-[a-z-]+-\\d+)\\.(?:on\\.aws|"
+ flociHost + ")");
}
private LambdaOrigin lambdaOrigin(String domainName) {
Matcher matcher = lambdaOriginHost.matcher(domainName == null ? "" : domainName);
if (!matcher.matches()) {
return LambdaOrigin.NONE;
}
boolean global = "global".equals(matcher.group(2));
if ("lambda-url".equals(matcher.group(1))) {
return global ? LambdaOrigin.NONE : LambdaOrigin.FUNCTION_URL;
}
return global ? LambdaOrigin.GLOBAL_WEB_FUNCTION : LambdaOrigin.WEB_FUNCTION;
}
/**
* The origin access control an origin names has to exist, and suit a Lambda origin by the rules
* CloudFront checks in this order. Then come the Lambda@Edge origin triggers it refuses in front
* of the origins those controls sign.
*/
private void validateOriginAccessControls(DistributionConfig config) {
if (config == null || config.getOrigins() == null) {
return;
}
Set<String> amzAuthOrigins = new HashSet<>();
for (Origin origin : config.getOrigins()) {
String oacId = origin == null ? null : origin.getOriginAccessControlId();
if (oacId == null || oacId.isBlank()) {
continue;
}
Optional<OriginAccessControl> oac = oacStore.get(oacId);
if (oac.isEmpty()) {
throw new AwsException("InvalidOriginAccessControl",
"The specified origin access control does not exist or is not valid.", 400);
}
validateOriginAccessControlFor(lambdaOrigin(origin.getDomainName()), oac.get());
if ("always-amz-auth".equals(oac.get().getSigningBehavior())
|| "sigv4a".equals(oac.get().getSigningProtocol())) {
amzAuthOrigins.add(origin.getId());
}
}
if (config.getDefaultCacheBehavior() != null) {
rejectOriginTriggers(amzAuthOrigins, config.getDefaultCacheBehavior().getTargetOriginId(),
config.getDefaultCacheBehavior().getLambdaFunctionAssociations());
}
if (config.getCacheBehaviors() != null) {
for (CacheBehavior behavior : config.getCacheBehaviors()) {
rejectOriginTriggers(amzAuthOrigins, behavior.getTargetOriginId(),
behavior.getLambdaFunctionAssociations());
}
}
}
private static void validateOriginAccessControlFor(LambdaOrigin origin, OriginAccessControl oac) {
boolean lambda = "lambda".equals(oac.getOriginAccessControlOriginType());
boolean webFunction = origin == LambdaOrigin.WEB_FUNCTION || origin == LambdaOrigin.GLOBAL_WEB_FUNCTION;
if (webFunction ? !lambda : (lambda && origin == LambdaOrigin.NONE)) {
throw illegalOriginAccessConfiguration("The origin type and OAC origin type differ");
}
if (!lambda) {
return;
}
boolean sigv4a = "sigv4a".equals(oac.getSigningProtocol());
if (origin == LambdaOrigin.GLOBAL_WEB_FUNCTION && !sigv4a) {
throw illegalOriginAccessConfiguration("This origin domain requires SigV4a signing protocol.");
}
if (origin != LambdaOrigin.GLOBAL_WEB_FUNCTION && sigv4a) {
throw illegalOriginAccessConfiguration("SigV4a signing protocol is not compatible with this origin domain.");
}
boolean amzAuth = "always-amz-auth".equals(oac.getSigningBehavior());
if (webFunction && !amzAuth) {
throw illegalOriginAccessConfiguration("Lambda-Web origins require always-amz-auth signing behavior.");
}
if (!webFunction && amzAuth) {
throw illegalOriginAccessConfiguration("always-amz-auth signing behavior requires a Lambda-Web origin.");
}
}
private static AwsException illegalOriginAccessConfiguration(String reason) {
return new AwsException("IllegalOriginAccessConfiguration", "Illegal configuration: " + reason, 400);
}
private static void rejectOriginTriggers(Set<String> amzAuthOrigins, String targetOriginId,
List<Map<String, Object>> associations) {
if (!amzAuthOrigins.contains(targetOriginId) || associations == null) {
return;
}
for (Map<String, Object> association : associations) {
Object eventType = association.get("EventType");
if ("origin-request".equals(eventType) || "origin-response".equals(eventType)) {
throw new AwsException("InvalidLambdaFunctionAssociation",
"Lambda@Edge origin triggers are incompatible with SigV4a and always-amz-auth origins."
+ " Use a different origin or disassociate the function.", 400);
}
}
}
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.Distribution;
import io.github.hectorvent.floci.services.cloudfront.model.DistributionConfig;
import io.github.hectorvent.floci.services.cloudfront.model.Origin;
import io.github.hectorvent.floci.services.cloudfront.model.OriginAccessControl;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebIamAuth;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebService;
import io.github.hectorvent.floci.services.s3.ByteRange;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -109,6 +110,7 @@ public class CloudFrontServingController {
private final CloudFrontService service;
private final S3Service s3Service;
private final LambdaWebService lambdaWebService;
private final LambdaWebIamAuth lambdaWebIamAuth;
private final CurrentVertxRequest currentVertxRequest;
private final HttpServer httpServer;
private final CloudFrontOriginHttpClient httpClient;
@@ -116,11 +118,13 @@ public class CloudFrontServingController {
@Inject
public CloudFrontServingController(CloudFrontService service, S3Service s3Service,
LambdaWebService lambdaWebService, EmulatorConfig emulatorConfig,
CurrentVertxRequest currentVertxRequest, HttpServer httpServer) {
LambdaWebService lambdaWebService, LambdaWebIamAuth lambdaWebIamAuth,
EmulatorConfig emulatorConfig, CurrentVertxRequest currentVertxRequest,
HttpServer httpServer) {
this.service = service;
this.s3Service = s3Service;
this.lambdaWebService = lambdaWebService;
this.lambdaWebIamAuth = lambdaWebIamAuth;
this.currentVertxRequest = currentVertxRequest;
this.httpServer = httpServer;
this.httpClient = new CloudFrontOriginHttpClient(
@@ -496,7 +500,7 @@ public class CloudFrontServingController {
CloudFrontOriginRequestBuilder.build(viewerRequest(method, viewerScheme),
forwarding(config, normalized), distribution.getDomainName());
return fetchFromCustomOrigin(
origin, forwardUri, originRequest, viewerScheme, method, viewerBody);
distribution, origin, forwardUri, originRequest, viewerScheme, method, viewerBody);
}
/** The live viewer request, with CloudFront's signing parameters removed from its query. */
@@ -763,7 +767,7 @@ public class CloudFrontServingController {
* Fetches from a custom (non-S3) origin. {@code forwardUri} already includes the origin path;
* {@code originRequest} carries the forwarded query and headers.
*/
private OriginResponse fetchFromCustomOrigin(Origin origin, String forwardUri,
private OriginResponse fetchFromCustomOrigin(Distribution distribution, Origin origin, String forwardUri,
CloudFrontOriginRequestBuilder.OriginRequest originRequest,
String viewerScheme, String method, ViewerBody viewerBody) {
boolean includeBody = !"HEAD".equals(method);
@@ -797,6 +801,9 @@ public class CloudFrontServingController {
}
if (webEndpoint != null) {
originHeaders.put("Host", webEndpoint);
if (alwaysAmzAuth(origin)) {
originHeaders.putAll(lambdaWebIamAuth.cloudFrontSignature(distribution.getArn()));
}
}
rb.method(method, HttpRequest.BodyPublishers.noBody());
// Both bodies are streamed, so neither has to fit in memory: the viewer's goes out with its
@@ -829,6 +836,13 @@ public class CloudFrontServingController {
}
}
/** Whether the origin's access control is always-amz-auth, the one a Web Function origin is signed under. */
private boolean alwaysAmzAuth(Origin origin) {
String oacId = origin.getOriginAccessControlId();
return oacId != null && !oacId.isBlank()
&& "always-amz-auth".equals(service.getOriginAccessControl(oacId).getSigningBehavior());
}
private String webFunctionEndpoint(Origin origin) {
try {
return lambdaWebService.endpointDomain(normalizeOriginHost(origin.getDomainName())).orElse(null);
@@ -1056,7 +1070,7 @@ public class CloudFrontServingController {
} else {
String forwardUri = CloudFrontRequestRouter.resolveForwardUri(errOrigin.getOriginPath(), errNormalized, null);
page = fetchFromCustomOrigin(
errOrigin, forwardUri, CloudFrontOriginRequestBuilder.OriginRequest.empty(),
distribution, errOrigin, forwardUri, CloudFrontOriginRequestBuilder.OriginRequest.empty(),
viewerScheme, includeBody ? "GET" : "HEAD", null);
}
if (page.status() >= 400) {
@@ -1,8 +1,10 @@
package io.github.hectorvent.floci.services.lambdaweb;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.IamConditionContextResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.ServicePrincipals;
import io.github.hectorvent.floci.core.common.auth.CredentialScope;
import io.github.hectorvent.floci.core.common.auth.SessionTokenCheck;
import io.github.hectorvent.floci.core.common.auth.SigV4Canonicalization;
@@ -27,9 +29,13 @@ import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -39,6 +45,10 @@ import java.util.Optional;
* signature for the service {@code lambda} in the endpoint's region, then
* {@code lambda:InvokeWebFunctionEndpoint} on the endpoint ARN. The signature is always checked.
* The policies are evaluated when IAM enforcement is on, as everywhere else in Floci.
*
* <p>CloudFront signs for a distribution under an {@code always-amz-auth} origin access control.
* Floci's CloudFront stands in for that signature with the {@code lambda-web-cloudfront-*} headers,
* which carry the distribution and a key only this process knows. The function never sees them.
*/
@ApplicationScoped
public class LambdaWebIamAuth {
@@ -48,11 +58,14 @@ public class LambdaWebIamAuth {
private static final String SERVICE = "lambda";
private static final String SECURITY_TOKEN = "X-Amz-Security-Token";
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";
private final EmulatorConfig config;
private final IamService iamService;
private final IamPolicyEvaluator evaluator;
private final Instance<ScpProvider> scpProvider;
private final String cloudFrontKey;
@Inject
public LambdaWebIamAuth(EmulatorConfig config, IamService iamService, IamPolicyEvaluator evaluator,
@@ -61,6 +74,14 @@ public class LambdaWebIamAuth {
this.iamService = iamService;
this.evaluator = evaluator;
this.scpProvider = scpProvider;
byte[] key = new byte[32];
new SecureRandom().nextBytes(key);
this.cloudFrontKey = HexFormat.of().formatHex(key);
}
/** The headers CloudFront signs an origin request with for {@code distributionArn}. */
public Map<String, String> cloudFrontSignature(String distributionArn) {
return Map.of(CLOUDFRONT_SOURCE_ARN, distributionArn, CLOUDFRONT_KEY, cloudFrontKey);
}
/** What the checks read from a request, copied on the event loop so a worker can check it. */
@@ -87,10 +108,45 @@ public class LambdaWebIamAuth {
* storage, is thrown rather than taken for a refusal. Blocks on IAM storage.
*/
public boolean allows(Inbound request, WebFunctionTarget target) {
String distributionArn = cloudFrontSource(request);
if (distributionArn != null) {
return authorizeCloudFront(distributionArn, target);
}
String accessKeyId = authenticate(request, target.region());
return accessKeyId != null && authorize(accessKeyId, target);
}
/** The distribution CloudFront signed the request for, or null when it did not sign it. */
private String cloudFrontSource(Inbound request) {
String key = request.headers().get(CLOUDFRONT_KEY);
String distributionArn = request.headers().get(CLOUDFRONT_SOURCE_ARN);
if (key == null || !AwsArnUtils.isArn(distributionArn) || !MessageDigest.isEqual(
key.getBytes(StandardCharsets.UTF_8), cloudFrontKey.getBytes(StandardCharsets.UTF_8))) {
return null;
}
return distributionArn;
}
/** CloudFront calls as its service principal, so the function's resource policy decides alone. */
private boolean authorizeCloudFront(String distributionArn, WebFunctionTarget target) {
if (!config.services().iam().enforcementEnabled()) {
return true;
}
String principal = ServicePrincipals.of("cloudfront");
String endpointArn = target.endpoint().endpointArn;
Map<String, List<String>> context = resourceContext(target);
context.putAll(IamConditionContextResolver.serviceCallContext(principal, endpointArn, target.accountId(),
distributionArn, AwsArnUtils.parse(distributionArn).accountId()));
String policy = target.function().policy;
boolean allowed = evaluator.evaluateServicePrincipal(isBlank(policy) ? null : List.of(policy), principal,
ACTION, endpointArn, context) == Decision.ALLOW;
if (!allowed) {
LOG.infov("IAM enforcement DENY: service={0} action={1} resource={2} source={3}",
principal, ACTION, endpointArn, distributionArn);
}
return allowed;
}
/** The access key that signed the request, or null when the signature does not hold. */
private String authenticate(Inbound request, String region) {
Signed found = signed(request);
@@ -219,9 +275,7 @@ public class LambdaWebIamAuth {
if (scpLevels != null) {
caller = caller.withScpLevels(scpLevels);
}
Map<String, List<String>> context = new HashMap<>();
context.put("lambda:Resource/WebFunctionAuthType", List.of(target.endpoint().authType));
target.function().tags.forEach((key, value) -> context.put("aws:ResourceTag/" + key, List.of(value)));
Map<String, List<String>> context = resourceContext(target);
Optional<CallerArns> callerArns = iamService.resolveCallerArns(accessKeyId);
if (callerArns.isPresent()) {
caller = caller.withPrincipalArn(callerArns.get().callerArn());
@@ -240,6 +294,13 @@ public class LambdaWebIamAuth {
!= Decision.DENY;
}
private static Map<String, List<String>> resourceContext(WebFunctionTarget target) {
Map<String, List<String>> context = new HashMap<>();
context.put("lambda:Resource/WebFunctionAuthType", List.of(target.endpoint().authType));
target.function().tags.forEach((key, value) -> context.put("aws:ResourceTag/" + key, List.of(value)));
return context;
}
private static boolean isBlank(String value) {
return value == null || value.isBlank();
}