Skip to content

Conversation

giuseppe
Copy link
Member

the store might be owned by another user.

Closes: #1827

@giuseppe giuseppe force-pushed the overlay-ignore-mkdir-fail-in-additional-store branch from ad64c96 to 0050c51 Compare February 13, 2024 14:30
@giuseppe giuseppe changed the title overlay: ignore chown errors in adidtionalimagestore overlay: ignore chown errors in additionalimagestore Feb 13, 2024
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

This would ignore all kinds of errors; is there a way to restrict this to chown errors only?

if !inAdditionalStore { MkdirAllAs } else { MkdirAll } seems to be an option. I don’t immediately know about the Rmdir one.


Or, really, if the store is supposed to be read-only, then why change it at all? Test that the directories exist, and fail if they don’t.

But if the merged directory is supposed to be created on a Get and always deleted on a Put, I can’t see how that can possibly work as truly read-only additional image store: a “legitimate” image store won’t have the merged directory, and we won’t be able to create it. Am I missing something?

@giuseppe
Copy link
Member Author

This would ignore all kinds of errors; is there a way to restrict this to chown errors only?

if !inAdditionalStore { MkdirAllAs } else { MkdirAll } seems to be an option. I don’t immediately know about the Rmdir one.

Or, really, if the store is supposed to be read-only, then why change it at all? Test that the directories exist, and fail if they don’t.

But if the merged directory is supposed to be created on a Get and always deleted on a Put, I can’t see how that can possibly work as truly read-only additional image store: a “legitimate” image store won’t have the merged directory, and we won’t be able to create it. Am I missing something?

the correct test would be to check whether the directory has the ContainersOverrideXattr xattr set and assume fuse-overlayfs is used, in this case the mode specified in the xattr will be used, no matter what is the mode on the directory itself. But do we care to make it so specific and not just try in any case?

If you prefer, I can rewrite it as:

if !inAdditionalStore { MkdirAllAs } else { // do nothing, just assume it exists }

are you ok with it?

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 13, 2024

(Warning: I don’t understand the full feature, I’m going just by the bug report and the PR.)

Yes, the talk about “read-only additional image store” would lead to basically what you propose. I don’t feel too strongly about the “test that the directories exist” part. But then I saw the Remove of merged — and I don’t understand how that could work. I assume it does actually work for you — so I’m missing something trivial.

@giuseppe
Copy link
Member Author

Yes, the talk about “read-only additional image store” would lead to basically what you propose. I don’t feel too strongly about the “test that the directories exist” part. But then I saw the Remove of merged — and I don’t understand how that could work. I assume it does actually work for you — so I’m missing something trivial.

I am not even sure why we need to rm the mount directory, we could just drop that code IMO, so we don't have to worry whether the store is read-only or writeable

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 13, 2024

Git blame points at #390 .

And I’m still interested in understanding how this works in the first place, in #1828 (review) . (Admittedly I didn’t try that in practice.)

@giuseppe
Copy link
Member Author

And I’m still interested in understanding how this works in the first place, in #1828 (review) . (Admittedly I didn’t try that in practice.)

the question is: should we fail when the directory in the additional image store (which is supposed to be R/O) doesn't exist but the user has enough privileges to create it? Or should we try to create it anyway?

	if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
		if !inAdditionalStore {
			return "", err
		}
		// if it is in an additional store, do not fail if the directory already exists
		if _, err2 := os.Stat(mergedDir); err2 != nil {
			return "", err
		}
	}

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 13, 2024

Oh I don’t have a strong opinion on that design question.

I’m stuck at an earlier phase: If the user doesn’t have enough privileges, I understand mergedDir should not exist most of the time. So how does this work when we can’t create it, and it doesn’t exist? … and if it doesn’t, the primary goal of this PR can’t be achieved at all AFAICT.

@giuseppe
Copy link
Member Author

I understand mergedDir should not exist most of the time.

if you just perform a "pull" then the directory exists, at least until you try to mount/unmount it.

Maybe we can replace the rmdir with a rename("merged.tmp", "merged")? It is an atomic operation with empty directories

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 13, 2024

if you just perform a "pull" then the directory exists, at least until you try to mount/unmount it.

OK I’ll need to look into the situation in more detail, then.


Maybe we can replace the rmdir with a rename

Does that retain the originally-wanted benefit of handling leaked mounts?

@giuseppe
Copy link
Member Author

``

Does that retain the originally-wanted benefit of handling leaked mounts?

