Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

Conversation

@monstermunchkin
Copy link
Contributor

Support for non-numerical uid/gid added, as specified by appc.

Resolves #1919

pexit_if((f = fopen(path, "r")) == NULL, "Unable to open \"%s\"", path);

while (getline(&line, &llen, f) != -1) {
s = strdup(line);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't s be free()'d when done?

@alban
Copy link
Member

alban commented Feb 9, 2016

Thanks for this work!

All the parsing is done in C via appexec.c and not in Go via stage1/init/common/pod.go:appToSystemd. I wonder why this choice. It might be easier to do in Go because:

  • There is already related code for that in group.go (but it might change in rkt should not use /etc/group directly #2105 so not sure if it is a good idea to use that)
  • When the file is missing in the ACI, the error is produced late, after the pod has been started rather than before. It means it cannot use the structured error formatting (Make errors structured #1937 /cc @blixtra ) and the errors are less user-friendly. For example, instead of Cannot stat "/opt/stage2/rkt-inspect/rootfs/etc/nofile", I would prefer to see something like "The ACI image xyz uses group /foo/xyz but file /foo/xyz does not exist in the ACI" or similar.

What do you think?

@monstermunchkin
Copy link
Contributor Author

I just thought I'd validate shortly before entering the chroot. Other than that, there was no particular reason I chose C over Go.

Thanks for pointing out group.go, I didn't know about that code. If the ability to parse /etc/group-like files doesn't get removed completely, I could use it. It might also be useful having similar code which parses /etc/passwd-like files. Perhaps in pkg/passwd/passwd.go?

Structured and user-friendly errors are a good point. I'll be moving the validation to Go then.

@alban
Copy link
Member

alban commented Feb 9, 2016

@monstermunchkin not sure what form it should take. I added a note in #2105.

@monstermunchkin
Copy link
Contributor Author

So, I have moved the validation to stage1/init/common/pod.go:appToSystemd. The group package can now also read from a specified file, and the passwd package has been added which does the same, only for passwd-like files.

Please let me know what you think about the code.

if strings.HasPrefix(app.User, "/") {
var stat syscall.Stat_t
if err = syscall.Lstat(strings.Join([]string{common.AppRootfsPath(p.Root, appName),
app.User}, "/"), &stat); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you append a "/" at the end of the filename for lstat?

ditto for the groups below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be filepath.Join(common.AppRootfsPath(p.Root, appName), app.User).

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, I read filepath.Join instead of strings.Join. I agree that using filepath.Join is better in that case.

@monstermunchkin
Copy link
Contributor Author

Thanks for the feedback, I did some changes.

When using path-like uid/gid, UnshiftRange is called, which is now part of uid/uid.go. The function prototype is basically the same as ShiftRange. It could however be changed to accept a single argument, and return (uint32, error) instead of (uint32, uint32, error).

The function prototypes of parseGroupLine and parsePasswdLine have been changed, and return an error if necessary. The related tests have been updated as well.

}

for i, tt := range tests {
g, err := parsePasswdLine(tt.line)
Copy link
Member

Choose a reason for hiding this comment

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

p, err := ...

@alban
Copy link
Member

alban commented Feb 19, 2016

One small change, then the code looks good to me. Can you add an entry in CHANGELOG.md?

@krnowak can you review the changes in tests/functional.mk?

@krnowak
Copy link
Collaborator

krnowak commented Feb 19, 2016

Lemme see.

// This is a partial implementation for app.User and app.Group:
// For now, only numeric ids (and the string "root") are supported.
var uid, gid int
var _uid, gid int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why prepending an underline to the uid variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise it conflicts with the uid package since uid.NewBlankUidRange() is called shortly after. Are there any preferred naming rules in situations like these?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I missed that. Ok, let's keep it like that then. I'm not aware of any rules for that.

}
uidReal, _, err := uidRange.UnshiftRange(stat.Uid, 0)
if err != nil {
return errwrap.Wrap(fmt.Errorf("unable to determine real uid"), err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

errors.New.

@krnowak
Copy link
Collaborator

krnowak commented Feb 19, 2016

Some nitpicks, otherwise LFAD.

The passwd package looks up given user name.
Allow looking up gids from a specified file. This makes gid validation
easier.
Instead of relying on the caller to provide a Group struct which
parseGroupLine then fills with data, a Group struct is created within
the function and then returned.
If the line is not parseable, an error is returned instead.
Add support for non-numerical uid/gid, as specified by appc. Uid/gid can
be numerical, textual, or path-like.

Resolves #1919
@alban
Copy link
Member

alban commented Feb 19, 2016

Thank you! LGTM.

alban added a commit that referenced this pull request Feb 19, 2016
stage1,tests: add support for non-numerical uid/gid
@alban alban merged commit 849adaf into rkt:master Feb 19, 2016
@alban alban mentioned this pull request Feb 25, 2016
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.

3 participants