mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): resolve background layers in their function account (#6162)
Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
52c54834b0
commit
2ecc01b3e5
8 files changed
+250
-4
No files matched your search
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.lambda;
|
||||
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.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.FileTrees;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
@@ -465,6 +466,36 @@ public class LambdaLayerService {
|
||||
return layerStore.get(region, layerName, version).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves initialization input against the stored function's scope. Provisioned workers
|
||||
* run outside a request; the ambient account must not select another account's layer.
|
||||
* Cross-account sharing remains unsupported.
|
||||
*/
|
||||
public LambdaLayerVersion resolveLayerByArnForAccount(
|
||||
String layerVersionArn, String accountId, String functionRegion) {
|
||||
AwsArnUtils.Arn arn = parseLayerVersionArn(layerVersionArn);
|
||||
if (arn == null || accountId == null || accountId.isBlank()
|
||||
|| functionRegion == null || functionRegion.isBlank()
|
||||
|| !"lambda".equals(arn.service())
|
||||
|| AwsArnUtils.isForeignPartition(arn, AwsRegions.partitionFor(functionRegion))
|
||||
|| AwsArnUtils.isForeignAccount(arn, accountId)) {
|
||||
return null;
|
||||
}
|
||||
String[] resourceParts = arn.resource().split(":");
|
||||
if (resourceParts.length != 3) {
|
||||
return null;
|
||||
}
|
||||
long version;
|
||||
try {
|
||||
version = Long.parseLong(resourceParts[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
return layerStore.getForAccount(accountId, arn.region(), resourceParts[1], version)
|
||||
.filter(layer -> layerVersionArn.equals(layer.getLayerVersionArn()))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the ARN is a well-formed layer version ARN naming an account or partition other
|
||||
* than the caller's, so Floci cannot decide whether it exists. On the live service such a
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaLayerVersion;
|
||||
@@ -38,6 +40,16 @@ public class LambdaLayerStore {
|
||||
return backend.get(key(region, layerName, version));
|
||||
}
|
||||
|
||||
/** Resolves an owned layer from an async worker without a request account context. */
|
||||
public Optional<LambdaLayerVersion> getForAccount(
|
||||
String accountId, String region, String layerName, long version) {
|
||||
if (backend instanceof AccountAwareStorageBackend<LambdaLayerVersion> aware) {
|
||||
return aware.getForAccountMigratingLegacy(accountId, key(region, layerName, version),
|
||||
layer -> accountId.equals(AwsArnUtils.accountOrDefault(layer.getLayerVersionArn(), "")));
|
||||
}
|
||||
return backend.get(key(region, layerName, version));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all versions of a given layer in a region, sorted by version ascending.
|
||||
*/
|
||||
|
||||
+2
-1
@@ -389,7 +389,8 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
// 3. Copy layer contents into /opt (layers are merged in order)
|
||||
if (fn.getLayers() != null && !fn.getLayers().isEmpty()) {
|
||||
for (String layerArn : fn.getLayers()) {
|
||||
LambdaLayerVersion layer = layerService.resolveLayerByArn(layerArn);
|
||||
LambdaLayerVersion layer = layerService.resolveLayerByArnForAccount(
|
||||
layerArn, lambdaAccountId, lambdaRegion);
|
||||
if (layer != null && layer.getCodeLocalPath() != null) {
|
||||
Path layerPath = Path.of(layer.getCodeLocalPath());
|
||||
if (Files.exists(layerPath)) {
|
||||
|
||||
+3
-3
@@ -180,7 +180,7 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher {
|
||||
String cwLogStream = logStreamer.logStreamName(fn, shortId);
|
||||
|
||||
String codeDownloadUrl = imagePackage ? null : codeDownloadUrl(fn, region);
|
||||
List<String> layerUrls = imagePackage ? List.of() : layerDownloadUrls(fn, region);
|
||||
List<String> layerUrls = imagePackage ? List.of() : layerDownloadUrls(fn, accountId, region);
|
||||
|
||||
Optional<String> caConfigMap = ContainerCaBundle.hostPath(config).map(bundle -> ensureCaConfigMap(namespace, bundle));
|
||||
|
||||
@@ -401,13 +401,13 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher {
|
||||
return downloadUrl(bucket, key, account, region);
|
||||
}
|
||||
|
||||
private List<String> layerDownloadUrls(LambdaFunction fn, String functionRegion) {
|
||||
private List<String> layerDownloadUrls(LambdaFunction fn, String accountId, String functionRegion) {
|
||||
if (fn.getLayers() == null || fn.getLayers().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String layerArn : fn.getLayers()) {
|
||||
LambdaLayerVersion layer = layerService.resolveLayerByArn(layerArn);
|
||||
LambdaLayerVersion layer = layerService.resolveLayerByArnForAccount(layerArn, accountId, functionRegion);
|
||||
if (layer == null) {
|
||||
LOG.warnv("Could not resolve layer ARN {0} for function {1}", layerArn, fn.getFunctionName());
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user