Skip to content

fix: confine Docker copy dependency sources#10074

Open
fsabiu wants to merge 2 commits into
GoogleContainerTools:mainfrom
fsabiu:fix-docker-copy-source-context
Open

fix: confine Docker copy dependency sources#10074
fsabiu wants to merge 2 commits into
GoogleContainerTools:mainfrom
fsabiu:fix-docker-copy-source-context

Conversation

@fsabiu
Copy link
Copy Markdown

@fsabiu fsabiu commented May 3, 2026

Description

Confine Dockerfile COPY and ADD dependency sources to the configured
Skaffold build context before dependency walking or build-context packaging.

Skaffold already treats these sources as relative to the build context. This
change makes that boundary explicit by resolving each source against the
workspace and rejecting any source that resolves outside it.

The new regression coverage checks both:

  • a direct parent-path source in the project Dockerfile;
  • a parent-path source inherited from base-image ONBUILD metadata.

User Facing Changes

Skaffold now returns an error when a Dockerfile COPY or ADD source resolves
outside the artifact build context instead of treating the outside path as a
dependency.

Tests

go test ./pkg/skaffold/docker

@fsabiu fsabiu requested a review from a team as a code owner May 3, 2026 13:30
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 3, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements validation to prevent Docker COPY commands from accessing files outside the build context. It introduces a new helper function resolveCopySourceInWorkspace to validate and resolve source paths, and includes unit tests to ensure that paths resolving outside the workspace are correctly rejected. Feedback was provided regarding a performance improvement to avoid redundant absolute path calculations for the workspace within loops.

Comment thread pkg/skaffold/docker/parse.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant