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

Support overlayfs path contains colon #3581

Merged

Conversation

chenk008
Copy link
Contributor

@chenk008 chenk008 commented Oct 11, 2021

Signed-off-by: chenk008 kongchen28@gmail.com

What type of PR is this?

/kind bug

What this PR does / why we need it:

After patched this PR containers/podman#11912, podman run --rootfs /root/a:b:O echo hello failed with error message

Error: rootfs-overlay: creating overlay failed "/root/a:b" from native overlay: mount overlay:/var/lib/containers/storage/overlay-containers/6f8b0d6252f15175c8006235ad246a9b163ed293ba4dcc8886a65d7d5673fd21/rootfs/merge, flags: 0x4, data: lowerdir=/root/a:b,upperdir=/var/lib/containers/storage/overlay-containers/6f8b0d6252f15175c8006235ad246a9b163ed293ba4dcc8886a65d7d5673fd21/rootfs/upper,workdir=/var/lib/containers/storage/overlay-containers/6f8b0d6252f15175c8006235ad246a9b163ed293ba4dcc8886a65d7d5673fd21/rootfs/work,context="system_u:object_r:container_file_t:s0:c364,c880": no such file or directory

But overlayfs mount support path which contains colon, the below command works.

mount -t overlay overlay -o lowerdir='/root/a\:b',upperdir=/var/lib/containers/storage/overlay-containers/4eb7c0ede19c7a837b7d790d5d2bc7c3ad95cd47fbedc056a96a45e8c371201e/rootfs/upper,workdir=/var/lib/containers/storage/overlay-containers/4eb7c0ede19c7a837b7d790d5d2bc7c3ad95cd47fbedc056a96a45e8c371201e/rootfs/work /var/lib/containers/storage/overlay-containers/4eb7c0ede19c7a837b7d790d5d2bc7c3ad95cd47fbedc056a96a45e8c371201e/rootfs/merge

How to verify it

podman run --rootfs /root/a:b:O echo hello succeeded to echo hello.

Which issue(s) this PR fixes:

It is related to containers/podman#11913

Special notes for your reviewer:

Does this PR introduce a user-facing change?

None

@TomSweeneyRedHat
Copy link
Member

@chenk008 thanks for the PR. Our CI system won't accept a PR without a new test added. Could you add a simple one, and your verification sample would work well, please?

Otherwise the code LGTM. Although a small comment above your new function might be useful.

@chenk008
Copy link
Contributor Author

chenk008 commented Oct 12, 2021

@TomSweeneyRedHat Thanks for your suggestion.

I am trying to find a way to add some test. I found only buildah run --volume /root/a:/root/test:O will use overlayfs mount in buildah. So I want to support volume contains colon (e.g. buildah run --volume /root/a\:b:/root/test:O), do you think it is fine?

@TomSweeneyRedHat
Copy link
Member

@chenk008 that would work for me, but I'm not sure if you need the \ before the b.

@flouthoc
Copy link
Collaborator

@chenk008 Could you break your commit message into multiple lines. CI is failing because commit message is too long.

@chenk008 chenk008 changed the title Support overlayfs path contains colon [WIP] Support overlayfs path contains colon Oct 13, 2021
@chenk008 chenk008 force-pushed the support_colon_in_overlay_path branch 3 times, most recently from a85cb01 to 93dff78 Compare October 14, 2021 12:48
@chenk008
Copy link
Contributor Author

@TomSweeneyRedHat Indeed the \ before the : will tell the argument parser the : should not be regarded as separator.

@chenk008
Copy link
Contributor Author

@flouthoc Thanks for your suggestion, I rewrited the commit message.

@chenk008 chenk008 force-pushed the support_colon_in_overlay_path branch 3 times, most recently from e8a2365 to 688b9fa Compare October 18, 2021 01:33
@chenk008 chenk008 changed the title [WIP] Support overlayfs path contains colon Support overlayfs path contains colon Oct 18, 2021
@rhatdan
Copy link
Member

rhatdan commented Oct 18, 2021

@chenk008 You need to rebase your merge to get rid of the merge commit.

git rebase -i origin
git push --force

@rhatdan
Copy link
Member

rhatdan commented Oct 18, 2021

LGTM
@flouthoc PTAL

val := SplitStringWithColonEscape(args.volume)
assert.Equal(t, val, args.expectedResult)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@TomSweeneyRedHat
Copy link
Member

LGTM

@chenk008 chenk008 force-pushed the support_colon_in_overlay_path branch from b4b2803 to f3e30fd Compare October 19, 2021 01:37
@chenk008
Copy link
Contributor Author

@rhatdan Thanks for your suggestion. I have squashed commits.

pkg/overlay/overlay.go Outdated Show resolved Hide resolved
@@ -105,8 +105,7 @@ func mountHelper(contentDir, source, dest string, _, _ int, graphOptions []strin
return mount, err
}
}

overlayOptions = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s,private", source, upperDir, workDir)
overlayOptions = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s,private", escapeColon(source), upperDir, workDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not scoped to this PR: but since we have a boilerplate for escaping we could also support escaping source and dest for other types not just overlay. No actionable on this comment just leaving here for note.

// the colon is backslash-escaped
if idx-1 > 0 && str[idx-1] == '\\' {
sb.WriteRune(r)
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we ever get to this else since all the escape colons are filtered by the first if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we get a separator : without \, we will reach to the else and get a slice element.

@flouthoc
Copy link
Collaborator

LGTM, Just couple of nit or doubt. @nalind @giuseppe PTAL

In linux, directory can contains colon.
Add support to mount path contains colon.

buildah run --volume /root/a\\:b:/root/test:O

Signed-off-by: chenk008 <kongchen28@gmail.com>
@chenk008 chenk008 force-pushed the support_colon_in_overlay_path branch from f3e30fd to 03186a3 Compare October 20, 2021 06:40
@rhatdan
Copy link
Member

rhatdan commented Oct 21, 2021

/lgtm
/approve
Thanks @chenk008

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 21, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chenk008, 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-merge-robot openshift-merge-robot merged commit e2c952f into containers:main Oct 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2023
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