Skip to content

Fix Redis and Valkey initial data import when the container runs as a non-root user - #1626

Merged
cristianrgreco merged 3 commits into
testcontainers:mainfrom
Mario-Mohar:fix/redis-valkey-file-modes
Nov 19, 2026
Merged

cristianrgreco merged 3 commits into
testcontainers:mainfrom
Mario-Mohar:fix/redis-valkey-file-modes

Conversation

@Mario-Mohar

@Mario-Mohar Mario-Mohar commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Redis and Valkey modules copied the initial data file and import.sh with modes 666 and 777 written as decimal numbers, which Docker applies as octal 1232 and 1411. The data file ended up write only for its owner and the script read only for its owner.

This changes them to 0o644 and 0o755 and adds a short JSDoc note on FileToCopy.mode and ContentToCopy.mode saying the value is an octal permission.

#1525 will follow in a separate PR. While testing it I found that a password with a space also breaks the Redis server start and executeCliCmd, so I've asked on that issue how much of it should go into one change.

Verification

New test in both modules: start the container as the image's non-root user (withUser("redis"), withUser("valkey")) with withInitialData, then read user:002 back. It runs against every image in IMAGES.

  • Before the fix: 6 of 6 new tests fail with bash: /tmp/import.sh: Permission denied
  • After the fix: npx vitest run packages/modules/redis/src packages/modules/valkey/src, 57 passed
  • npm run format, npm run lint, npm run knip and npm run check-compiles pass

Run with Podman 6.1 through the Docker socket.

Not breaking

Only the permissions of two files the modules copy for their own import change. Root still has full access, so withInitialData behaves as before. The JSDoc change is documentation only.

Closes #1526

@Mario-Mohar
Mario-Mohar marked this pull request as ready for review October 30, 2026 11:36
@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Nov 14, 2026
@cristianrgreco cristianrgreco changed the title Use octal file modes in the Redis and Valkey modules Fix Redis and Valkey initial data import when the container runs as a non-root user Nov 15, 2026

@cristianrgreco cristianrgreco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mario-Mohar, the fix itself looks right and it covers both modules. I've retitled the PR to describe the user-visible change.

The new tests check permission bits in an exec, but what users run into is withInitialData failing when the container runs as a non-root user. Please test that directly instead (inline comments).

@Mario-Mohar

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I replaced both tests: they now start the container with withUser("redis") / withUser("valkey") plus withInitialData and read user:002 back. Without the fix all 6 fail with bash: /tmp/import.sh: Permission denied, with it the 57 tests in both modules pass.

@cristianrgreco cristianrgreco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@cristianrgreco
cristianrgreco merged commit d8b2cd1 into testcontainers:main Nov 19, 2026
188 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use octal file modes in the Redis and Valkey modules

2 participants