Skip to content

Conversation

sorenhansendk
Copy link
Contributor

@sorenhansendk sorenhansendk commented Aug 30, 2023

  • Beautified the Dockerfile a little bit
  • Running the container as the dfly user resolves write permission issues on volumes provisioned on the Container-as-a-service provider, fly.io. If the container runs as root (which is the default if no user is specified), I'm unable to write files to an external /data volume. Additionally - it's also considered as best practice to execute a container with a user account that has lower privileges than root

I think it can solve this discussion: #1527

romange
romange previously approved these changes Aug 31, 2023
@romange
Copy link
Collaborator

romange commented Aug 31, 2023 via email

@sorenhansendk
Copy link
Contributor Author

Can you please update all other Dockerfiles in the folder with this change?

Sure! I have force-pushed a fix to all 4 files 👍

@romange
Copy link
Collaborator

romange commented Aug 31, 2023

Gonna be released in 1.9.0 . Thanks again for catching this!

@romange romange enabled auto-merge (squash) August 31, 2023 16:41
@romange romange merged commit 7492550 into dragonflydb:main Aug 31, 2023
@sorenhansendk sorenhansendk deleted the patch-1 branch September 1, 2023 09:29
romange added a commit that referenced this pull request Aug 15, 2024
Fixes #2917

The problem is described in this "working as intended" issue moby/moby#3124
So the advised approach of using "USER dfly" directive does not really work because it requires
that the host will also define 'dfly' user with the same id. It's unrealistic expectation.

Therefore, we revert the fix done in #1775 and follow valkey approach:
https://github.com/valkey-io/valkey-container/blob/mainline/docker-entrypoint.sh#L12

1. we run the entrypoint in the container as root which later spawns the dragonfly process
2. if we run as root:
   a. we chmod files under /data to dfly.
   b. use su-exec to run exec ourselves as dfly.
3. if we do not run as root we execute the docker command.

So even though the process starts as root, the server runs as dfly and only the bootstrap
part has elevated permissions is used to fix the volume access.

While we are at it, we also switched to setpriv following the change of https://github.com/valkey-io/valkey-container/pull/24/files

Signed-off-by: Roman Gershman <[email protected]>
romange added a commit that referenced this pull request Aug 15, 2024
Fixes #2917

The problem is described in this "working as intended" issue moby/moby#3124
So the advised approach of using "USER dfly" directive does not really work because it requires
that the host will also define 'dfly' user with the same id. It's unrealistic expectation.

Therefore, we revert the fix done in #1775 and follow valkey approach:
https://github.com/valkey-io/valkey-container/blob/mainline/docker-entrypoint.sh#L12

1. we run the entrypoint in the container as root which later spawns the dragonfly process
2. if we run as root:
   a. we chmod files under /data to dfly.
   b. use su-exec to run exec ourselves as dfly.
3. if we do not run as root we execute the docker command.

So even though the process starts as root, the server runs as dfly and only the bootstrap
part has elevated permissions is used to fix the volume access.

While we are at it, we also switched to setpriv following the change of https://github.com/valkey-io/valkey-container/pull/24/files

Signed-off-by: Roman Gershman <[email protected]>
romange added a commit that referenced this pull request Aug 15, 2024
Fixes #2917

The problem is described in this "working as intended" issue moby/moby#3124
So the advised approach of using "USER dfly" directive does not really work because it requires
that the host will also define 'dfly' user with the same id. It's unrealistic expectation.

Therefore, we revert the fix done in #1775 and follow valkey approach:
https://github.com/valkey-io/valkey-container/blob/mainline/docker-entrypoint.sh#L12

1. we run the entrypoint in the container as root which later spawns the dragonfly process
2. if we run as root:
   a. we chmod files under /data to dfly.
   b. use setpriv to exec ourselves as dfly.
3. if we do not run as root we execute the docker command.

So even though the process starts as root, the server runs as dfly and only the bootstrap
part has elevated permissions is used to fix the volume access.

While we are at it, we also switched to setpriv following the change of https://github.com/valkey-io/valkey-container/pull/24/files

Signed-off-by: Roman Gershman <[email protected]>
romange added a commit that referenced this pull request Aug 22, 2024
Fixes #2917

The problem is described in this "working as intended" issue moby/moby#3124
So the advised approach of using "USER dfly" directive does not really work because it requires
that the host will also define 'dfly' user with the same id. It's unrealistic expectation.

Therefore, we revert the fix done in #1775 and follow valkey approach:
https://github.com/valkey-io/valkey-container/blob/mainline/docker-entrypoint.sh#L12

1. we run the entrypoint in the container as root which later spawns the dragonfly process
2. if we run as root:
   a. we chmod files under /data to dfly.
   b. use setpriv to exec ourselves as dfly.
3. if we do not run as root we execute the docker command.

So even though the process starts as root, the server runs as dfly and only the bootstrap
part has elevated permissions is used to fix the volume access.

While we are at it, we also switched to setpriv following the change of https://github.com/valkey-io/valkey-container/pull/24/files

Signed-off-by: Roman Gershman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants