fix(mwaa): reject a malformed configured AirflowVersion as ValidationException (#3453)

MwaaEnvironmentManager.pythonTagFor parses AirflowVersion with a bare
Integer.parseInt. resolveAirflowVersion only checked that the requested
version was present in the operator-configured supported-versions list,
so a misconfigured entry (e.g. a stray "latest") would pass that check
and reach pythonTagFor, surfacing as an internal NumberFormatException
out of container startup, well after Postgres had already been created
for the environment, rather than a clean 400 at CreateEnvironment.

resolveAirflowVersion now also validates the version's shape (a numeric
major.minor, with an optional patch) before checking list membership, so
a malformed value is rejected immediately as ValidationException.

Follow-up from hectorvent's review on #3445.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-11 23:20:41 -05:00
1 parent 6d43e16d0e
commit a7902b97f3
2 files changed
+46 -2

No files matched your search

@@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ApplicationScoped
@@ -43,6 +44,16 @@ public class MwaaService implements TagHandler {
private static final Logger LOG = Logger.getLogger(MwaaService.class);
/**
* Shape {@code MwaaEnvironmentManager.pythonTagFor} requires: at least a numeric
* {@code major.minor}, an optional {@code .patch}. {@code supported-versions} is
* operator-configurable, so a malformed entry (e.g. a stray {@code latest}) must be rejected
* here as a clean {@code ValidationException} rather than reaching {@code pythonTagFor} and
* surfacing as an internal {@code NumberFormatException} well after Postgres has already been
* created for the environment.
*/
private static final Pattern AIRFLOW_VERSION_PATTERN = Pattern.compile("\\d+\\.\\d+(\\.\\d+)?");
private final StorageBackend<String, Environment> storage;
private final EmulatorConfig config;
private final RegionResolver regionResolver;
@@ -339,7 +350,7 @@ public class MwaaService implements TagHandler {
private String resolveAirflowVersion(String requested) {
List<String> supported = config.services().mwaa().supportedVersions();
String version = requested != null && !requested.isBlank() ? requested : config.services().mwaa().defaultVersion();
if (!supported.contains(version)) {
if (!AIRFLOW_VERSION_PATTERN.matcher(version).matches() || !supported.contains(version)) {
throw new AwsException("ValidationException",
"Unsupported AirflowVersion '" + version + "'. Supported versions: " + supported, 400);
}