fix(lambdaweb): give the code bucket check the version as s3:VersionId (#6483)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-25 07:39:20 -04:00
1 parent 3dc5d356d0
commit 8f3a6eafeb
6 files changed
+61 -10

No files matched your search

@@ -59,6 +59,15 @@ public class ServiceCallAuthorizer {
*/
public Decision authorize(String service, String action, String resourceArn,
String sourceArn, String sourceAccount) {
return authorize(service, action, resourceArn, sourceArn, sourceAccount, Map.of());
}
/**
* As {@link #authorize(String, String, String, String, String)}, with the keys the target
* service adds for the request, such as {@code s3:versionid} for an object version.
*/
public Decision authorize(String service, String action, String resourceArn, String sourceArn,
String sourceAccount, Map<String, List<String>> requestKeys) {
if (!config.services().iam().enforcementEnabled()) {
return Decision.ALLOW;
}
@@ -73,6 +82,7 @@ public class ServiceCallAuthorizer {
.toList();
Map<String, List<String>> context = IamConditionContextResolver.serviceCallContext(
servicePrincipal, resourceArn, ownerAccountId, sourceArn, sourceAccount);
context.putAll(requestKeys);
Decision decision = evaluator.evaluateServicePrincipal(
documents.isEmpty() ? null : documents, servicePrincipal, action, resourceArn, context);
if (decision == Decision.DENY) {
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.IamConditionContextResolver;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -640,7 +641,8 @@ public class LambdaWebService implements Resettable {
throw new AwsException("ValidationException", "Zipped size must be smaller than "
+ LambdaWebCode.MAX_BYTES + " bytes", 400);
}
requireLambdaCanRead(fn, revision);
requireLambdaCanRead(fn, revision,
build.versionId != null ? build.versionId : object.object().getVersionId());
size = code.store(accountId, region, fn.functionName, revision.revisionId, object.body());
} catch (IOException e) {
throw new UncheckedIOException("Could not close the code object s3://" + build.bucket + "/" + build.key, e);
@@ -663,13 +665,14 @@ public class LambdaWebService implements Resettable {
}
/** AWS evaluates only s3:GetObjectVersion, although its message names both actions. */
private void requireLambdaCanRead(WebFunction fn, WebFunctionRevision revision) {
private void requireLambdaCanRead(WebFunction fn, WebFunctionRevision revision, String versionId) {
WebFunctionRevision.BuildConfig build = revision.buildConfig;
AwsArnUtils.Arn function = AwsArnUtils.parse(fn.functionArn);
String objectArn = AwsArnUtils.Arn.global(function.partition(), "s3", "", build.bucket + "/" + build.key)
.toString();
if (serviceCalls.authorize("lambda", "s3:GetObjectVersion", objectArn, revision.revisionArn,
function.accountId()) == Decision.DENY) {
function.accountId(), Map.of(IamConditionContextResolver.VERSION_ID, List.of(versionId)))
== Decision.DENY) {
throw new AwsException("ValidationException", "Lambda service principal " + ServicePrincipals.of("lambda")
+ " does not have s3:GetObject and s3:GetObjectVersion permission on s3://" + build.bucket + "/"
+ build.key + ". Update the bucket policy to grant the Lambda service principal access and retry.",