pkg/idtools: refactor to avoid string-splitting#41377
Merged
Merged
Conversation
Member
Author
thaJeztah
force-pushed
the
refactor_idtools
branch
from
August 20, 2020 10:14
3d2c213 to
68737ef
Compare
thaJeztah
commented
Aug 20, 2020
thaJeztah
force-pushed
the
refactor_idtools
branch
from
August 20, 2020 10:22
68737ef to
e4acd8d
Compare
The package used a lot of string-formatting, followed by string-splitting. This looked to originate from attempts to use templating to allow future extensibility (9a3ab03). Looking at the history of the package, only a single update was made to these templates, 5 years go, which makes it unlikely that more templating will be needed. This patch simplifies the handling of arguments to use `[]string` instead of a single `string` (and splitting to a `[]string`). This both simplifies the code somewhat, and prevents user/group-names containing spaces to be splitted (causing, e.g. `getent` to fail). Note that user/group-names containing spaces are invalid (or at least discouraged), there are situations where such names may be used, so we should avoid breaking on such names. Before this change, a user/group name with a space in its name would fail; dockerd --userns-remap="user:domain users" INFO[2020-08-19T10:26:59.288868661+02:00] Starting up Error during groupname lookup for "domain users": getent unable to find entry "domain" in group database With this change: # Add some possibly problematic usernames for testing # need to do this manually, as `adduser` / `useradd` won't accept these names echo 'user name:x:1002:1002::/home/one:/bin/false' >> /etc/passwd; \ echo 'user name:x:1002:' >> /etc/group; \ echo 'user name:1266401166:65536' >> /etc/subuid; \ echo 'user name:1266401153:65536' >> /etc/subgid; \ echo 'user$HOME:x:1003:1003::/home/one:/bin/false' >> /etc/passwd; \ echo 'user$HOME:x:1003:' >> /etc/group; \ echo 'user$HOME:1266401166:65536' >> /etc/subuid; \ echo 'user$HOME:1266401153:65536' >> /etc/subgid; \ echo 'user'"'"'name:x:1004:1004::/home/one:/bin/false' >> /etc/passwd; \ echo 'user'"'"'name:x:1004:' >> /etc/group; \ echo 'user'"'"'name:1266401166:65536' >> /etc/subuid; \ echo 'user'"'"'name:1266401153:65536' >> /etc/subgid; \ echo 'user"name:x:1005:1005::/home/one:/bin/false' >> /etc/passwd; \ echo 'user"name:x:1005:' >> /etc/group; \ echo 'user"name:1266401166:65536' >> /etc/subuid; \ echo 'user"name:1266401153:65536' >> /etc/subgid; # Start the daemon using those users dockerd --userns-remap="user name:user name" dockerd --userns-remap='user$HOME:user$HOME' dockerd --userns-remap="user'name":"user'name" dockerd --userns-remap='user"name':'user"name' Signed-off-by: Sebastiaan van Stijn <[email protected]>
thaJeztah
force-pushed
the
refactor_idtools
branch
from
August 20, 2020 10:24
e4acd8d to
ea9886c
Compare
cpuguy83
approved these changes
Aug 20, 2020
| // if no `getent` command on host, can't do anything else | ||
| if getentCmd == "" { | ||
| return nil, fmt.Errorf("") | ||
| return nil, fmt.Errorf("unable to find getent command") |
Member
Author
There was a problem hiding this comment.
LOL, yes, I guess it had to return "an error", but empty error string felt a bit too minimal 😹
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fixes #41372
The package used a lot of string-formatting, followed by string-splitting.
This looked to originate from attempts to use templating to allow future
extensibility (9a3ab03 / #12648).
Looking at the history of the package, only a single update was made to
these templates, 5 years go, which makes it unlikely that more templating
will be needed.
This patch simplifies the handling of arguments to use
[]stringinsteadof a single
string(and splitting to a[]string). This both simplifiesthe code somewhat, and prevents user/group-names containing spaces to be
splitted (causing, e.g.
getentto fail).Note that user/group-names containing spaces are invalid (or at least
discouraged), there are situations where such names may be used, so we
should avoid breaking on such names.
Before this change, a user/group name with a space in its name would fail;
With this change:
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)