Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(opensearch): name data-plane containers per account and region (#1984)

Jeff Hellerf33bef18e3ad
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66afb4f2..2ce7bc61 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
+- **OpenSearch — data-plane containers are named per account** — a domain's container was named `ministack-opensearch-<region>-<domain>`, so a second account creating a domain of the same name (including an account on another MiniStack sharing the Docker daemon) failed with a Docker name conflict, and the failed create's cleanup removed containers by that name. The names now carry an account and region hash, as RDS's do. Contributed by @skialpine.
- **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
diff --git a/ministack/services/opensearch.py b/ministack/services/opensearch.py
index babdf2ac..9276b43d 100644
--- a/ministack/services/opensearch.py
+++ b/ministack/services/opensearch.py
@@ -22,6 +22,7 @@ which stay account-scoped because their ARN keys embed region.
import contextvars
import copy
+import hashlib
import json
import logging
import os
@@ -334,12 +335,18 @@ def _get_docker():
return _docker_client
+def _scope() -> str:
+ # A short account+region hash, as RDS names its containers: Dashboards reaches
+ # the data container by name, a single DNS label of at most 63 characters.
+ return hashlib.sha1(f"{get_account_id()}:{get_region()}".encode()).hexdigest()[:12]
+
+
def _container_name(domain_name: str) -> str:
- return f"ministack-opensearch-{get_region()}-{domain_name}"
+ return f"ministack-opensearch-{_scope()}-{domain_name}"
def _dashboards_container_name(domain_name: str) -> str:
- return f"ministack-opensearch-dashboards-{get_region()}-{domain_name}"
+ return f"ministack-opensearch-dashboards-{_scope()}-{domain_name}"
def _image_is_local(docker_client, image: str) -> bool:
diff --git a/tests/test_opensearch.py b/tests/test_opensearch.py
index 79667500..9032f659 100644
--- a/tests/test_opensearch.py
+++ b/tests/test_opensearch.py
@@ -654,24 +654,29 @@ def test_opensearch_reset_clears_all_regions():
set_request_region(original_region)
-def test_opensearch_dataplane_names_include_region():
- from ministack.core.responses import get_region, set_request_region
+def test_opensearch_dataplane_names_include_account_and_region():
+ """Two accounts, or two regions, may each own a domain of the same name;
+ their containers must not collide, and the data container's name stays one
+ DNS label (Dashboards reaches it by name) for the longest domain name."""
+ from ministack.core.responses import (
+ get_account_id, get_region, set_request_account_id, set_request_region,
+ )
from ministack.services import opensearch
- original_region = get_region()
+ original_account, original_region = get_account_id(), get_region()
+ longest = "d" * 28
+ names = set()
try:
- set_request_region(REGION)
- assert opensearch._container_name("same") == f"ministack-opensearch-{REGION}-same"
- assert opensearch._dashboards_container_name("same") == (
- f"ministack-opensearch-dashboards-{REGION}-same"
- )
-
- set_request_region("us-west-2")
- assert opensearch._container_name("same") == "ministack-opensearch-us-west-2-same"
- assert opensearch._dashboards_container_name("same") == (
- "ministack-opensearch-dashboards-us-west-2-same"
- )
+ for account, region in (("111111111111", REGION), ("222222222222", REGION),
+ ("111111111111", "ap-southeast-3")):
+ set_request_account_id(account)
+ set_request_region(region)
+ names.add((opensearch._container_name("same"),
+ opensearch._dashboards_container_name("same")))
+ assert len(opensearch._container_name(longest)) <= 63
+ assert len(names) == 3
finally:
+ set_request_account_id(original_account)
set_request_region(original_region)