From fb3c93018e27f3dd50850c727aaf4a925f858f02 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:19:45 -0400 Subject: [PATCH] fix(mwaa): accept every Airflow 2.x version Amazon MWAA offers (#8394) The default supported-versions list held 2.10.5, 2.9.3 and 2.8.4, none of which real MWAA offers, so a CreateEnvironment with an AirflowVersion AWS accepts (2.9.2, 2.10.3, 2.11.0 and the rest) failed validation. Add 2.7.2, 2.8.1, 2.9.2, 2.10.1, 2.10.3, 2.11.0 and 2.11.2 to the default list and keep the three versions Floci already offered. With 2.7.2 offered, the CLI proxy refuses "providers notifications" below Airflow 2.8, as AWS's CLI reference lists it from v2.8 only. --- docs/services/mwaa.md | 6 ++-- .../io/floci/aws/config/EmulatorConfig.java | 5 +-- .../services/mwaa/MwaaEnvironmentManager.java | 26 ++++++++++---- .../floci/aws/services/mwaa/MwaaService.java | 2 +- src/main/resources/application.yml | 2 +- .../mwaa/MwaaEnvironmentManagerTest.java | 34 +++++++++++++------ .../services/mwaa/MwaaIntegrationTest.java | 3 +- 7 files changed, 53 insertions(+), 25 deletions(-) diff --git a/docs/services/mwaa.md b/docs/services/mwaa.md index eb498fbb56..34171fa5e8 100644 --- a/docs/services/mwaa.md +++ b/docs/services/mwaa.md @@ -31,7 +31,7 @@ Environment metadata is stored in-process. No Docker containers are started. The Floci starts two containers per environment: - `floci-aws-mwaa-..-db`: a private `postgres` metadata database, never given a published host port; it's only ever reached by the sibling Airflow container over the Docker network. -- `floci-aws-mwaa-..-airflow`: a real `apache/airflow` container running **LocalExecutor** (webserver + scheduler in one process tree). `AirflowVersion` genuinely selects the image tag (`apache/airflow:-python3.11` for versions through 2.10.x, `apache/airflow:-python3.12` from 2.11.0 onward, matching the Airflow/Python pairing real Amazon MWAA runs for each version), validated against `supported-versions`. Unlike some Floci services where a requested version is echoed back but not actually applied, MWAA always runs the exact Airflow version requested. +- `floci-aws-mwaa-..-airflow`: a real `apache/airflow` container running **LocalExecutor** (webserver + scheduler in one process tree). `AirflowVersion` genuinely selects the image tag (`apache/airflow:-python3.11` for versions through 2.10.x, `apache/airflow:-python3.12` from 2.11.0 onward, matching the Airflow/Python pairing real Amazon MWAA runs for each version), validated against `supported-versions`. The default list holds every Airflow 2.x version Amazon MWAA offers (2.7.2, 2.8.1, 2.9.2, 2.10.1, 2.10.3, 2.11.0 and 2.11.2) plus 2.10.5, 2.9.3 and 2.8.4, which Floci offered before and real MWAA does not. Airflow 3.x is not offered: the container runs the Airflow 2 `webserver`. Unlike some Floci services where a requested version is echoed back but not actually applied, MWAA always runs the exact Airflow version requested. `AirflowConfigurationOptions` is applied too, not just echoed back: each `section.key` entry becomes an `AIRFLOW__SECTION__KEY` environment variable on the Airflow container, the same mechanism real Amazon MWAA uses, so a DAG's `conf.get("section", "key")` sees the configured value. A malformed key (missing the `section.key` dot) or one that would collide with a variable Floci itself manages (the executor, database connection, or security keys) is skipped and logged, rather than silently breaking the environment's required wiring. `CreateEnvironment` also enforces the same key/value shape botocore does for this field (a 1-64 character key matching `[a-z]+([a-z0-9._]*[a-z0-9_]+)?`, a 1-65536 character printable-ASCII value), since Floci is reachable via raw HTTP or CLI `--cli-input-json`, which bypasses the SDKs' own client-side validation. This only applies at creation time: `UpdateEnvironment` still rejects `AirflowConfigurationOptions` (see [Not Implemented](#not-implemented) below), so changing an option on an existing environment requires deleting and recreating it. @@ -42,7 +42,7 @@ Once Airflow's unauthenticated `/health` endpoint reports both `metadatabase` an ### Web/CLI proxy -Floci runs its own HTTP proxy per environment (published on a host port from the configured range) that fronts the real Airflow webserver: every request is forwarded through to Airflow as-is, **except** `POST /aws_mwaa/cli`, which the proxy intercepts itself. It validates the `Authorization: Bearer ` from `CreateCliToken`, then runs supported Amazon MWAA Airflow CLI commands inside the container via `docker exec` and returns the AWS-documented `{stdout, stderr}` (base64) shape. Unsupported commands return an error in `stderr` without reaching the container. The supported commands match the [Amazon MWAA Airflow v2 CLI list](https://docs.aws.amazon.com/mwaa/latest/userguide/airflow-cli-command-reference.html); every Airflow version Floci currently offers is at least 2.8.4. `Environment.WebserverUrl` and the URL returned by `CreateWebLoginToken` both point at this proxy, so Airflow-UI browsing and the CLI-token flow go through the same place. +Floci runs its own HTTP proxy per environment (published on a host port from the configured range) that fronts the real Airflow webserver: every request is forwarded through to Airflow as-is, **except** `POST /aws_mwaa/cli`, which the proxy intercepts itself. It validates the `Authorization: Bearer ` from `CreateCliToken`, then runs supported Amazon MWAA Airflow CLI commands inside the container via `docker exec` and returns the AWS-documented `{stdout, stderr}` (base64) shape. Unsupported commands return an error in `stderr` without reaching the container. The supported commands match the [Amazon MWAA Airflow v2 CLI list](https://docs.aws.amazon.com/mwaa/latest/userguide/airflow-cli-command-reference.html); as in that list, `providers notifications` needs Airflow 2.8 or later, so a 2.7.2 environment refuses it. `Environment.WebserverUrl` and the URL returned by `CreateWebLoginToken` both point at this proxy, so Airflow-UI browsing and the CLI-token flow go through the same place. ### Startup scripts (`StartupScriptS3Path`) @@ -78,7 +78,7 @@ services: | `FLOCI_SERVICES_MWAA_ENABLED` | `true` | Enable the MWAA service | | `FLOCI_SERVICES_MWAA_MOCK` | `false` | Metadata-only mode (no Docker) | | `FLOCI_SERVICES_MWAA_DEFAULT_POSTGRES_IMAGE` | `postgres:16-alpine` | Metadata-database Docker image | -| `FLOCI_SERVICES_MWAA_SUPPORTED_VERSIONS` | `2.10.5,2.9.3,2.8.4` | Comma-separated `AirflowVersion` allow-list; `CreateEnvironment` rejects any other value | +| `FLOCI_SERVICES_MWAA_SUPPORTED_VERSIONS` | `2.11.2,2.11.0,2.10.5,2.10.3,2.10.1,2.9.3,2.9.2,2.8.4,2.8.1,2.7.2` | Comma-separated `AirflowVersion` allow-list; `CreateEnvironment` rejects any other value | | `FLOCI_SERVICES_MWAA_DEFAULT_VERSION` | `2.10.5` | `AirflowVersion` used when the request omits one | | `FLOCI_SERVICES_MWAA_PROXY_BASE_PORT` | `8700` | First port in the web/CLI proxy range | | `FLOCI_SERVICES_MWAA_PROXY_MAX_PORT` | `8799` | Last port in the web/CLI proxy range | diff --git a/src/main/java/io/floci/aws/config/EmulatorConfig.java b/src/main/java/io/floci/aws/config/EmulatorConfig.java index d611f77165..42e5941ca6 100644 --- a/src/main/java/io/floci/aws/config/EmulatorConfig.java +++ b/src/main/java/io/floci/aws/config/EmulatorConfig.java @@ -4010,8 +4010,9 @@ public interface EmulatorConfig { /** Airflow versions environments may request. Combined with the image tag * {@code apache/airflow:-}, where the Python tag matches the * version real Amazon MWAA runs for that Airflow version: see - * {@code MwaaEnvironmentManager.pythonTagFor}. */ - @WithDefault("2.10.5,2.9.3,2.8.4") + * {@code MwaaEnvironmentManager.pythonTagFor}. The default is every Airflow 2.x version + * Amazon MWAA offers, plus 2.10.5, 2.9.3 and 2.8.4, which Floci offered first. */ + @WithDefault("2.11.2,2.11.0,2.10.5,2.10.3,2.10.1,2.9.3,2.9.2,2.8.4,2.8.1,2.7.2") List supportedVersions(); /** Airflow version used when {@code CreateEnvironment} omits {@code AirflowVersion}. */ diff --git a/src/main/java/io/floci/aws/services/mwaa/MwaaEnvironmentManager.java b/src/main/java/io/floci/aws/services/mwaa/MwaaEnvironmentManager.java index a02112be90..da25d5ddf1 100644 --- a/src/main/java/io/floci/aws/services/mwaa/MwaaEnvironmentManager.java +++ b/src/main/java/io/floci/aws/services/mwaa/MwaaEnvironmentManager.java @@ -386,9 +386,10 @@ public class MwaaEnvironmentManager { * arguments with POSIX quoting rules and executed without a shell, so shell syntax such as * {@code ;}, {@code |} or {@code $(...)} reaches Airflow as plain arguments. */ - public ContainerExec.Result runAirflowCli(String airflowContainerId, String cliCommand) throws Exception { + public ContainerExec.Result runAirflowCli(String airflowContainerId, String airflowVersion, String cliCommand) + throws Exception { List arguments = splitCliArguments(cliCommand); - if (!isSupportedCliCommand(arguments)) { + if (!isSupportedCliCommand(arguments, airflowVersion)) { return new ContainerExec.Result(1, "", "Command is not supported by Amazon MWAA\n", false); } List argv = new ArrayList<>(); @@ -397,7 +398,7 @@ public class MwaaEnvironmentManager { return execInContainer(airflowContainerId, argv.toArray(new String[0])); } - static boolean isSupportedCliCommand(List arguments) { + static boolean isSupportedCliCommand(List arguments, String airflowVersion) { if (arguments.isEmpty()) { return false; } @@ -405,7 +406,14 @@ public class MwaaEnvironmentManager { return true; } Set subcommands = MWAA_CLI_SUBCOMMANDS.get(arguments.getFirst()); - return arguments.size() >= 2 && subcommands != null && subcommands.contains(arguments.get(1)); + if (arguments.size() < 2 || subcommands == null || !subcommands.contains(arguments.get(1))) { + return false; + } + // Amazon MWAA's CLI reference lists "providers notifications" from v2.8 on. It is the one + // command above whose minimum is newer than v2.7.2, the oldest version MWAA still offers. + boolean providersNotifications = "providers".equals(arguments.getFirst()) + && "notifications".equals(arguments.get(1)); + return !providersNotifications || isAtLeast(airflowVersion, 2, 8); } /** @@ -523,10 +531,14 @@ public class MwaaEnvironmentManager { * every 3.x release) runs Python 3.12. */ static String pythonTagFor(String airflowVersion) { + return isAtLeast(airflowVersion, 2, 11) ? "python3.12" : "python3.11"; + } + + static boolean isAtLeast(String airflowVersion, int major, int minor) { String[] parts = airflowVersion.split("\\.", 3); - int major = Integer.parseInt(parts[0]); - int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; - return (major > 2 || (major == 2 && minor >= 11)) ? "python3.12" : "python3.11"; + int actualMajor = Integer.parseInt(parts[0]); + int actualMinor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; + return actualMajor > major || (actualMajor == major && actualMinor >= minor); } /** diff --git a/src/main/java/io/floci/aws/services/mwaa/MwaaService.java b/src/main/java/io/floci/aws/services/mwaa/MwaaService.java index b8eec4fc6c..4e07bd179e 100644 --- a/src/main/java/io/floci/aws/services/mwaa/MwaaService.java +++ b/src/main/java/io/floci/aws/services/mwaa/MwaaService.java @@ -174,7 +174,7 @@ public class MwaaService implements TagHandler { proxyManager.startProxy(environmentIdentity(environment), proxyPort, environment.getAirflowInternalHost(), environment.getAirflowInternalPort(), this::isValidCliToken, - cliCommand -> environmentManager.runAirflowCli(airflowContainerId, cliCommand)); + cliCommand -> environmentManager.runAirflowCli(airflowContainerId, version, cliCommand)); provisioned = true; } catch (Exception e) { LOG.errorv(e, "Failed to start MWAA environment {0}", name); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 24f31da5d9..cde83b0c01 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -891,7 +891,7 @@ floci: enabled: true mock: false default-postgres-image: "postgres:16-alpine" - supported-versions: "2.10.5,2.9.3,2.8.4" + supported-versions: "2.11.2,2.11.0,2.10.5,2.10.3,2.10.1,2.9.3,2.9.2,2.8.4,2.8.1,2.7.2" default-version: "2.10.5" proxy-base-port: 8700 proxy-max-port: 8799 diff --git a/src/test/java/io/floci/aws/services/mwaa/MwaaEnvironmentManagerTest.java b/src/test/java/io/floci/aws/services/mwaa/MwaaEnvironmentManagerTest.java index 4ee80f89b7..7c24169c61 100644 --- a/src/test/java/io/floci/aws/services/mwaa/MwaaEnvironmentManagerTest.java +++ b/src/test/java/io/floci/aws/services/mwaa/MwaaEnvironmentManagerTest.java @@ -553,7 +553,7 @@ class MwaaEnvironmentManagerTest { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, "airflow-container-id", 2, "dag1\n", "warning\n"); - ContainerExec.Result result = manager.runAirflowCli("airflow-container-id", "dags list"); + ContainerExec.Result result = manager.runAirflowCli("airflow-container-id", "2.10.5", "dags list"); assertEquals(List.of(List.of("airflow", "dags", "list")), commands); assertEquals(2, result.exitCode()); @@ -577,7 +577,7 @@ class MwaaEnvironmentManagerTest { void shellSyntaxInACliCommandReachesAirflowAsPlainArguments() throws Exception { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); - manager.runAirflowCli(AIRFLOW_ID, "dags list ; touch /tmp/pwned $(id) `id` | cat > /tmp/out"); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "dags list ; touch /tmp/pwned $(id) `id` | cat > /tmp/out"); assertEquals(List.of(List.of("airflow", "dags", "list", ";", "touch", "/tmp/pwned", "$(id)", "`id`", "|", "cat", ">", "/tmp/out")), commands); @@ -589,7 +589,7 @@ class MwaaEnvironmentManagerTest { for (String command : List.of("users list", "users create", "db shell", "config get-value", "webserver", "scheduler", "celery worker", "dags unknown", "dags", "")) { - ContainerExec.Result result = manager.runAirflowCli(AIRFLOW_ID, command); + ContainerExec.Result result = manager.runAirflowCli(AIRFLOW_ID, "2.10.5", command); assertEquals(1, result.exitCode(), command); assertTrue(result.stderr().contains("not supported"), command); } @@ -610,17 +610,31 @@ class MwaaEnvironmentManagerTest { "roles list", "tasks clear", "tasks failed-deps", "tasks list", "tasks render", "tasks run", "tasks state", "tasks states-for-dag-run", "tasks test", "variables delete", "variables get", "variables list", "variables set")) { - assertTrue(MwaaEnvironmentManager.isSupportedCliCommand(List.of(command.split(" "))), command); + assertTrue(MwaaEnvironmentManager.isSupportedCliCommand(List.of(command.split(" ")), "2.8.1"), command); } } + @Test + void providersNotificationsNeedsAirflow28() throws Exception { + List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); + + ContainerExec.Result refused = manager.runAirflowCli(AIRFLOW_ID, "2.7.2", "providers notifications"); + manager.runAirflowCli(AIRFLOW_ID, "2.7.2", "providers triggerer"); + manager.runAirflowCli(AIRFLOW_ID, "2.8.1", "providers notifications"); + + assertEquals(1, refused.exitCode()); + assertTrue(refused.stderr().contains("not supported")); + assertEquals(List.of(List.of("airflow", "providers", "triggerer"), + List.of("airflow", "providers", "notifications")), commands); + } + @Test void quotedCliArgumentsReachAirflowWhole() throws Exception { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); - manager.runAirflowCli(AIRFLOW_ID, "dags trigger -c '{\"key\": \"a b\"}' my_dag"); - manager.runAirflowCli(AIRFLOW_ID, "variables set greeting \"say \\\"hi\\\" to $USER\" ''"); - manager.runAirflowCli(AIRFLOW_ID, "variables get two\\ words"); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "dags trigger -c '{\"key\": \"a b\"}' my_dag"); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "variables set greeting \"say \\\"hi\\\" to $USER\" ''"); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "variables get two\\ words"); assertEquals(List.of( List.of("airflow", "dags", "trigger", "-c", "{\"key\": \"a b\"}", "my_dag"), @@ -632,7 +646,7 @@ class MwaaEnvironmentManagerTest { void backslashNewlineJoinsTheTextOnEitherSide() throws Exception { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); - manager.runAirflowCli(AIRFLOW_ID, "variables set greeting hel\\\nlo \"wor\\\nld\""); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "variables set greeting hel\\\nlo \"wor\\\nld\""); assertEquals(List.of(List.of("airflow", "variables", "set", "greeting", "hello", "world")), commands); } @@ -641,7 +655,7 @@ class MwaaEnvironmentManagerTest { void onlySpacesTabsAndNewlinesSeparateArguments() throws Exception { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); - manager.runAirflowCli(AIRFLOW_ID, "variables\tset\ngreeting hello\u2003world"); + manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "variables\tset\ngreeting hello\u2003world"); assertEquals(List.of(List.of("airflow", "variables", "set", "greeting", "hello\u2003world")), commands); } @@ -651,7 +665,7 @@ class MwaaEnvironmentManagerTest { List> commands = ContainerExecStubs.completeEveryExec(dockerClient, AIRFLOW_ID, 0, "", ""); assertThrows(IllegalArgumentException.class, - () -> manager.runAirflowCli(AIRFLOW_ID, "dags trigger -c '{\"key\": 1}")); + () -> manager.runAirflowCli(AIRFLOW_ID, "2.10.5", "dags trigger -c '{\"key\": 1}")); assertEquals(List.of(), commands); } } diff --git a/src/test/java/io/floci/aws/services/mwaa/MwaaIntegrationTest.java b/src/test/java/io/floci/aws/services/mwaa/MwaaIntegrationTest.java index 69bffd615c..1044ec36e9 100644 --- a/src/test/java/io/floci/aws/services/mwaa/MwaaIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/mwaa/MwaaIntegrationTest.java @@ -161,7 +161,8 @@ class MwaaIntegrationTest { @Test @Order(10) void everySupportedAirflowVersionRoundTrips() { - String[] versions = {"2.10.5", "2.9.3", "2.8.4"}; + String[] versions = {"2.11.2", "2.11.0", "2.10.5", "2.10.3", "2.10.1", "2.9.3", "2.9.2", "2.8.4", "2.8.1", + "2.7.2"}; for (String version : versions) { String name = "mwaa-it-v" + version.replace(".", ""); given().contentType(JSON)