Skip to content
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

add support for podman create/run --domainname #15200

Closed
wants to merge 1 commit into from

Conversation

cdoern
Copy link
Contributor

@cdoern cdoern commented Aug 4, 2022

domainname functions similarly to --hostname, it sets the value in /etc/hosts
to whatever you speficy in conjunction with --hostname. so if you pass
--hostname=foo --domainmame=baz.net, /etc/hosts will get the combined entry and /proc/sys/kernel/domainname will get baz.net via a sysctl.

resolves #15102

Signed-off-by: Charlie Doern [email protected]

Does this PR introduce a user-facing change?

introduce --domanname to podman create/run which allows users to set a domainname along with a hostname in their host files

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

I took a quick look at docker and this doe snot match it.
The domain name is added in /etc/hosts and setdomainname()? Looks like they jusy use a sysctl for that: https://github.com/moby/moby/blob/master/daemon/oci_utils.go#L8

Also you are ignoring the compat API value and it must be added to podman container inspect.

cmd/podman/containers/create.go Outdated Show resolved Hide resolved
pkg/specgen/generate/namespaces.go Outdated Show resolved Hide resolved
@giuseppe
Copy link
Member

giuseppe commented Aug 5, 2022

I think the problem is with the /proc/sys/kernel/domainname file that is always owned by root in the initial user namespace, so writing to it always fails from a rootless user namespace, even if the value is namespaced.

I am not sure how the patch to crun can address it, have you verified it really writes to /proc/sys/kernel/domainname and that you can read the value back from /proc/sys/kernel/domainname within the container?

The correct fix IMO is to address it in the OCI specs and make domainname explicit as the hostname is.

The only possible workaround I see is to convert a write to kernel.domainname to a setdomainname(2), something like:

diff --git a/src/libcrun/linux.c b/src/libcrun/linux.c
index 5a7531e..4cd39e2 100644
--- a/src/libcrun/linux.c
+++ b/src/libcrun/linux.c
@@ -3255,6 +3255,14 @@ libcrun_set_sysctl (libcrun_container_t *container, libcrun_error_t *err)
       if (UNLIKELY (ret < 0))
         return ret;
 
+      if (strcmp (name, "kernel/domainname") == 0)
+        {
+          ret = setdomainname (def->linux->sysctl->values[i], strlen (def->linux->sysctl->values[i]));
+          if (UNLIKELY (ret < 0))
+            return crun_make_error (err, errno, "setdomainname");
+          continue;
+        }
+

I am fine to such a workaround if it unblocks you, but I still suggest to 1) verify your patch really does what it is supposed to do 2) propose a fix for the OCI runtime specs.

Also no need to block with rootless if it is not currently supported. Just skip the test.

@cdoern
Copy link
Contributor Author

cdoern commented Aug 5, 2022

I agree with the OCI spec approach. I've been messing around with the crun hack all day and it doesn't seem to want to cooperate. I'll make a PR for the runtime spec on Monday.

@rhatdan
Copy link
Member

rhatdan commented Aug 6, 2022

Does this work with Docker? Perhaps only because docker daemon runs as root and running docker in rootless mode this would fail also?

@mheon
Copy link
Member

mheon commented Aug 6, 2022

Do we want to add the flag as root-only for now, and enable rootless support once the OCI spec PR merges and support actually lands in crun/runc?

@cdoern
Copy link
Contributor Author

cdoern commented Aug 6, 2022

Do we want to add the flag as root-only for now, and enable rootless support once the OCI spec PR merges and support actually lands in crun/runc?

That sgtm, I haven't pushed the new version with the sysctl. I'll finish that up on Monday then take care of the spec PR

@cdoern cdoern force-pushed the domainName branch 4 times, most recently from 3b6d21a to cb3104a Compare August 8, 2022 15:41
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2022
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 31, 2022
pkg/specgen/generate/namespaces.go Outdated Show resolved Hide resolved
docs/source/markdown/podman-create.1.md.in Outdated Show resolved Hide resolved
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 3, 2022
@cdoern
Copy link
Contributor Author

cdoern commented Sep 9, 2022

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2022
@openshift-merge-robot openshift-merge-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 9, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 11, 2022
@cdoern
Copy link
Contributor Author

cdoern commented Oct 11, 2022

@giuseppe @Luap99 @rhatdan PTAL, once my PR in runtime-tools gets merged in I think this is the proper structure.

@cdoern
Copy link
Contributor Author

cdoern commented Dec 19, 2022

@giuseppe @rhatdan PTAL

docs/source/markdown/options/domainname.md Outdated Show resolved Hide resolved
@@ -99,6 +99,19 @@ var _ = Describe("Podman run dns", func() {
Expect(session.OutputToString()).To(ContainSubstring("foobar"))
})

