Skip to content

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

fix: a service reset removes only this MiniStack's containers (#2386)

jeffreyheller04e72a56ee56
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 103cf0f4..0f4d314f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **Auth — SigV4a signatures are verified under `AUTH=true`** — requests signed with `AWS4-ECDSA-P256-SHA256`, which SDKs use for Multi-Region Access Points, were refused for every IAM user. Header and presigned S3 signatures are now checked with the P-256 key SigV4a derives from the secret, with their date or expiry, and an `X-Amz-Region-Set` that leaves out the serving region is refused (`RegionSetMismatch` on S3, the unknown-key error elsewhere). Contributed by @iot-rocket.
### Fixed
+- **Reset — `/_ministack/reset` no longer removes another MiniStack's containers** — the OpenSearch, OpenSearch Serverless, DSQL, ECS and EKS resets removed every container carrying the service's label on the Docker daemon, including those of other MiniStack instances sharing it. They now remove only this instance's (`ministack.instance`), as the EC2, Lambda microVM and Flink resets and the boot and shutdown sweeps already do. Contributed by @jeffreyheller.
- **S3 — Multi-Region Access Point requests are authorized** — under `AUTH=true`, requests through an MRAP hostname were served without an IAM check. They are now authorized on the member bucket and then on the MRAP, whose policy is evaluated like a bucket policy, and answer `AccessDenied` naming the resource that refused them. Contributed by @iot-rocket.
- **Cognito — signing keys, managed login and federated users** — every user pool signed with one shared key (`kid` `ministack-key-1`); each pool now has two keys of its own, one for access tokens and one for ID tokens, both published at its JWKS URI, and a token verifies only against its own pool. Managed login refuses PKCE `plain` and a `code_challenge` without `S256` (`error=invalid_request`), any `redirect_uri` the client didn't register, also for a client with no callback URLs, and a `grant_type` other than `authorization_code`, `refresh_token` or `client_credentials` (400 `unsupported_grant_type`). Adding an identity provider creates the group `<user pool id>_<provider name>`, and a federated user's new profile joins it and carries its `identities`, so the ID token has both claims. Reported by @cupidchan.
- **S3 — bucket policy writes through an access point** — under `AUTH=true` `PutBucketPolicy` and `DeleteBucketPolicy` sent through an access point alias or ARN changed the bucket's policy; they now get 403 `AccessDenied` with an explicit deny on the access point, while `GetBucketPolicy` through it and both writes on the bucket itself work as before. Contributed by @iot-rocket.
diff --git a/ministack/services/dsql.py b/ministack/services/dsql.py
index b0f36ada..cdeaea88 100644
--- a/ministack/services/dsql.py
+++ b/ministack/services/dsql.py
@@ -1206,9 +1206,10 @@ def reset():
docker_client = rds._get_docker()
if docker_client:
- for c in docker_client.containers.list(
- all=True, filters={"label": "ministack=dsql"}
- ):
+ for c in docker_client.containers.list(all=True, filters={"label": [
+ "ministack=dsql",
+ f"{container_reaper.INSTANCE_LABEL}={container_reaper.instance_id()}",
+ ]}):
try:
c.stop(timeout=2)
c.remove(v=True)
diff --git a/ministack/services/ecs.py b/ministack/services/ecs.py
index 25e84847..16e62e3f 100644
--- a/ministack/services/ecs.py
+++ b/ministack/services/ecs.py
@@ -3537,7 +3537,7 @@ def reset():
docker_client = _get_docker()
if docker_client:
- # Stop + remove every ministack=ecs container (running OR exited).
+ # Stop + remove this instance's ministack=ecs containers (running OR exited).
# Including exited ones matters because short-lived commands
# (echo, wget probes) leave Exited containers behind that otherwise
# only the background reaper would remove.
@@ -3547,7 +3547,10 @@ def reset():
# run's worth of tasks one at a time is tens of seconds during which
# every other request is blocked.
container_reaper.drop_containers(
- docker_client.containers.list(all=True, filters={"label": "ministack=ecs"}),
+ docker_client.containers.list(all=True, filters={"label": [
+ "ministack=ecs",
+ f"{container_reaper.INSTANCE_LABEL}={container_reaper.instance_id()}",
+ ]}),
stop_timeout=2, force=True)
except Exception:
pass
diff --git a/ministack/services/eks.py b/ministack/services/eks.py
index 7812562f..d31147e1 100644
--- a/ministack/services/eks.py
+++ b/ministack/services/eks.py
@@ -631,12 +631,15 @@ def _start_k3s_container(
def _stop_all_k3s():
- """Stop all k3s containers managed by MiniStack."""
+ """Stop the k3s containers this MiniStack manages."""
client = _get_docker()
if not client:
return
try:
- for c in client.containers.list(filters={"label": "ministack=eks"}):
+ for c in client.containers.list(filters={"label": [
+ "ministack=eks",
+ f"{container_reaper.INSTANCE_LABEL}={container_reaper.instance_id()}",
+ ]}):
try:
c.stop(timeout=5)
c.remove(v=True, force=True)
diff --git a/ministack/services/opensearch.py b/ministack/services/opensearch.py
index 9276b43d..d3c990f8 100644
--- a/ministack/services/opensearch.py
+++ b/ministack/services/opensearch.py
@@ -140,10 +140,10 @@ def reset():
_domain_packages.clear()
docker = _get_docker()
if docker is not None:
- for c in docker.containers.list(
- all=True,
- filters={"label": "com.ministack.service=opensearch"},
- ):
+ for c in docker.containers.list(all=True, filters={"label": [
+ "com.ministack.service=opensearch",
+ f"{container_reaper.INSTANCE_LABEL}={container_reaper.instance_id()}",
+ ]}):
try:
c.stop(timeout=2)
c.remove(force=True, v=True)
diff --git a/ministack/services/opensearchserverless.py b/ministack/services/opensearchserverless.py
index ac618215..6e861822 100644
--- a/ministack/services/opensearchserverless.py
+++ b/ministack/services/opensearchserverless.py
@@ -95,9 +95,10 @@ def reset():
if docker is None:
return
try:
- containers = docker.containers.list(
- all=True, filters={"label": f"com.ministack.service={_CONTAINER_LABEL}"}
- )
+ containers = docker.containers.list(all=True, filters={"label": [
+ f"com.ministack.service={_CONTAINER_LABEL}",
+ f"{container_reaper.INSTANCE_LABEL}={container_reaper.instance_id()}",
+ ]})
except Exception:
return
container_reaper.drop_containers(containers, force=True)
diff --git a/tests/test_ministack.py b/tests/test_ministack.py
index 1a064f60..2f8408a4 100644
--- a/tests/test_ministack.py
+++ b/tests/test_ministack.py
@@ -816,6 +816,34 @@ def test_boot_sweep_takes_our_predecessor_but_spares_other_instances(fake_docker
assert "another-instance" in fake_docker.live(), "boot sweep destroyed another instance's container"
[email protected]("service,labels", [
+ ("opensearch", {"com.ministack.service": "opensearch"}),
+ ("opensearchserverless", {"com.ministack.service": "opensearchserverless"}),
+ ("dsql", {}),
+ ("ecs", {}),
+ ("eks", {}),
+])
+def test_service_reset_spares_other_instances_containers(fake_docker, monkeypatch, service, labels):
+ """A reset clears this instance's containers; another MiniStack on the daemon keeps its own."""
+ import importlib
+
+ from ministack.core import container_reaper
+ from ministack.services import rds
+
+ mod = importlib.import_module(f"ministack.services.{service}")
+ for name, port in (("theirs", "4777"), ("ours", "4566")):
+ monkeypatch.setenv("GATEWAY_PORT", port)
+ fake_docker.containers.run(name=name, labels={**container_reaper.own_labels(service), **labels})
+ monkeypatch.setattr(rds if service == "dsql" else mod, "_get_docker", lambda: fake_docker)
+ if service == "dsql":
+ monkeypatch.setattr(mod, "_docker_available", lambda: True)
+
+ mod.reset()
+
+ assert fake_docker.live() == ["theirs"], f"{service} reset removed another instance's container"
+
+
@pytest.mark.serial
def test_boot_sweep_survives_one_container_whose_inspect_fails(fake_docker, monkeypatch):
"""A full listing inspects every container, so one failed inspect used to cost the whole sweep."""