-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support Rootless Docker #1727
Support Rootless Docker #1727
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,11 @@ fix_mount() { | |
# https://systemd.io/CONTAINER_INTERFACE/ | ||
# however, we need other things from `docker run --privileged` ... | ||
# and this flag also happens to make /sys rw, amongst other things | ||
# | ||
# EACCES on rootless is negligible. | ||
set +o errexit | ||
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. you already detect if we're in rootless or not below, instead detect that early on and save it, and switch on it here? |
||
mount -o remount,ro /sys | ||
set -o errexit | ||
|
||
echo 'INFO: making mounts shared' >&2 | ||
# for mount propagation | ||
|
@@ -232,6 +236,13 @@ enable_network_magic(){ | |
fi | ||
} | ||
|
||
select_containerd_config_toml() { | ||
if ! egrep -q "0[[:space:]]+0[[:space:]]+4294967295" /proc/1/uid_map; then | ||
echo "INFO: Detected rootless provider. Overriding /etc/containerd/config.toml with /etc/containerd/config-rootless.toml" >&2 | ||
cp -f /etc/containerd/config-rootless.toml /etc/containerd/config.toml | ||
fi | ||
} | ||
|
||
# run pre-init fixups | ||
fix_kmsg | ||
fix_mount | ||
|
@@ -242,6 +253,7 @@ fix_product_uuid | |
configure_proxy | ||
select_iptables | ||
enable_network_magic | ||
select_containerd_config_toml | ||
|
||
# we want the command (expected to be systemd) to be PID1, so exec to it | ||
exec "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# | ||
# A wrapper script to remove .linux.resources.devices, which are meaningless in userns. | ||
# Needs jq. | ||
# | ||
# Workaround until we get proper fixes in containerd and runc | ||
set -eu -o pipefail | ||
RUNTIME="runc" | ||
|
||
if egrep -q "0[[:space:]]+0[[:space:]]+4294967295" /proc/self/uid_map; then | ||
# we are not in userns, no need to patch the config | ||
exec $RUNTIME "$@" | ||
exit $? | ||
fi | ||
|
||
bundle="." | ||
bundle_flag="" | ||
# FIXME: support `--bundle=STRING` as well | ||
for f in $@; do | ||
if [[ -n $bundle_flag ]]; then | ||
bundle=$f | ||
break | ||
else | ||
case $f in | ||
-b | --bundle) | ||
bundle_flag=$f | ||
;; | ||
esac | ||
fi | ||
done | ||
|
||
if [ -f $bundle/config.json ]; then | ||
q="del(.linux.resources.devices) | del(.linux.devices)" | ||
tmp=$(mktemp -d ociwrapper.XXXXXXXX) | ||
jq "$q" <$bundle/config.json >$tmp/config.json | ||
mv $tmp/config.json $bundle/config.json | ||
rm -rf $tmp | ||
fi | ||
|
||
exec $RUNTIME "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,8 @@ func (c *buildContext) buildImage(dir string) error { | |
return errors.New("failed to find imported pause image") | ||
} | ||
containerdConfig, err := getContainerdConfig(containerdConfigTemplateData{ | ||
SandboxImage: pauseImage, | ||
SandboxImage: pauseImage, | ||
DefaultRuntimeName: "runc", | ||
}) | ||
if err != nil { | ||
return err | ||
|
@@ -196,6 +197,18 @@ func (c *buildContext) buildImage(dir string) error { | |
if err := createFile(cmder, containerdConfigPath, containerdConfig); err != nil { | ||
return err | ||
} | ||
containerdRootlessConfig, err := getContainerdConfig(containerdConfigTemplateData{ | ||
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. we should be able to do this without building a special node-image. 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. How can we edit TOML in the entrypoint? Is sed robust enough? 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. it should be, since the entrypoint is tied to the config, and at this point user patches have not yet been applied, so we know what the config looks like. we can sed on |
||
SandboxImage: pauseImage, | ||
DefaultRuntimeName: "ociwrapper", | ||
RestrictOOMScoreAdj: true, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
const containerdRootlessConfigPath = "/etc/containerd/config-rootless.toml" | ||
if err := createFile(cmder, containerdRootlessConfigPath, containerdRootlessConfig); err != nil { | ||
return err | ||
} | ||
|
||
// Save the image changes to a new image | ||
cmd := exec.Command( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,8 @@ func (p *Provider) Provision(status *cli.Status, cfg *config.Cluster) (err error | |
return err | ||
} | ||
|
||
// kind doesn't work with podman rootless, surface an error | ||
if os.Geteuid() != 0 { | ||
p.logger.Errorf("podman provider does not work properly in rootless mode") | ||
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. I don't think we should stop failing until this works, actually, this was previous state but it was confusing for users |
||
os.Exit(1) | ||
p.logger.Warn("support for rootless mode is experimental, some features may not work") | ||
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. the PR body suggests that it doesn't work, if that's the case then this new message seems misleading. |
||
} | ||
|
||
// TODO: validate cfg | ||
|
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.
how big is this?
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.
about 1MB including deps
https://packages.ubuntu.com/focal/jq
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.
thanks, paying 1MB for rootless seems worthwhile :-)