mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(lambda): preserve owner account for execution logs (#3787)
* fix(lambda): preserve owner account for execution logs * test(lambda): cover account-aware log streaming
This commit is contained in:
1 parent
008aa9ba35
commit
5cb1453f4e
7 files changed
+91
-23
No files matched your search
+11
-1
@@ -141,7 +141,12 @@ public class ContainerLogStreamer {
|
||||
*/
|
||||
public ResultCallback.Adapter<Frame> execLogCallback(String logGroup, String logStream,
|
||||
String region, String logPrefix) {
|
||||
return frameCallback(null, logGroup, logStream, region, logPrefix);
|
||||
return execLogCallbackForAccount(null, logGroup, logStream, region, logPrefix);
|
||||
}
|
||||
|
||||
public ResultCallback.Adapter<Frame> execLogCallbackForAccount(
|
||||
String accountId, String logGroup, String logStream, String region, String logPrefix) {
|
||||
return frameCallback(accountId, logGroup, logStream, region, logPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,6 +214,11 @@ public class ContainerLogStreamer {
|
||||
forwardToCloudWatchLogs(null, logGroup, logStream, region, line);
|
||||
}
|
||||
|
||||
public void streamToCloudWatchLogsForAccount(
|
||||
String accountId, String logGroup, String logStream, String region, String line) {
|
||||
forwardToCloudWatchLogs(accountId, logGroup, logStream, region, line);
|
||||
}
|
||||
|
||||
private void forwardToCloudWatchLogs(
|
||||
String accountId, String logGroup, String logStream, String region, String line) {
|
||||
try {
|
||||
|
||||
+11
-7
@@ -414,8 +414,10 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
// Extensions can log as soon as they start, which is before the container's own log stream
|
||||
// is attached below. Create the group/stream up front so those early lines are not dropped
|
||||
// by CloudWatch; the call is idempotent, so attach() repeating it is harmless.
|
||||
LogDestination logDestination = new LogDestination(cwLogGroup, cwLogStream, lambdaRegion);
|
||||
logStreamer.ensureLogGroupAndStream(cwLogGroup, cwLogStream, lambdaRegion);
|
||||
LogDestination logDestination = new LogDestination(
|
||||
lambdaAccountId, cwLogGroup, cwLogStream, lambdaRegion);
|
||||
logStreamer.ensureLogGroupAndStreamForAccount(
|
||||
lambdaAccountId, cwLogGroup, cwLogStream, lambdaRegion);
|
||||
|
||||
// Real AWS's runtime interface client discovers and launches every binary under
|
||||
// /opt/extensions/ as a sibling process to the main entrypoint before the runtime is
|
||||
@@ -440,8 +442,9 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
LambdaExecutionRoleCredentials.sessionAccountId(fn));
|
||||
|
||||
// Attach log streaming
|
||||
Closeable logHandle = logStreamer.attach(
|
||||
containerId, cwLogGroup, cwLogStream, lambdaRegion, "lambda:" + fn.getFunctionName());
|
||||
Closeable logHandle = logStreamer.attachForAccount(
|
||||
lambdaAccountId, containerId, cwLogGroup, cwLogStream,
|
||||
lambdaRegion, "lambda:" + fn.getFunctionName());
|
||||
handle.setLogStream(logHandle);
|
||||
|
||||
return handle;
|
||||
@@ -1304,7 +1307,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
* (or other extensions) from running.
|
||||
*/
|
||||
/** Where a container's output is sent: the CloudWatch log group/stream and its region. */
|
||||
private record LogDestination(String logGroup, String logStream, String region) { }
|
||||
private record LogDestination(String accountId, String logGroup, String logStream, String region) { }
|
||||
|
||||
/**
|
||||
* Arms an async watch (via Docker's own wait-for-exit API, not polling) that notices when
|
||||
@@ -1360,8 +1363,9 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
// the container log and an observability extension's output would vanish entirely.
|
||||
// Draining is also required in its own right — an unread exec pipe fills up and
|
||||
// stalls the extension process.
|
||||
dockerClient.execStartCmd(execId).exec(logStreamer.execLogCallback(
|
||||
logDestination.logGroup(), logDestination.logStream(), logDestination.region(),
|
||||
dockerClient.execStartCmd(execId).exec(logStreamer.execLogCallbackForAccount(
|
||||
logDestination.accountId(), logDestination.logGroup(), logDestination.logStream(),
|
||||
logDestination.region(),
|
||||
"lambda:" + functionName + ":" + name));
|
||||
LOG.infov("Launched extension {0} for function {1} (container {2})",
|
||||
name, functionName, containerId);
|
||||
|
||||
+3
-2
@@ -164,6 +164,7 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher {
|
||||
var shortId = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
podName = LambdaPodSpecFactory.podName(fn.getFunctionName(), shortId);
|
||||
var region = AwsArnUtils.regionOrDefault(fn.getFunctionArn(), config.defaultRegion());
|
||||
String accountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId());
|
||||
var cwLogGroup = "/aws/lambda/" + fn.getFunctionName();
|
||||
var cwLogStream = logStreamer.logStreamName(shortId);
|
||||
|
||||
@@ -222,8 +223,8 @@ public class KubernetesPodLauncher implements LambdaRuntimeLauncher {
|
||||
// so a failure here (e.g. a missing pods/log RBAC verb) must not tear down a
|
||||
// healthy execution environment.
|
||||
try {
|
||||
var logHandle = logStreamer.attach(namespace, podName, cwLogGroup, cwLogStream,
|
||||
region, "lambda:" + fn.getFunctionName());
|
||||
var logHandle = logStreamer.attachForAccount(accountId, namespace, podName,
|
||||
cwLogGroup, cwLogStream, region, "lambda:" + fn.getFunctionName());
|
||||
handle.setLogStream(logHandle);
|
||||
} catch (Exception logFailure) {
|
||||
LOG.warnv("Log streaming for pod {0} could not start; the environment still "
|
||||
|
||||
+8
-2
@@ -39,7 +39,12 @@ public class KubernetesPodLogStreamer {
|
||||
|
||||
public Closeable attach(String namespace, String podName, String logGroup,
|
||||
String logStream, String region, String logPrefix) {
|
||||
cloudWatchWriter.ensureLogGroupAndStream(logGroup, logStream, region);
|
||||
return attachForAccount(null, namespace, podName, logGroup, logStream, region, logPrefix);
|
||||
}
|
||||
|
||||
public Closeable attachForAccount(String accountId, String namespace, String podName,
|
||||
String logGroup, String logStream, String region, String logPrefix) {
|
||||
cloudWatchWriter.ensureLogGroupAndStreamForAccount(accountId, logGroup, logStream, region);
|
||||
|
||||
InputStream logStreamBody = client.openPodLogStream(namespace, podName, "runtime");
|
||||
|
||||
@@ -55,7 +60,8 @@ public class KubernetesPodLogStreamer {
|
||||
continue;
|
||||
}
|
||||
LOG.infov("[{0}] {1}", logPrefix, trimmed);
|
||||
cloudWatchWriter.streamToCloudWatchLogs(logGroup, logStream, region, trimmed);
|
||||
cloudWatchWriter.streamToCloudWatchLogsForAccount(
|
||||
accountId, logGroup, logStream, region, trimmed);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Normal on pod deletion: the log stream just ends.
|
||||
|
||||
Reference in new issue
Block a user