fix: Reflect Unix file mode when building tarball from .NET 7 onwards#1397
Merged
HofmeisterAn merged 1 commit intoMar 12, 2025
Merged
Conversation
When the image build process is creating the tarball of files needed to build the image, it currently just uses the default value of 700. This causes those files to be readable only by the owner (i.e. root) when placed in the container. The fix is to read the file mode of the files when building the tarball on Unix. The API in use only exists in .NET 7.0 and higher, so this change also extends the Windows workaround to Unix. When the `GetUnixFileMode` function isn't available, just use 755 as the file mode.
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
HofmeisterAn
approved these changes
Mar 12, 2025
HofmeisterAn
left a comment
Collaborator
There was a problem hiding this comment.
Good idea 😎 thanks.
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.
What does this PR do?
When the image build process is creating the tarball of files needed to build the image, it currently just uses the default value of 700. This causes those files to be readable only by the owner (i.e. root) when placed in the container.
The fix is to read the file mode of the files when building the tarball on Unix. The API in use only exists in .NET 7.0 and higher, so this change also extends the Windows workaround to Unix. When the
GetUnixFileModefunction isn't available, just use 755 as the file mode.Why is it important?
The behavior when an image is built using Testcontainers on Unix differs from the behavior when the image is built externally. This is especially problematic when running the container as a non-root user (e.g.
USER ubuntu) as all of the files copied from the tarball are restricted to the root user only.Related issues
Closes #1171
How to test this PR
This PR was tested locally on Fedora 41 using Podman. The test scenario used a simple docker file that copied a script (mode
755) from the local disk and tried to execute it:Dockerfile
app/app.py
Without my change, the script would fail to execute due to the
700permissions onapp.py. With my change, the script executed successfully.