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

Run vtpm container as non-root #3060

Merged
merged 1 commit into from
Jun 22, 2024
Merged

Conversation

shjala
Copy link
Member

@shjala shjala commented Feb 23, 2023

This PR adjust the vtpm containers configurations to run it as non-root user.
Depends on #3986

I'm trying to make vtpm run with a non-root user, I have tried the USER configuration in docker file and also in the docker-compose file, but for some reason unknown to me it is not respected, and no matter what it gets executed as root user in run-time.

This is a hacky way to make it run as a non-root user and be functional.

any alternative solution?

@shjala shjala requested a review from deitch February 23, 2023 13:37
@shjala
Copy link
Member Author

shjala commented Feb 23, 2023

@rouming

@shjala shjala marked this pull request as draft February 23, 2023 14:47
pkg/vtpm/Dockerfile Outdated Show resolved Hide resolved
@eriknordmark
Copy link
Contributor

@shjala with apparmor in place, are you still pursuing this PR? If so we need to pull in @deitch to figure out the issues.

@shjala
Copy link
Member Author

shjala commented Jul 12, 2023

@eriknordmark yes I would like to have both DAC and MAC properly in place, I will try once more and then ask Avi if unsuccessful.

@github-actions github-actions bot requested review from eriknordmark and rouming June 11, 2024 12:32
@shjala shjala force-pushed the vtpm-no-root branch 6 times, most recently from 92a250b to 2e1c712 Compare June 18, 2024 12:58
@shjala shjala changed the title [WIP] Make vtpm run as a non-root user Make vtpm run as a non-root user Jun 18, 2024
@shjala shjala marked this pull request as ready for review June 18, 2024 13:00
@shjala shjala changed the title Make vtpm run as a non-root user Run vtpm container as non-root Jun 18, 2024
pkg/vtpm/Dockerfile Outdated Show resolved Hide resolved
Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
@@ -1,6 +1,8 @@
image: eve-vtpm
org: lfedge
config:
uid: vtpm
Copy link
Member Author

Choose a reason for hiding this comment

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

@eriknordmark This is almost ready, it works fine I just need to do some more tests with systest make sure Azure IoT works too, there is just a tiny issue with the UID number, maybe @deitch can help. We let the adduser pick the UID and I would like to use the string "vtpm" in the build.yml. The UID in the system is 100 :

linuxkit-525400123456:~# cat /etc/passwd | grep vtpm
vtpm:x:100:101:vtpm:/nonexistent:/bin/false

but for some reason the uid in the vtpm config is 114 :

linuxkit-525400123456:~# cat /containers/services/vtpm/config.json
{
   "ociVersion": "1.0.2-dev",
   "process": {
       "user": {
           "uid": 114,
           "gid": 114
       },
       "args": [
           "/usr/bin/init.sh"
       ],
[...]   

and as a result :

linuxkit-525400123456:~# ps aux | grep vtpm_server
 1588 114       0:00 /usr/bin/vtpm_server
 3237 root      0:00 grep vtpm_server
linuxkit-525400123456:~# eve enter vtpm
linuxkit-525400123456:/$ ps
PID   USER     TIME  COMMAND
    1 114       0:00 {init.sh} /bin/sh /usr/bin/init.sh
    7 114       0:00 /usr/bin/vtpm_server
   20 114       0:00 sh -l
   27 114       0:00 ps

I don't know from where this number comes from (build container?), surely I can pass uid number to adduser and use the same number in build.yml to make the problem go away, but would be nice to use names instead of numbers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you pass a specific uid to adduser?

Copy link
Member Author

@shjala shjala Jun 21, 2024

Choose a reason for hiding this comment

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

surely I can pass uid number to adduser and use the same number in build.yml to make the problem go away, but would be nice to use names instead of numbers.

yes I can.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

@shjala shjala Jun 21, 2024

Choose a reason for hiding this comment

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

vtpm is 14th container declared in rootfs.yml as result it should get uid 114 (100+14) which matches the run-time uid I see in the container.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

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

LGTM

@eriknordmark eriknordmark merged commit d235c79 into lf-edge:master Jun 22, 2024
47 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants