fix: resolve dockerfile_template with secure=False during containerize#5596
Open
Abhishek8108 wants to merge 2 commits intobentoml:mainfrom
Open
fix: resolve dockerfile_template with secure=False during containerize#5596Abhishek8108 wants to merge 2 commits intobentoml:mainfrom
Abhishek8108 wants to merge 2 commits intobentoml:mainfrom
Conversation
resolve_user_filepath was called with the default secure=True in generate_containerfile, which checks that the resolved path is relative to os.getcwd(). During `bentoml containerize` the build context is a BentoML-managed temp directory (e.g. /tmp/...), not the user's project directory, so the check is a false positive and raises ValueError. Pass secure=False since the path is resolved against a BentoML-controlled directory, not a user-supplied path — the template was already validated and copied into the bento archive during `bentoml build`. Fixes bentoml#5566
For more information, see https://pre-commit.ci
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.
Summary
Fixes #5566.
bentoml containerizeraisedValueError: Accessing file outside of current working directory is not allowedfor any bento that usesdockerfile_template. This is a regression introduced in #5548.Root cause:
generate_containerfilecalledresolve_user_filepath(user_templates, build_ctx)with the defaultsecure=True. Thesecure=Truecheck verifies that the resolved path is relative toos.getcwd(). Duringbentoml containerize,build_ctxis a BentoML-managed temp directory (e.g./tmp/...), which is never under the user's CWD — so the check fires as a false positive.Fix: Pass
secure=Falsewhen resolving the template path insidegenerate_containerfile. This is correct because:build_config.pyduringbentoml build(wheresecure=Trueis appropriate)build_ctxis a BentoML-controlled temp dir, not a user-supplied pathbuild_ctx— there is no security concernChange: One argument added to one call site in
generate.py. Regression test added totest_generate.pythat reproduces the failure before the fix and passes after.Test plan
test_generate_containerfile_dockerfile_template_outside_cwdpasses (creates a template intmp_path, which is outside CWD, and callsgenerate_containerfile— previously raisedValueError)test_generate_containerfile_quotes_system_packagesstill passespytest tests/unit/_internal/container/test_generate.py -v