Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run: use internal.GetTempDir with os.MkdirTemp for root and bundle path #5084

Merged
merged 1 commit into from Oct 12, 2023

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Oct 11, 2023

Projects which are using buildah as a library and set TMPDIR manually can stumble upon a use-case where TMPDIR was set to a relative path.

Such as export TMPDIR=. in such case buildah will try to create a temporary root using Mkdirtemp leading to a point where bundle is not generated correctly since path was relative.

Following use case can be resolved by making sure that buildah always converts relative path to absolute path and GetTempDir does it well.

Example reproducer with podman

FROM alpine
RUN echo hello
export TMPDIR=.
podman build --no-cache -t test .

Expected failure

STEP 1/2: FROM alpine
STEP 2/2: RUN echo hello
error running container: checking permissions on "buildah2341274198": stat buildah2341274198: no such file or directory
ERRO[0000] did not get container create message from subprocess: EOF
Error: building at STEP "RUN echo hello": while running runtime: exit status 1

Closes: RHEL-2598

What type of PR is this?

/kind api-change
/kind bug
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

What this PR does / why we need it:

How to verify it

  • Integration test cannot be added as it can be only reproduced by projects which are using buildah as a library ( such as podman ) however reproducer for podman is given to verify the bug.

  • Unit test added for GetTempDir to make sure it is converting relative values to TMPDIR to absolute

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

run: use internal.GetTempDir instead of os.MkdirTemp

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -499,7 +504,7 @@ func setupSlirp4netnsNetwork(config *config.Config, netns, cid string, options [
Mask: res.Subnet.Mask,
}}
netStatus := map[string]nettypes.StatusBlock{
slirp4netns.BinaryName: nettypes.StatusBlock{
slirp4netns.BinaryName: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gofmt did this change and it not relevant to this PR

@packit-as-a-service
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@flouthoc flouthoc requested a review from nalind October 11, 2023 07:16
@flouthoc flouthoc changed the title run: use internal.GetTempDir instead of os.MkdirTemp for root and bundle path run: use internal.GetTempDir with os.MkdirTemp for root and bundle path Oct 11, 2023
@rhatdan
Copy link
Member

rhatdan commented Oct 11, 2023

LGTM
@vrothberg @giuseppe @nalind @umohnani8 @Luap99 PTAL

@nalind
Copy link
Member

nalind commented Oct 11, 2023

Does this also need to touch call sites in image.go and sshagent.go?

Projects which are using buildah as a library and set `TMPDIR` manually
can stumble upon a use-case where `TMPDIR` was set to a relative path.

Such as `export TMPDIR=.` in such case buildah will try to create a
temporary root using `Mkdirtemp` leading to a point where bundle is not
generated correctly since path was relative.

Following use case can be resolved by making sure that buildah always
converts relative path to absolute path and `GetTempDir` does it well.

Example reproducer with podman

```Dockerfile
FROM alpine
RUN echo hello
```

```console
export TMPDIR=.
podman build --no-cache -t test .
```

Expected failure
```console
STEP 1/2: FROM alpine
STEP 2/2: RUN echo hello
error running container: checking permissions on "buildah2341274198": stat buildah2341274198: no such file or directory
ERRO[0000] did not get container create message from subprocess: EOF
Error: building at STEP "RUN echo hello": while running runtime: exit status 1
```

Closes: RHEL-2598

Signed-off-by: Aditya R <arajan@redhat.com>
@flouthoc
Copy link
Collaborator Author

@nalind Good point. Done.

@nalind
Copy link
Member

nalind commented Oct 11, 2023

LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 11, 2023

/hold
/lgtm

@umohnani8
Copy link
Member

LGTM

@flouthoc
Copy link
Collaborator Author

/hold cancel

@flouthoc flouthoc merged commit 3c8a3a2 into containers:main Oct 12, 2023
33 of 36 checks passed
@TomSweeneyRedHat
Copy link
Member

Late for the review, but a very nice change @flouthoc

flouthoc added a commit to flouthoc/podman that referenced this pull request Oct 16, 2023
Test edge-case described here: containers/buildah#5084
Test case in: RHEL-2598

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/podman that referenced this pull request Oct 16, 2023
Test edge-case described here: containers/buildah#5084
Test case in: RHEL-2598

Signed-off-by: Aditya R <arajan@redhat.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants