From f48bc2aa40ed3494f418d4c6915a5d9bc2ba54de Mon Sep 17 00:00:00 2001 From: Michal Schreiber <73832189+ck-michals@users.noreply.github.com> Date: Wed, 16 Sep 2026 15:39:37 +0200 Subject: [PATCH] fix(rds): accept the master usernames each engine really allows (#3730) The 16 character cap was applied to every engine, but RDS accepts 63 on PostgreSQL and 32 on MySQL, so an instance whose master username is longer could not be created at all. The bound now comes from DatabaseEngine, using the engine createDbInstance already resolves; the character rule and the error message are unchanged. Closes #3729 --- .../sdk-test-awscli/test/rds.bats | 28 +++++++++++++++ .../floci/services/rds/RdsService.java | 3 +- .../services/rds/model/DatabaseEngine.java | 10 ++++++ .../floci/services/rds/RdsServiceTest.java | 35 ++++++++++++++++++- 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/compatibility-tests/sdk-test-awscli/test/rds.bats b/compatibility-tests/sdk-test-awscli/test/rds.bats index f1a65a9dd7..49c8189f72 100644 --- a/compatibility-tests/sdk-test-awscli/test/rds.bats +++ b/compatibility-tests/sdk-test-awscli/test/rds.bats @@ -404,3 +404,31 @@ teardown() { assert_failure assert_output --partial 'InvalidParameterCombination' } + +@test "rds: a master username longer than 16 characters is accepted on postgres, as on AWS" { + run aws_cmd rds create-db-instance \ + --db-instance-identifier "$DB_ID" \ + --engine postgres \ + --db-instance-class db.t3.micro \ + --allocated-storage 10 \ + --master-username application_db_admin_user \ + --master-user-password "secret99password" + assert_success + + run aws_cmd rds describe-db-instances --db-instance-identifier "$DB_ID" \ + --query 'DBInstances[0].MasterUsername' + assert_success + assert_output --partial 'application_db_admin_user' + + # 64 characters is one past what PostgreSQL accepts on a live account + long_username="a$(printf 'b%.0s' $(seq 63))" + run aws_cmd rds create-db-instance \ + --db-instance-identifier "$DB_ID_2" \ + --engine postgres \ + --db-instance-class db.t3.micro \ + --allocated-storage 10 \ + --master-username "$long_username" \ + --master-user-password "secret99password" + assert_failure + assert_output --partial 'InvalidParameterValue' +} diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java index 17515f996c..bf8ffb56f6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java @@ -611,7 +611,8 @@ public class RdsService implements Resettable, ResourceProvider { int proxyPort = allocateProxyPort(); if (masterUsername == null || masterUsername.isBlank()) { masterUsername = "root"; - } else if (masterUsername.length() > 16 || !masterUsername.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) { + } else if (masterUsername.length() > engine.maxMasterUsernameLength() + || !masterUsername.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) { throw new AwsException("InvalidParameterValue", "MasterUsername must begin with a letter and contain only alphanumeric characters or underscores.", 400); } diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DatabaseEngine.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DatabaseEngine.java index 20244d264a..29b2343802 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DatabaseEngine.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DatabaseEngine.java @@ -12,4 +12,14 @@ public enum DatabaseEngine { case MYSQL, MARIADB -> 3306; }; } + + // The API reference documents 16 characters for every engine, but RDS accepts longer + // master usernames on PostgreSQL and MySQL. These are the limits the service enforces. + public int maxMasterUsernameLength() { + return switch (this) { + case POSTGRES -> 63; + case MYSQL -> 32; + case MARIADB -> 16; + }; + } } diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java index 05063d18d6..48da4fabd1 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java @@ -2760,11 +2760,44 @@ class RdsServiceTest { AwsException ex4 = assertThrows(AwsException.class, () -> rdsService.createDbInstance("mydb4", "postgres", "13", - "a1234567890123456", "password", "dbname", "db.t3.micro", + "a" + "b".repeat(63), "password", "dbname", "db.t3.micro", 20, false, null, null, null, null, false)); assertEquals("InvalidParameterValue", ex4.getErrorCode()); } + @Test + void createDbInstanceAcceptsTheLongestMasterUsernameEachEngineAllows() { + DbInstance postgres = rdsService.createDbInstance("pg63", "postgres", "13", + "a" + "b".repeat(62), "password", "dbname", "db.t3.micro", + 20, false, null, null, null, null, false); + assertEquals(63, postgres.getMasterUsername().length()); + + DbInstance mysql = rdsService.createDbInstance("my32", "mysql", "8.0", + "a" + "b".repeat(31), "password", "dbname", "db.t3.micro", + 20, false, null, null, null, null, false); + assertEquals(32, mysql.getMasterUsername().length()); + + DbInstance mariadb = rdsService.createDbInstance("mar16", "mariadb", "11.4", + "a" + "b".repeat(15), "password", "dbname", "db.t3.micro", + 20, false, null, null, null, null, false); + assertEquals(16, mariadb.getMasterUsername().length()); + } + + @Test + void createDbInstanceRejectsMasterUsernameLongerThanTheEngineAllows() { + AwsException mysql = assertThrows(AwsException.class, () -> + rdsService.createDbInstance("my33", "mysql", "8.0", + "a" + "b".repeat(32), "password", "dbname", "db.t3.micro", + 20, false, null, null, null, null, false)); + assertEquals("InvalidParameterValue", mysql.getErrorCode()); + + AwsException mariadb = assertThrows(AwsException.class, () -> + rdsService.createDbInstance("mar17", "mariadb", "11.4", + "a" + "b".repeat(16), "password", "dbname", "db.t3.micro", + 20, false, null, null, null, null, false)); + assertEquals("InvalidParameterValue", mariadb.getErrorCode()); + } + @Test void createDbSnapshotThrowsForNonPostgres() { rdsService.createDbInstance("mydb", "mysql", "8.0",