Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(rds): grant the MySQL master user on the background start path (#1983)
Jeff Hellerf662333ea6ba
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9469d783..66afb4f2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,9 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]+### Fixed++- **RDS — a MySQL master user started in the background keeps its admin grant** — an instance whose engine image was not cached yet, or one respawned on restore, started on a background path that skipped the master-user grant the inline path gives, so the master user held only its own database and `SET PERSIST` failed for lack of `SYSTEM_VARIABLES_ADMIN`. Both paths now grant it. Contributed by @skialpine.### Added- **OpenSearch Serverless — collections, security and access policies, and a proxied data plane** — `CreateCollection`, `BatchGetCollection`, `ListCollections`, `UpdateCollection`, `DeleteCollection`, `Create`/`Get`/`Update`/`Delete`/`ListSecurityPolicy` (`encryption`, `network`), `Create`/`Get`/`Update`/`Delete`/`ListAccessPolicy` (`data`), `GetPoliciesStats` and `TagResource` / `UntagResource` / `ListTagsForResource`, enough for Terraform's `aws_opensearchserverless_collection`, `_security_policy` and `_access_policy` to apply, plan clean and destroy. A collection needs a matching encryption policy (exact name or `prefix*`, most specific wins) unless `encryptionConfig` is given, and answers `kmsKeyArn: auto` for an AWS-owned key; policy documents are validated, a resource pattern may sit in only one encryption policy, a data policy refuses empty or wildcard principals, and an update must name the current `policyVersion` (`base64("<lastModifiedDate>_<n>")`). Its `collectionEndpoint`, `http://<id>.<region>.aoss.<host>:<port>`, is served through the gateway and requests must be SigV4-signed for `aoss` and carry `x-amz-content-sha256` (403 otherwise); with `OPENSEARCH_DATAPLANE=1` it is backed by its own `opensearchproject/opensearch` container, persisted on a named Docker volume across a restart under `PERSIST_STATE` and removed on `DeleteCollection`, otherwise it answers 503. APIs AOSS does not support answer 404, as `_refresh`, `_cluster/*` and scroll do on AWS, and `TIMESERIES` collections refuse custom document ids and updates. Data access and network policies are stored, not enforced. Checked against the botocore model and the OpenSearch Serverless developer guide and API reference.diff --git a/ministack/services/rds.py b/ministack/services/rds.pyindex 7a1e0f57..55756a1a 100644--- a/ministack/services/rds.py+++ b/ministack/services/rds.py@@ -2535,6 +2535,10 @@ def _start_rds_container_for_instance(db_id, instance):except Exception:passreturn+ _grant_mysql_master_user_privileges(+ internal_host or "127.0.0.1", internal_port or host_port,+ master_user, master_pass, db_id,+ )_instance_available_unless_stopped(instance)logger.info("RDS: respawned container %s for instance %s",container_name, db_id)diff --git a/tests/test_rds.py b/tests/test_rds.pyindex ce4768fe..937a39d7 100644--- a/tests/test_rds.py+++ b/tests/test_rds.py@@ -5264,6 +5264,48 @@ def test_rds_restore_state_respawns_docker_container(monkeypatch):m._instances.clear()+def test_rds_deferred_mysql_start_grants_master_privileges(monkeypatch):+ """A MySQL instance started in the background (cold image cache, or a+ restore) gets the same master-user admin grant as one started inline."""+ from ministack.services import rds as m++ class FakeContainer:+ id = "cid-mysql"+ attrs = {"NetworkSettings": {"Networks": {}}}++ def reload(self): pass++ class FakeContainers:+ def get(self, name):+ raise Exception("not found")++ class FakeDocker:+ containers = FakeContainers()++ grants = []+ monkeypatch.setattr(m, "_get_docker", lambda: FakeDocker())+ monkeypatch.setattr(m, "_get_ministack_network", lambda c: None)+ monkeypatch.setattr(m, "_is_host_port_free", lambda port: True)+ monkeypatch.setattr(m, "_run_rds_container", lambda *_args, **_kwargs: FakeContainer())+ monkeypatch.setattr(m, "_ensure_mysql_compatibility", lambda *_args, **_kwargs: None)+ monkeypatch.setattr(m, "_grant_mysql_master_user_privileges", lambda *args: grants.append(args))++ db_id = "deferred-mysql"+ instance = {+ "DBInstanceIdentifier": db_id, "Engine": "mysql", "EngineVersion": "8.4",+ "MasterUsername": "admin", "_MasterUserPassword": "password123",+ "DBName": "mydb", "DBInstanceStatus": "creating", "_HostPort": 15600,+ }+ m._instances.clear()+ m._instances[db_id] = instance+ try:+ m._start_rds_container_for_instance(db_id, instance)+ assert grants == [("127.0.0.1", 15600, "admin", "password123", db_id)]+ assert instance["DBInstanceStatus"] == "available"+ finally:+ m._instances.clear()++@pytest.mark.parametrize("scenario",[