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

Set $container_uuid for systemd containers #13187

Closed
jfroy opened this issue Feb 9, 2022 · 8 comments · Fixed by #13622
Closed

Set $container_uuid for systemd containers #13187

jfroy opened this issue Feb 9, 2022 · 8 comments · Fixed by #13622
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue

Comments

@jfroy
Copy link

jfroy commented Feb 9, 2022

/kind feature

Description

Set $container_uuid for containers running in systemd mode. From https://systemd.io/CONTAINER_INTERFACE/:

systemd has special support for allowing container managers to initialize the UUID for /etc/machine-id to some manager supplied value. This is only enabled if /etc/machine-id is empty (i.e. not yet set) at boot time of the container. The container manager should set $container_uuid as environment variable for the container’s PID 1 to the container UUID.

The UUID could be derived from the container ID's first 128 bits, or by mixing the full container ID's 256 bits. Doing it that way does mean that the $container_uuid variable would be set fairly late in the container creation process, perhaps in Runtime::setupContainer.

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 9, 2022
@rhatdan
Copy link
Member

rhatdan commented Feb 9, 2022

I agree this is a good idea. I think you would just truncate the container id to 64 chars. I am still not sure what functionality this would add.

@jfroy
Copy link
Author

jfroy commented Feb 9, 2022

It's a small thing for sure. Having a machine-id tied to the lifetime of the container is semantically what you want. I am not sure to what extent the dbus / systemd machine-id is used by software, but on the flip side it exists and it should be as correct as can be.

@jfroy
Copy link
Author

jfroy commented Feb 9, 2022

I'm happy to send a PR, but I wanted to open an issue first to discuss wisdom (do we want this) and strategy (I am not very familiar with podman or libpod).

@rhatdan
Copy link
Member

rhatdan commented Feb 9, 2022

Open a PR, I think it makes sense.

jfroy added a commit to jfroy/podman that referenced this issue Feb 10, 2022
The `container_uuid` environment variable is read by systemd to set the
machine ID, per
https://systemd.io/CONTAINER_INTERFACE/#environment-variables. This
patch modifies `generateSpec` to apply this environment variable. The
"UUID" is the container ID's first 32 characters.

Fixed containers#13187
jfroy pushed a commit to jfroy/podman that referenced this issue Feb 11, 2022
The `container_uuid` environment variable is read by systemd to set the
machine ID, per
https://systemd.io/CONTAINER_INTERFACE/#environment-variables. This
patch modifies `generateSpec` to apply this environment variable. The
"UUID" is the container ID's first 32 characters.

Fixed containers#13187

Signed-off-by: Jean-Francois Roy <jfroy@devklog.net>
@jdoss
Copy link
Contributor

jdoss commented Feb 14, 2022

May I add a suggestion to this feature request?

The /run/host/container-uuid file may be used to pass the same information as the $container_uuid environment variable (see above). This file should be newline terminated.

This would be super helpful too. Since ENV vars can be overwritten, an immutable file that has a container UUID would be awesome to have available inside the container.

@jfroy
Copy link
Author

jfroy commented Feb 14, 2022

May I add a suggestion to this feature request?

The /run/host/container-uuid file may be used to pass the same information as the $container_uuid environment variable (see above). This file should be newline terminated.

This would be super helpful too. Since ENV vars can be overwritten, an immutable file that has a container UUID would be awesome to have available inside the container.

I considered adding this file as well, but looking at the systemd code, it is never read. I suppose it exists for other software. In any case, it seems like a good addition and I'll see if I can spend the time to add it.

@jdoss
Copy link
Contributor

jdoss commented Feb 14, 2022

Thank you @jfroy!

jfroy pushed a commit to jfroy/podman that referenced this issue Feb 16, 2022
This patch sets the `container_uuid` environment variable to the
container's fist 32 characters.

This patch also mounts a basic /run/host that contains container-manager
and container-uuid.

See https://systemd.io/CONTAINER_INTERFACE for the details.

Fixed containers#13187

Signed-off-by: Jean-Francois Roy <jfroy@devklog.net>
jfroy pushed a commit to jfroy/podman that referenced this issue Feb 17, 2022
This patch sets the `container_uuid` environment variable to the
container's fist 32 characters.

This patch also mounts a basic /run/host that contains container-manager
and container-uuid.

See https://systemd.io/CONTAINER_INTERFACE for the details.

Fixed containers#13187

Signed-off-by: Jean-Francois Roy <jfroy@devklog.net>
jfroy pushed a commit to jfroy/podman that referenced this issue Feb 17, 2022
This patch sets the `container_uuid` environment variable to the
container's fist 32 characters.

This patch also mounts a basic /run/host that contains container-manager
and container-uuid.

See https://systemd.io/CONTAINER_INTERFACE for the details.

Fixed containers#13187

Signed-off-by: Jean-Francois Roy <jfroy@devklog.net>
@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

rhatdan added a commit to rhatdan/podman that referenced this issue Mar 23, 2022
systemd expects the container_uuid environment variable be set
when it is running in a container.

Fixes: containers#13187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/podman that referenced this issue Mar 23, 2022
systemd expects the container_uuid environment variable be set
when it is running in a container.

Fixes: containers#13187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
keonchennl pushed a commit to gcalin/podman that referenced this issue Mar 24, 2022
systemd expects the container_uuid environment variable be set
when it is running in a container.

Fixes: containers#13187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
keonchennl pushed a commit to gcalin/podman that referenced this issue Mar 29, 2022
systemd expects the container_uuid environment variable be set
when it is running in a container.

Fixes: containers#13187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
gbraad pushed a commit to gbraad-redhat/podman that referenced this issue Jul 13, 2022
systemd expects the container_uuid environment variable be set
when it is running in a container.

Fixes: containers#13187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@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 Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue
Projects
None yet
3 participants