It("podman run domainname sets /etc/hosts and /proc/sys/kernel/domainname", func() {
Skip("Waiting for crun release > 1.6")
Copy link
Member

Choose a reason for hiding this comment

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

crun 1.6 was released some time ago. Where is the test failing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, let me un-comment that and see if this all works...

@cdoern
Copy link
Contributor Author

cdoern commented Dec 20, 2022

@giuseppe it seems /proc/sys/kernel/domainname does not get set but /etc/hosts does. Does this mean the domainname is working or not? not sure if the /proc file is meant to be set

@cdoern cdoern force-pushed the domainName branch 5 times, most recently from 51427a9 to bac6343 Compare December 21, 2022 16:10
@giuseppe
Copy link
Member

@giuseppe it seems /proc/sys/kernel/domainname does not get set but /etc/hosts does. Does this mean the domainname is working or not? not sure if the /proc file is meant to be set

it sounds like working from Podman but it doesn't look like working from the OCI runtime. To what test are you referring?

@cdoern
Copy link
Contributor Author

cdoern commented Dec 21, 2022

@giuseppe it seems /proc/sys/kernel/domainname does not get set but /etc/hosts does. Does this mean the domainname is working or not? not sure if the /proc file is meant to be set

it sounds like working from Podman but it doesn't look like working from the OCI runtime. To what test are you referring?

@giuseppe I was checking /proc/sys/kernel/domainname in a test but I am not sure if that file is meant to contain the --domainname. running commands like hostname -A work appropriately though... so i am not sure if crun is doing it right or not.

@rhatdan
Copy link
Member

rhatdan commented Dec 21, 2022

# domainname dan
sh-5.2# domainname
dan
sh-5.2# cat /proc/sys/kernel/domainname 
dan

If I run a container I will also see domainname dan within it, which seems wrong, but I can change it

sh-5.2# podman run -ti --privileged fedora sh
# dnf -y install /usr/bin/domainname
...
Installed:
  hostname-3.23-7.fc37.x86_64                                                                                                                                                        

Complete!
# domainname
dan
# domainname walsh
# domainname
walsh
# exit
sh-5.2# domainname
dan

@rhatdan
Copy link
Member

rhatdan commented Dec 21, 2022

I would expect the /proc/sys/kernel/domainname to show the containers domainname, if this is set.

@cdoern
Copy link
Contributor Author

cdoern commented Dec 22, 2022

I would expect the /proc/sys/kernel/domainname to show the containers domainname, if this is set.

ok, then I think this is an issue with crun. Since /etc/hosts seems to be updated and the spec does indeed have the proper domainname entity set, something must be wrong..

though, in crun all of the domainname tests pass. @giuseppe WDYT?

@giuseppe
Copy link
Member

is the correct crun installed?

If I pull locally your changes (testing commit c91508b9c18a3f193c7ab28beaaad85573747e3d), I see it works:

$ sudo bin/podman run --rm --domainname as-root fedora cat /proc/sys/kernel/domainname
as-root
$ bin/podman run --rm --domainname and-also-rootless fedora cat /proc/sys/kernel/domainname
and-also-rootless

Instead of installing an additional package, let's change the test to print directly /proc/sys/kernel/domainname

@cdoern
Copy link
Contributor Author

cdoern commented Dec 22, 2022

@giuseppe could ci have an old crun version?

@giuseppe
Copy link
Member

yes I think that is the issue. It is using crun-1.6-2.fc36-x86_64 while the support was added in crun 1.7.

Let's not block on the CI, just skip the test for now

domainname functions similarly to --hostname, it sets the value in /etc/hosts
to whatever you speficy in conjunction with --hostname. so if you pass
--hostname=foo --domainmame=baz.net, /etc/hosts will get the combined entry and /proc/sys/kernel/domainname will get
baz.net
resolves containers#15102

Signed-off-by: Charlie Doern <[email protected]>
@vrothberg
Copy link
Member

@cdoern I think rebasing and unskipping the test is possible now. Do you have time to tackle it?

@Luap99
Copy link
Member

Luap99 commented Jan 17, 2023

@cdoern I think rebasing and unskipping the test is possible now. Do you have time to tackle it?

The VM image update is still blocked, so there were no updates since November so we are still on crun 1.6.2 at the moment AFAIK.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 22, 2023
@openshift-merge-robot
Copy link
Collaborator

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@vrothberg
Copy link
Member

Friendly ping. @cdoern I think we are good to give it another try.

@vrothberg vrothberg closed this May 3, 2023
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to set domainname via REST Endpoint
8 participants