-
Notifications
You must be signed in to change notification settings - Fork 944
fix: check user/group in container start #1716
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import ( | |
| "io" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
|
|
@@ -13,6 +15,7 @@ import ( | |
| "github.com/alibaba/pouch/pkg/meta" | ||
| "github.com/alibaba/pouch/pkg/utils" | ||
|
|
||
| "github.com/containerd/containerd/mount" | ||
| "github.com/opencontainers/image-spec/specs-go/v1" | ||
| ) | ||
|
|
||
|
|
@@ -352,6 +355,46 @@ func (c *Container) UnsetMergedDir() { | |
| c.Snapshotter.Data["MergedDir"] = "" | ||
| } | ||
|
|
||
| // SetSnapshotterMeta sets snapshotter for container | ||
| func (c *Container) SetSnapshotterMeta(mounts []mount.Mount) { | ||
| // TODO(ziren): now we only support overlayfs | ||
| data := make(map[string]string, 0) | ||
| for _, opt := range mounts[0].Options { | ||
| if strings.HasPrefix(opt, "upperdir=") { | ||
| data["UpperDir"] = strings.TrimPrefix(opt, "upperdir=") | ||
| } | ||
| if strings.HasPrefix(opt, "lowerdir=") { | ||
| data["LowerDir"] = strings.TrimPrefix(opt, "lowerdir=") | ||
| } | ||
| if strings.HasPrefix(opt, "workdir=") { | ||
| data["WorkDir"] = strings.TrimPrefix(opt, "workdir=") | ||
| } | ||
| } | ||
|
|
||
| c.Snapshotter = &types.SnapshotterData{ | ||
| Name: "overlayfs", | ||
| Data: data, | ||
| } | ||
| } | ||
|
|
||
| // GetSpecificBasePath accepts a given path, look for whether the path is exist | ||
| // within container, if has, returns container base path like BaseFS, if not, return empty string | ||
| func (c *Container) GetSpecificBasePath(path string) string { | ||
| // first try container BaseFS, it is a general view, | ||
| if utils.IsFileExist(filepath.Join(c.BaseFS, path)) { | ||
| return c.BaseFS | ||
| } | ||
|
|
||
| // then try lower and upper directory, since overlay filesystem support only. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a good solution to fix mergeDir not mounted 👋 |
||
| for _, prefixPath := range c.Snapshotter.Data { | ||
| if utils.IsFileExist(filepath.Join(prefixPath, path)) { | ||
| return prefixPath | ||
| } | ||
| } | ||
|
|
||
| return "" | ||
| } | ||
|
|
||
| // ContainerRestartPolicy represents the policy is used to manage container. | ||
| type ContainerRestartPolicy types.RestartPolicy | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel weird ! can we judge whether the baseFS is mounted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is used to get specified file from container, BaseFs is not created when container start, so we can only try image path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i still have another question: can we ensure passwd file exists in UpperDir?
Or can we mount the mergedDir when we found it not mounted, then we can ensure the passwd file exists in MergedDir.
it's just my advice, you can think about it again, thanks a lot @Ace-Tang
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we run a container, merged dir is not created yet until pouch pass create options to containerd, then containerd created it and mount. Add this function cause we can only find file in image when container in start process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this pr can fix if merged dir is un-mounted by error.