moby--moby/pkg
Sebastiaan van Stijn ea9886cec4
pkg/idtools: refactor to avoid string-splitting
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 (9a3ab0358e).

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 name1002:1002::/home/one:/bin/false' >> /etc/passwd; \
    echo 'user name1002:' >> /etc/group; \
    echo 'user name:1266401166:65536' >> /etc/subuid; \
    echo 'user name:1266401153:65536' >> /etc/subgid; \
    echo 'user$HOME1003:1003::/home/one:/bin/false' >> /etc/passwd; \
    echo 'user$HOME1003:' >> /etc/group; \
    echo 'user$HOME:1266401166:65536' >> /etc/subuid; \
    echo 'user$HOME:1266401153:65536' >> /etc/subgid; \
    echo 'user'"'"'name1004:1004::/home/one:/bin/false' >> /etc/passwd; \
    echo 'user'"'"'name1004:' >> /etc/group; \
    echo 'user'"'"'name:1266401166:65536' >> /etc/subuid; \
    echo 'user'"'"'name:1266401153:65536' >> /etc/subgid; \
    echo 'user"name1005:1005::/home/one:/bin/false' >> /etc/passwd; \
    echo 'user"name1005:' >> /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 <github@gone.nl>
2020-08-20 12:24:38 +02:00
..
aaparser
archive Merge pull request #40941 from cpuguy83/down_with_the_func_init 2020-07-14 15:44:08 +02:00
authorization pkg/authorization: Fix test failures on macOS 2020-04-08 13:06:50 +03:00
broadcaster
capabilities
chrootarchive chrootarchive: fix "conversion from int to string yields a string of one rune" 2020-06-25 13:38:42 +02:00
containerfs pkg/containerfs: normalize comment formatting 2019-11-27 15:39:57 +01:00
devicemapper pkg/devicemapper ignore SA4000 false positive (staticcheck) 2019-09-18 12:57:52 +02:00
directory TestMoveToSubdir: use sort.Strings() (gosimple) 2019-09-18 12:55:45 +02:00
discovery bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
dmesg
filenotify TestPollerEvent: fix filemode (staticcheck) 2019-09-18 12:57:56 +02:00
fileutils bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
fsutils
homedir pkg/homedir: clarify Get() docs wrt static linking 2019-10-24 16:39:24 -07:00
idtools pkg/idtools: refactor to avoid string-splitting 2020-08-20 12:24:38 +02:00
ioutils bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
jsonmessage remove uses of deprecated pkg/term 2020-04-21 16:29:27 +02:00
locker
longpath
loopback
mount pkg/mount: make standalone golint happy 2020-04-02 11:32:27 -07:00
namesgenerator Fixed typo in inventor comments. 2020-04-07 09:03:56 -04:00
parsers pkg/parsers: remove uses of mattn/go-shellwords 2020-07-14 14:03:10 +02:00
pidfile
platform
plugingetter
plugins Replace errors.Cause() with errors.Is() / errors.As() 2020-04-29 00:28:41 +02:00
pools bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
progress pkg/progress: normalize comment formatting 2019-11-27 15:41:23 +01:00
pubsub
reexec bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
signal Merge pull request #40496 from thaJeztah/locally_scope_variable 2020-04-07 09:54:25 +09:00
stdcopy
streamformatter bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
stringid
symlink pkg/symlink: don't depend on pkg/system and pkg/longpath 2020-03-09 16:41:54 +01:00
sysinfo pkg/sysinfo: rm duplicates 2020-06-26 16:19:52 -07:00
system Add solaris support to lstat 2020-08-12 11:40:58 +02:00
tailfile bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
tarsum bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
term pkg/term: vendor moby/term and make pkg/term an alias 2020-04-21 16:29:19 +02:00
truncindex
urlutil
useragent
README.md

README.md

pkg/ is a collection of utility packages used by the Moby project without being specific to its internals.

Utility packages are kept separate from the moby core codebase to keep it as small and concise as possible. If some utilities grow larger and their APIs stabilize, they may be moved to their own repository under the Moby organization, to facilitate re-use by other projects. However that is not the priority.

The directory pkg is named after the same directory in the camlistore project. Since Brad is a core Go maintainer, we thought it made sense to copy his methods for organizing Go code :) Thanks Brad!

Because utility packages are small and neatly separated from the rest of the codebase, they are a good place to start for aspiring maintainers and contributors. Get in touch if you want to help maintain them!