Repository navigation
Conversation
CreateJobPrerequisites runs as root on the host before launching a bpm container. Previously: 1. Additional volume paths were checked via os.Stat and paths were chowned via os.Chown, both of which follow symlinks. 2. Directory creation via createDirFor performed os.MkdirAll followed by os.Chown, which also followed symlinks. Because these paths reside in or can be placed in directories writable by the vcap user (such as ephemeral data directories or log directories), a compromised container could plant a symlink to an arbitrary host file or directory (e.g. /etc or /etc/shadow). On the next bpm restart, root-bpm would dereference the symlink and chown the host target to vcap. Fix: - Added safeio.MkdirAllChown and safeio.Lchown which use os.Lstat and os.Lchown to ensure symlinks are rejected and ownership changes do not follow symbolic links. - Updated CreateJobPrerequisites to verify additional volume paths with os.Lstat, rejecting symlink paths. - Replaced createDirFor and chownPaths with safeio.MkdirAllChown and safeio.Lchown. - Added comprehensive unit tests in safeio_test.go and adapter_test.go. [TNZGOV-18900] ai-assisted=yes
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Overview
Problem
CreateJobPrerequisites()runs as root on the host before launching a bpm container. Previously:os.Statand chowned viaos.Chown, both of which follow symlinks.createDirForperformedos.MkdirAllfollowed byos.Chown, which also followed symlinks.Because these paths reside in or can be placed in directories writable by the
vcapuser (such as ephemeral data directories or log directories), a compromised container could plant a symlink to an arbitrary host file or directory (e.g./etcor/etc/shadow). On the nextbpm startor restart, root-bpm would dereference the symlink and chown the host target tovcap, enabling container escape and root escalation.Fix
safeio.MkdirAllChownandsafeio.Lchownwhich useos.Lstatandos.Lchown(lchown(2)) to verify targets are not symlinks and prevent following symbolic links during ownership changes.CreateJobPrerequisitesto inspect additional volume paths withos.Lstat, rejecting symlink paths.createDirForandchownPathswithsafeio.MkdirAllChownandsafeio.Lchown.src/bpm/safeio/safeio_test.goandsrc/bpm/runc/adapter/adapter_test.go.