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

Don't accidently remove XDG_RUNTIME_DIR when reseting storage #8750

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Dec 16, 2020

In certain cases XDG_RUNTIME_DIR was deleted by accident based on
settings in the storage.conf. This patch verifies that when doing
a storage reset, we don't accidently remove XDG_RUNTIME_DIR.

Fixes: #8680

Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 16, 2020
_, prevError := r.store.Shutdown(true)
if err := os.RemoveAll(r.store.GraphRoot()); err != nil {
graphRoot := r.store.GraphRoot()
if graphRoot == xdgRuntimeDir {
Copy link

Choose a reason for hiding this comment

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

I'm not very familiar with Go, so is that a string equality, or does it handle minor differences between paths as they might have been defined, eg. with or without a trailing /.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just string equality.

Copy link
Member Author

Choose a reason for hiding this comment

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

The filepath.Clean() will cleanup extra "/" and other cruft in the paths.

libpod/reset.go Outdated
@@ -77,18 +77,35 @@ func (r *Runtime) Reset(ctx context.Context) error {
}
}

xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
Copy link

Choose a reason for hiding this comment

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

The documentation XDG_RUNTIME_DIR says:

 If $XDG_RUNTIME_DIR is not set applications should fall back to a replacement directory with similar capabilities and print a warning message. Applications should use this directory for communication and synchronization purposes and should not place larger files in it, since it might reside in runtime memory and cannot necessarily be swapped out to disk.

So this should probably fallback to /run/user/<uid>.

}
if err := os.RemoveAll(r.store.RunRoot()); err != nil {
runRoot := r.store.RunRoot()
if runRoot == xdgRuntimeDir {
Copy link

Choose a reason for hiding this comment

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

It might be worth checking whether the "run root" is correctly prefixed, if it is a child of xdgRuntimeDir.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why would that matter?

Copy link

Choose a reason for hiding this comment

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

It matters if you can only do string comparisons. The new default configuration is $XDG_RUNTIME_DIR/overlays, it used to be $XDG_RUNTIME_DIR. You still don't want to nuke $XDG_RUNTIME_DIR/.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right the case above will only remove $XDG_RUNTIME_DIR/overlays which is what we want. It really does not mapper if XDG_RUNTIME_DIR/overlays or /random/path/overlays

@hadess
Copy link

hadess commented Dec 16, 2020

I'm slightly concerned about using string equality rather than path equality here, but looks good otherwise.

libpod/reset.go Outdated
if prevError != nil {
logrus.Error(prevError)
}
prevError = err
prevError = errors.Errorf("failed to remove runtime tmpdir %s, since it is the same XDG_RUNTIME_DIR", tempDir)
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
prevError = errors.Errorf("failed to remove runtime tmpdir %s, since it is the same XDG_RUNTIME_DIR", tempDir)
prevError = errors.Errorf("failed to remove runtime tmpdir %s, since it is the same as XDG_RUNTIME_DIR", tempDir)

libpod/reset.go Outdated
if prevError != nil {
logrus.Error(prevError)
}
prevError = err
prevError = errors.Errorf("failed to remove runtime root dir %s, since it is the same XDG_RUNTIME_DIR", runRoot)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
prevError = errors.Errorf("failed to remove runtime root dir %s, since it is the same XDG_RUNTIME_DIR", runRoot)
prevError = errors.Errorf("failed to remove runtime root dir %s, since it is the same as XDG_RUNTIME_DIR", runRoot)

@TomSweeneyRedHat
Copy link
Member

Couple small nits, LGTM once cleared.

Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat left a comment

Choose a reason for hiding this comment

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

LGTM
I like the filepath clean bit, will have to try and remember that for the future. Good call @hadess

In certain cases XDG_RUNTIME_DIR was deleted by accident based on
settings in the storage.conf. This patch verifies that when doing
a storage reset, we don't accidently remove XDG_RUNTIME_DIR.

Fixes: containers#8680

Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2020
@openshift-merge-robot openshift-merge-robot merged commit c38ae47 into containers:master Dec 17, 2020
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"toolbox reset" nukes files that don't belong to it
5 participants