fix(ecs): pass awsfirelens logConfiguration secretOptions to the log router output (#8303)

This commit is contained in:
Matheus André authored and GitHub committed 2026-11-14 11:16:20 -04:00
1 parent 2337c34ef9
commit 16cb752444
2 files changed
+133 -1

No files matched your search

@@ -268,6 +268,8 @@ public class EcsContainerManager {
throw new AwsException("ClientException",
"awsfirelens log driver requires a firelensConfiguration container", 400);
}
List<String> firelensSecretEnv = addFirelensSecretOptions(
firelensLogOptions, taskDef.getContainerDefinitions(), isFluentdRouter(firelensRouter), region);
List<ContainerDefinition> launchOrder = orderForDependencies(
launchOrder(taskDef.getContainerDefinitions(), firelensRouter), firelensRouter);
@@ -323,6 +325,9 @@ public class EcsContainerManager {
imagesByContainer.put(def,
containerBuilder.resolveImage(ecrRegistryManager.rewriteImageUri(def.getImage())));
}
if (firelensRouter != null) {
envVarsByContainer.get(firelensRouter).addAll(firelensSecretEnv);
}
// Pulled for every container before any is created, as the ECS agent does, so a tag
// moved in its registry since the last launch is what this task runs. Each container is
// created from the image id its pull resolved to, so a concurrent launch that moves the
@@ -1641,6 +1646,39 @@ public class EcsContainerManager {
return options;
}
/**
* Hands each awsfirelens container's {@code secretOptions} to the router the way the ECS agent does: the
* value, resolved from Secrets Manager or SSM, is an environment variable of the router named
* {@code <option>_<container index>}, and the output option beside the container's {@code options}
* only references it. The value never becomes config text, so it cannot add directives to the config.
*
* @return the router's environment entries, one per secret option
*/
private List<String> addFirelensSecretOptions(
Map<String, Map<String, String>> logOptions, List<ContainerDefinition> defs, boolean fluentd,
String region) {
List<String> routerEnv = new ArrayList<>();
for (int index = 0; index < defs.size(); index++) {
ContainerDefinition def = defs.get(index);
if (!isAwsFirelens(def)) {
continue;
}
List<Secret> secretOptions = def.getLogConfiguration().secretOptions();
if (secretOptions == null || secretOptions.isEmpty()) {
continue;
}
Map<String, String> options = new LinkedHashMap<>(logOptions.get(def.getName()));
for (Secret secretOption : secretOptions) {
String variable = secretOption.name() + "_" + index;
routerEnv.add(variable + "=" + resolveSecretValue(secretOption.valueFrom(), region));
options.put(secretOption.name(),
fluentd ? "\"#{ENV['" + variable + "']}\"" : "${" + variable + "}");
}
logOptions.put(def.getName(), options);
}
return routerEnv;
}
private static boolean isAwsFirelens(ContainerDefinition def) {
LogConfiguration log = def.getLogConfiguration();
return log != null && "awsfirelens".equals(log.logDriver());