[FLINK-37881] Drop gosu in favour of Dockerfile USER#242
Merged
gaborgsomogyi merged 2 commits intoapache:dev-masterfrom Nov 18, 2025
Merged
[FLINK-37881] Drop gosu in favour of Dockerfile USER#242gaborgsomogyi merged 2 commits intoapache:dev-masterfrom
gaborgsomogyi merged 2 commits intoapache:dev-masterfrom
Conversation
Contributor
|
I've gone through the code and one suggestion is that we should add migration patterns into the readme on |
Contributor
|
In the meantime I've made extensive testing on the code, namely:
|
Contributor
|
I think this will be good to go if nobody has comments and after rebase to latest. |
This change removes the gosu dependency for privilege dropping in favor of using the Dockerfile USER directive, which is the modern, recommended approach for running containers as non-root users. Changes: - Removed gosu installation and verification from Dockerfile template - Added USER flink directive before COPY in Dockerfile template - Replaced drop_privs_cmd() with check_priv_user() that warns if running as root instead of using gosu to drop privileges - Removed all $(drop_privs_cmd) calls from exec commands in entrypoint This aligns with security best practices by ensuring containers run as non-root from the start rather than starting as root and dropping privileges at runtime.
334f1cd to
2dfcfa6
Compare
Author
|
rebased |
gaborgsomogyi
approved these changes
Nov 11, 2025
Contributor
|
Waiting couple of days before merge to see whether somebody has comments |
Author
|
Thank you, @gaborgsomogyi |
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.
This PR removes the
gosuutility from Flink Docker images, replacing privilege-dropping at runtime with the DockerfileUSERdirective. This change improves security by following the principle of least privilege and aligns with modern container security best practices.Breaking Changes
Images now start as the
flinkuser (UID 9999) instead of root. This affects users who build custom Dockerfiles inheriting from official Flink images.Migration Required for Custom Dockerfiles
Before this change:
After this change:
Changes in This PR
Dockerfile Template (
Dockerfile-ubuntu.template)USER flinkdirective before entrypoint configurationEntrypoint Script (
docker-entrypoint.sh)drop_privs_cmd()withcheck_priv_user()that warns when running as root$(drop_privs_cmd)from all exec commandsflinkuser throughout its lifecycleSecurity Benefits
Impact Assessment
Affected Users
flink:*imagesCommon Migration Patterns
1. System Package Installation
2. File Copying with Ownership
3. Directory Creation
Kubernetes Considerations
If you have customised kubernetes entrypoint scripts, and you happen to have a volume mounts that the script was accessing, the volume mounts may require
fsGroupconfiguration:Testing
A comprehensive test suite has been added to validate the changes:
Test script:
testing/test-gosu-removal.shRollback Plan
Users requiring the old behavior can:
Affected Versions
Previous versions (1.19.x and earlier) are unaffected.
Documentation Updates
This breaking change will be documented in:
Related Work
Checklist