fix(mwaa): apply AirflowConfigurationOptions to the Airflow container (#3457)

CreateEnvironment stored and GetEnvironment echoed back
AirflowConfigurationOptions, but nothing translated it into the
container's actual configuration, so a DAG reading a custom
conf.get("section", "key") value at import time or task-run time got
nothing back, even though GetEnvironment reported the option as
configured.

Added MwaaEnvironmentManager.airflowConfigurationOptionsEnv, which
converts each AWS "section.key" entry into the AIRFLOW__SECTION__KEY
environment variable real Amazon MWAA sets for the same option, and
wired it into startAirflowContainer's env list. A malformed key (no
"section.key" dot on both sides) or one that would collide with a
variable Floci itself manages (PROTECTED_ENV_VARS: the executor,
database connection, security keys) is skipped and logged rather than
silently breaking the environment's required wiring.

Since this map now genuinely does something instead of being inert,
also added the validation CreateEnvironment's botocore model declares
for it (a 1-64 character key matching [a-z]+([a-z0-9._]*[a-z0-9_]+)?,
a 1-65536 character printable-ASCII value) as a server-side
ValidationException: the AWS SDKs enforce this client-side, but Floci
is also reachable via raw HTTP/CLI --cli-input-json, which bypasses
that, and an oversized or malformed entry should be rejected before
Docker container creation rather than passed through.

Fixes #3436
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-12 11:11:23 -05:00
1 parent 828b53c5af
commit d429d107ff
5 files changed
+191

No files matched your search

@@ -149,6 +149,62 @@ class MwaaEnvironmentManagerTest {
assertEquals("python3.12", MwaaEnvironmentManager.pythonTagFor("3.0.6"));
}
@Test
void airflowConfigurationOptionsEnvTranslatesSectionDotKeyToAirflowDoubleUnderscoreFormat() {
assertEquals(List.of("AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION=false"),
MwaaEnvironmentManager.airflowConfigurationOptionsEnv(
Map.of("core.dags_are_paused_at_creation", "false")));
}
@Test
void airflowConfigurationOptionsEnvSkipsAKeyMissingTheSectionDotKeySeparator() {
assertEquals(List.of(), MwaaEnvironmentManager.airflowConfigurationOptionsEnv(
Map.of("not_dotted", "value")));
}
@Test
void airflowConfigurationOptionsEnvSkipsAnEmptySectionOrKey() {
assertEquals(List.of(), MwaaEnvironmentManager.airflowConfigurationOptionsEnv(
Map.of(".key", "value", "section.", "value")));
}
@Test
void airflowConfigurationOptionsEnvSkipsAnEntryThatWouldOverrideFlociOwnedWiring() {
// core.executor -> AIRFLOW__CORE__EXECUTOR, one of Floci's own mandatory (LocalExecutor)
// vars. A configuration option request doesn't get to override that.
assertEquals(List.of(), MwaaEnvironmentManager.airflowConfigurationOptionsEnv(
Map.of("core.executor", "CeleryExecutor")));
}
@Test
void airflowConfigurationOptionsEnvHandlesANullOrEmptyMap() {
assertEquals(List.of(), MwaaEnvironmentManager.airflowConfigurationOptionsEnv(null));
assertEquals(List.of(), MwaaEnvironmentManager.airflowConfigurationOptionsEnv(Map.of()));
}
@Test
void startAirflowContainerAppliesConfiguredAirflowConfigurationOptions() {
when(containerDetector.isRunningInContainer()).thenReturn(false);
when(lifecycleManager.create(any())).thenReturn("airflow-container-id");
when(lifecycleManager.startCreated(eq("airflow-container-id"), any())).thenReturn(
new ContainerInfo("airflow-container-id", Map.of(8080, new EndpointInfo("172.18.0.5", 8080))));
Environment environment = new Environment();
environment.setName("my-env");
environment.setAirflowConfigurationOptions(Map.of(
"core.dags_are_paused_at_creation", "false",
"core.executor", "CeleryExecutor"));
manager.startAirflowContainer(environment, "2.10.5", "172.18.0.9", "db-secret-pw", null);
ArgumentCaptor<ContainerSpec> captor = ArgumentCaptor.forClass(ContainerSpec.class);
verify(lifecycleManager).create(captor.capture());
assertTrue(captor.getValue().env().contains("AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION=false"));
// The colliding entry must not have replaced Floci's own required executor setting.
assertTrue(captor.getValue().env().contains("AIRFLOW__CORE__EXECUTOR=LocalExecutor"));
assertFalse(captor.getValue().env().contains("AIRFLOW__CORE__EXECUTOR=CeleryExecutor"));
}
@Test
void airflowEnvVarsWireTheResolvedPostgresDsn() {
ContainerSpec spec = startAirflowAndCaptureSpec(false);
@@ -336,6 +336,60 @@ class MwaaServiceTest {
assertEquals("2.9.3", environment.getAirflowVersion());
}
@Test
void createEnvironmentWithValidAirflowConfigurationOptionsRoundTrips() {
CreateEnvironmentRequest request = createRequest("arn:aws:s3:::my-bucket", "dags");
request.setAirflowConfigurationOptions(Map.of("core.dags_are_paused_at_creation", "false"));
Environment environment = mwaaService.createEnvironment("config-options-env", request);
assertEquals(Map.of("core.dags_are_paused_at_creation", "false"),
environment.getAirflowConfigurationOptions());
}
@Test
void createEnvironmentRejectsAnOverlongAirflowConfigurationOptionKey() {
CreateEnvironmentRequest request = createRequest("arn:aws:s3:::my-bucket", "dags");
request.setAirflowConfigurationOptions(Map.of("core." + "x".repeat(64), "value"));
AwsException ex = assertThrows(AwsException.class,
() -> mwaaService.createEnvironment("bad-key-length-env", request));
assertEquals(400, ex.getHttpStatus());
assertEquals("ValidationException", ex.getErrorCode());
}
@Test
void createEnvironmentRejectsAnAirflowConfigurationOptionKeyWithInvalidCharacters() {
CreateEnvironmentRequest request = createRequest("arn:aws:s3:::my-bucket", "dags");
request.setAirflowConfigurationOptions(Map.of("Core.DagsArePaused", "false"));
AwsException ex = assertThrows(AwsException.class,
() -> mwaaService.createEnvironment("bad-key-chars-env", request));
assertEquals(400, ex.getHttpStatus());
assertEquals("ValidationException", ex.getErrorCode());
}
@Test
void createEnvironmentRejectsAnOverlongAirflowConfigurationOptionValue() {
CreateEnvironmentRequest request = createRequest("arn:aws:s3:::my-bucket", "dags");
request.setAirflowConfigurationOptions(Map.of("core.some_key", "x".repeat(65537)));
AwsException ex = assertThrows(AwsException.class,
() -> mwaaService.createEnvironment("bad-value-length-env", request));
assertEquals(400, ex.getHttpStatus());
assertEquals("ValidationException", ex.getErrorCode());
}
@Test
void createEnvironmentRejectsANonPrintableAirflowConfigurationOptionValue() {
CreateEnvironmentRequest request = createRequest("arn:aws:s3:::my-bucket", "dags");
request.setAirflowConfigurationOptions(Map.of("core.some_key", "line one\nline two"));
AwsException ex = assertThrows(AwsException.class,
() -> mwaaService.createEnvironment("bad-value-chars-env", request));
assertEquals(400, ex.getHttpStatus());
assertEquals("ValidationException", ex.getErrorCode());
}
@Test
void getEnvironment() {
mwaaService.createEnvironment("my-env", createRequest("arn:aws:s3:::my-bucket", "dags"));