I think it does, although after started looking into it, I am not sure we need to overcomplicate the code for such a corner case where an image is mounted/unmounted on an additional image store

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 13, 2024

*shrug* the original thing smells like a workaround, and it seems no-one cared enough to document in detail what it is working around (or maybe it is not known at all).

The trouble is that when creating the image, we don’t know that the store is going to later be used as an additional one.


One entirely different possibility might be to create the mounts somewhere else, not in the read-only additional store. That’s rather more disruptive.

But really I need to understand what happens on pull, first. Hopefully tomorrow. For now, I’m just confused.

@giuseppe giuseppe force-pushed the overlay-ignore-mkdir-fail-in-additional-store branch from 0050c51 to 56970a7 Compare February 14, 2024 11:31
Copy link
Contributor

openshift-ci bot commented Feb 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe

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

@giuseppe
Copy link
Member Author

I've replaced the Rmdir with a Rename so we can safely assume the merged directory is never removed.

Differently the diffDir errors are ignored, it might have the wrong ownership but should not really matter with additional image stores since we are already expecting the files in the additional image store owned by a different user to have different ownership.

// its atomic semantic. In this way the "merged" directory is never removed.
if err := unix.Rename(tmpMountpoint, mountpoint); err != nil {
logrus.Debugf("Failed to replace mountpoint %s overlay: %s - %v", id, mountpoint, err)
return fmt.Errorf("replacingmount point %q: %w", mountpoint, err)
Copy link
Member

Choose a reason for hiding this comment

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

nit: "replacing mount point %q: %w"


tmpMountpoint := path.Join(dir, "merged.1")
if err := idtools.MkdirAs(tmpMountpoint, 0o700, uid, gid); err != nil && !os.IsExist(err) {
Copy link
Member

@rhatdan rhatdan Feb 15, 2024

Choose a reason for hiding this comment

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

sed 's/os.IsExists(err)/errors.Is(err, os.ErrExist)/g'

@giuseppe giuseppe force-pushed the overlay-ignore-mkdir-fail-in-additional-store branch from 56970a7 to d7ca4a0 Compare February 15, 2024 12:38
@giuseppe
Copy link
Member Author

comments addressed ⬆️

@rhatdan
Copy link
Member

rhatdan commented Feb 16, 2024

LGTM
@mtrmac @nalind @saschagrunert @vrothberg PTAL

@TomSweeneyRedHat
Copy link
Member

LGTM
but definitely want a @mtrmac or @nalind head nod

@rhatdan rhatdan added the 5.0 label Feb 21, 2024
instead of removing the "merged" directory, replace it with a fresh
empty directory so that we can assume "merged" is always present and
there is no need to recreate it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
after the commit "overlay: replace rmdir with rename", it is safe to
assume it is never deleted.

Closes: containers#1827

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the overlay-ignore-mkdir-fail-in-additional-store branch from c5ba0c6 to 652b613 Compare February 23, 2024 08:22
ignore errors creating and chowning the diffDiff if it is in an
additional image store.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the overlay-ignore-mkdir-fail-in-additional-store branch from 652b613 to 9846c10 Compare February 23, 2024 08:30
@giuseppe
Copy link
Member Author

there are two reviews, can we get this merged?

@rhatdan
Copy link
Member

rhatdan commented Feb 27, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Feb 27, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 8a4fb72 into containers:main Feb 27, 2024
@nalind
Copy link
Member

nalind commented Jun 12, 2024

/cherry-pick release-1.42

@openshift-cherrypick-robot

@nalind: #1828 failed to apply on top of branch "release-1.42":

Applying: overlay: replace rmdir with rename
Using index info to reconstruct a base tree...
M	drivers/overlay/overlay.go
Falling back to patching base and 3-way merge...
Auto-merging drivers/overlay/overlay.go
CONFLICT (content): Merge conflict in drivers/overlay/overlay.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 overlay: replace rmdir with rename
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.42

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@nalind
Copy link
Member

nalind commented Jun 12, 2024

/cherry-pick release-1.45

@openshift-cherrypick-robot

@nalind: #1828 failed to apply on top of branch "release-1.45":

Applying: overlay: replace rmdir with rename
Using index info to reconstruct a base tree...
M	drivers/overlay/overlay.go
Falling back to patching base and 3-way merge...
Auto-merging drivers/overlay/overlay.go
CONFLICT (content): Merge conflict in drivers/overlay/overlay.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 overlay: replace rmdir with rename
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.45

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@TomSweeneyRedHat
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

additionalimagestores Not Working as Expected
6 participants