Skip to content

libcontainer: user: always treat numeric ids numerically#708

Merged
cyphar merged 3 commits into
opencontainers:masterfrom
cyphar:treat-numric-ids-properly
Mar 30, 2016
Merged

libcontainer: user: always treat numeric ids numerically#708
cyphar merged 3 commits into
opencontainers:masterfrom
cyphar:treat-numric-ids-properly

Conversation

@cyphar

@cyphar cyphar commented Mar 30, 2016

Copy link
Copy Markdown
Member

Most shadow-related tools don't treat numeric ids as potential
usernames, so change our behaviour to match that. Previously, using an
explicit specification like 111:222 could result in the UID and GID not
being 111 and 222 respectively (which is confusing).

Fixes #695

Signed-off-by: Aleksa Sarai [email protected]

@cyphar

cyphar commented Mar 30, 2016

Copy link
Copy Markdown
Member Author

@tianon I know it's been a while, but I've refactored most of the code you wrote a few years ago. Want to take a look? :P

Comment thread libcontainer/user/user.go Outdated
// panic, because this is a programming/logic error, not a runtime one
panic("parseLine expects only pointers! argument " + strconv.Itoa(i) + " is not a pointer!")
// Someone goof'd when writing code using this function. Scream so they can hear us.
panic(fmt.Sprintf("parseLine only accepts {*string, *int, *[]string} as arguments! %#v\n is not a pointer!", e))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lets not do a new line here ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Whoops, typo. :P

@cyphar

cyphar commented Mar 30, 2016

Copy link
Copy Markdown
Member Author

@dqminh Nits addressed. 😸

Comment thread libcontainer/user/user.go Outdated
}
return u.Name == userArg || strconv.Itoa(u.Uid) == userArg

if uid, err := strconv.Atoi(userArg); err == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think it'd be worthwhile or possible to do this test/conversion once instead of once per passwd entry like it's doing now, plus one more time outside this filter if we don't find the UID in the file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, I didn't consider the fact that it doesn't shortcircuit anymore. But since it's a constant for the entire function we can definitely refactor our essentially all calls to Atoi. I'm just not sure what to do about negative UIDs.

@tianon

tianon commented Mar 30, 2016

Copy link
Copy Markdown
Member

Other than the fact that we're hitting Atoi at least once per every line in both /etc/passwd and /etc/group unnecessarily, this LGTM (and I'm OK with the implementation if there isn't a clean way to switch that code) 👍

@crosbymichael

Copy link
Copy Markdown
Member

Thanks @cyphar !

Most shadow-related tools don't treat numeric ids as potential
usernames, so change our behaviour to match that. Previously, using an
explicit specification like 111:222 could result in the UID and GID not
being 111 and 222 respectively (which is confusing).

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar

cyphar commented Mar 30, 2016

Copy link
Copy Markdown
Member Author

@tianon I've addressed your concern about calling Atoi too many times per line. Merging.

cyphar added 2 commits March 31, 2016 07:44
Some of the code was quite confusing inside libcontainer/user, so
refactor and comment it so future maintainers can understand what's
going and what edge cases we have to deal with.

Signed-off-by: Aleksa Sarai <[email protected]>
@jordmoz

jordmoz commented Mar 30, 2016

Copy link
Copy Markdown

awesome, thanks all

@tianon

tianon commented Mar 30, 2016

Copy link
Copy Markdown
Member

🤘

runcom pushed a commit to runcom/docker that referenced this pull request Jun 8, 2016
… as uid numbers

Upstream reference: opencontainers/runc#708

Signed-off-by: Mrunal Patel <[email protected]>
Signed-off-by: Antonio Murdaca <[email protected]>
crawford pushed a commit to crawford/docker that referenced this pull request Jun 14, 2016
… as uid numbers

Upstream reference: opencontainers/runc#708

Signed-off-by: Mrunal Patel <[email protected]>
Signed-off-by: Antonio Murdaca <[email protected]>
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
config-solaris: Fix "VNIC`s" -> "VNIC's" typo
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.

6 participants