test: bind-mount container config files instead of streaming via archive#91
Open
BorisTyshkevich wants to merge 1 commit intomainfrom
Open
test: bind-mount container config files instead of streaming via archive#91BorisTyshkevich wants to merge 1 commit intomainfrom
BorisTyshkevich wants to merge 1 commit intomainfrom
Conversation
testcontainers' ContainerFile abstraction injects host files into containers
by tar-streaming them through Docker's PUT /containers/{id}/archive endpoint
(the same endpoint backing `docker cp`). Some hardened sandbox environments
(notably our agent isolator) intentionally block that endpoint to keep
binaries from being injected into running containers, which makes any test
using `Files: []ContainerFile{...}` fail at container create with:
isolator: endpoint not allowed: PUT /v1.51/containers/.../archive
Replace the two call sites with read-only bind mounts via
HostConfigModifier.Binds. Bind mounts are wired up at container create time
through POST /containers/create, which is allowed, and the file content
reaches the container via the kernel's mount machinery rather than a Docker
API tar stream.
In setupAntalyaClickHouseWithOIDC the host files were already on disk; just
moved them from Files: to hc.Binds. In TestTestConnection/connection_with_tls
the inputs were in-memory string Readers, so they're now materialized to a
t.TempDir() once via a small writeTmp helper before the bind mount.
Both call sites use :ro to preserve the read-only intent of the original
config-injection. Behavior is identical in environments where the archive
endpoint is allowed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
testcontainers' `Files: []ContainerFile{...}` abstraction injects host files into containers by tar-streaming them through Docker's `PUT /containers/{id}/archive` endpoint (the same endpoint backing `docker cp`). Some hardened sandbox environments intentionally block that endpoint to prevent arbitrary binary injection into running containers.
This PR replaces the two call sites with read-only bind mounts via `HostConfigModifier.Binds`. Bind mounts are wired up at container-create time through `POST /containers/create` (already allowed), and the file content reaches the container via the kernel's mount machinery rather than a Docker API tar stream.
Change
Two test files, ~30 LoC net:
Both call sites use `:ro` to preserve the read-only intent of the original config injection.
Why this is portable
Behavior is identical in environments where `PUT /containers/{id}/archive` is allowed. Bind mounts work in plain Docker, Docker Desktop, Colima, Lima, Podman, etc. — the change neither tightens nor loosens the security envelope outside the sandbox case it fixes.
Test plan
Scope
🤖 Generated with Claude Code