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

podman support #407

Closed
mmguero opened this issue Feb 8, 2024 · 8 comments
Closed

podman support #407

mmguero opened this issue Feb 8, 2024 · 8 comments
Assignees
Labels
docker Relating to docker and docker-compose as used by Malcolm enhancement New feature or request
Milestone

Comments

@mmguero
Copy link
Collaborator

mmguero commented Feb 8, 2024

I don't think there's any reason Malcolm couldn't run fine with rootless podman, particularly using the --userns keep-id:uid=xxxx,gid=yyyy option to map the current host user to a specific ID inside the container.

Just need to work through it and resolve issues that crop up.

@mmguero mmguero added docker Relating to docker and docker-compose as used by Malcolm enhancement New feature or request labels Feb 8, 2024
@mmguero mmguero added this to the z.staging milestone Feb 8, 2024
@mmguero mmguero self-assigned this Feb 8, 2024
@mmguero mmguero added this to Malcolm Feb 8, 2024
@mmguero mmguero moved this to Todo (develop) in Malcolm Feb 8, 2024
@mmguero mmguero modified the milestones: z.staging, v24.04.0 Feb 15, 2024
@mmguero mmguero removed their assignment Feb 15, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Mar 4, 2024

(copy/paste from a teams conversation, apologize for the bad formatting)

one bit of info I should mention about the podman one: all of the malcolm docker images go through the same entrypoint, this script. the purpose of this script is, for the most part, to set up the uid/gid stuff inside the container to match what the user has specified in the config environment variables. Some containers have this environment variable PUSER_PRIV_DROP set to true (like this) to immediately drop privileges in that script, while others need to be root for just a bit longer and then drop privileges inside the container either inside a supervisord process or some other way in the startup code of that container. But the important part is that every single one of the containers actual runtime processes drops to the correct non-root user upon startup. This ensures, among other things, that all files created get created from the host (the machine running Docker) point of view with the correct file ownership: if user manny is running Docker and that UID is 1000, then all processes run under and all files are created with ownership 1000; if user seth is running it and his UID is 1001, all processes run under 1001 and ownership of files belongs to that UID.

so the way docker and podman work is just a bit different: for docker, the PUID and PGID variables should be set to whatever your users' are, e.g., 1000 or whatever, and they'll get set appropriately inside the container. however, for rootless podman, it works a little bit different: by default, uid/gid 0 and 0 (or, in other words, root) map to the UID/GID of the user running podman.

So for like 90% of the containers, this can just be solved by setting the variables in process.env to 0 and 0 and it will pretty much work.

however, there are some containers that don't like this: for example, the opensearch container refuses to start if the UID/GID is set to zero, saying it's not safe to run as root.

however, podman has a userns mode capability with keep-id (here are some examples) that I think will take care of the problem. in other words, I think the solution is to set process.env to be the same UID and GID as we would with docker, but use the keep-id mode to map it so 1000 inside the container is the same as 1000 outside the container (or whatever the UID is, it would need to work for whatever is set in that .env file). here is some other reading on userns modes.

so one of the tricks will be how to set the --userns keep-id (or whatever the exact flag looks like) into the environment running podman via podman-compose or docker compose (i think both podman-compose and docker compose should be supported if possible, as both are valid options for running podman against docker-compose files). here are some things to look at:

Basically, it needs to work correctly for whatever the user's UID and GID from process.env are, and it needs to be able to do so ideally without modifying the docker-compose.yml file directly (ie., just pulling it from process.env) and it needs to not break existing docker-supported functionality

@mmguero mmguero moved this from Todo (develop) to In Progress in Malcolm Mar 6, 2024
@mmguero mmguero modified the milestones: v24.03.1, v24.04.0, z.staging Mar 19, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Mar 25, 2024

Podman 5 is out which seems to have a bunch of improvements, I'd recommend we use that as a baseline (and, if there's anything it makes easier, making that a minimum requirement).

@mmguero mmguero modified the milestones: z.staging, v24.05.0 Mar 27, 2024
@mmguero mmguero modified the milestones: v24.05.0, z.staging Apr 23, 2024
@mmguero mmguero moved this from In Progress to Todo (investigate) in Malcolm Jul 2, 2024
@mmguero mmguero modified the milestones: z.staging, v24.09.0 Aug 20, 2024
@mmguero mmguero self-assigned this Aug 28, 2024
@mmguero mmguero moved this from Todo (investigate) to In Progress in Malcolm Aug 28, 2024
@mmguero mmguero moved this from In Progress to Todo in Malcolm Aug 28, 2024
@mmguero mmguero moved this from Todo (investigate) to In Progress in Malcolm Aug 29, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Aug 29, 2024

I've started playing with this, and honestly the issues are very few:

  • Running podman rootless, without any of the UID mapping stuff from the previous comment, UID 0 maps to the host user's UID. So for the most part, setting UID and GID to 0 during configuration "just works."
  • the local driver for logging is fine for Docker but not for podman. Locally I changed it to journald but we need to determine what the right thing to do is, and how to handle it (I'd rather not have to maintain two different compose .yml files, although we may have to).
  • The biggest concern seems to be opensearch, because it simply will not let you run as root (I've even tried taking that out of the entrypoint, but there are other safeguards on it elsewhere. This means that even though it's not really running as root, inside of podman, it thinks it is. I think we're going to have to do some of the userns mapping mentioned above for this one.
    • In the meantime, I've pointed it at an external elasticsearch instance and things come up correctly

mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Aug 29, 2024
… specifying container runtime (docker vs. podman) for idaholab#407
@mmguero
Copy link
Collaborator Author

mmguero commented Aug 29, 2024

Here's a thread that's maybe working for the user namespace mapping stuff:

  • I've added a way to specify the container runtime (e.g., podman) via a -r/--runtime option or a MALCOLM_CONTAINER_RUNTIME environment variable (see mmguero-dev/Malcolm@d64970a).
  • This means that the scripts will execute podman compose instead of docker compose, and, as the default warning message says when executing podman compose says, "Executing external compose provider "/usr/local/bin/docker-compose". This is not a bad thing, because...
  • Adding userns_mode: keep-id to the services in the compose .yml file seems to now do the mapping correctly.

Need to 100% confirm this, but it looks good. Also need to make sure that this is ignored when in regular docker-compose mode. If not, we can add it on the fly, but that's less fun.

mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Sep 11, 2024

See containers/podman#23347 for another issue. Trying to run via podman compose with userns_mode: keep-id. Only the VOLUME-declared paths have 999 ownership.

mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
@mmguero mmguero moved this from In Progress to Testing in Malcolm Sep 11, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Sep 11, 2024

I've got this in a pretty-much-working state, just going through and hand-checking the logs and whatnot to make sure everything is the way it should be. I still need to test live-capture as well.

mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 11, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Sep 11, 2024

As expected live capture is failing, but everything else is working correctly as far as I can tell.

@mmguero mmguero moved this from Testing to In Progress in Malcolm Sep 11, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 12, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 12, 2024
@mmguero
Copy link
Collaborator Author

mmguero commented Sep 12, 2024

I have determined that it's impossible to do the live network capture using rootless podman (probably rootless docker as well) because of the user namespacing. Even with tricks like setcap and --cap-add, etc., it still results in Operation Not Permitted.

I've added this to the documentation in a few of the places we mention podman:

It should be noted that if rootless Podman is used, Malcolm itself cannot perform traffic capture on local network interfaces, although it can accept network traffic metadata forwarded from a a network sensor appliance.

@mmguero mmguero moved this from In Progress to Testing in Malcolm Sep 12, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 12, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 12, 2024
mmguero added a commit to mmguero-dev/Malcolm that referenced this issue Sep 12, 2024
@mmguero mmguero moved this from Testing to Done in Malcolm Sep 12, 2024
@mmguero mmguero closed this as completed Sep 12, 2024
This was referenced Sep 18, 2024
@mmguero mmguero moved this from Done to Released in Malcolm Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Relating to docker and docker-compose as used by Malcolm enhancement New feature or request
Projects
Status: Released
Development

No branches or pull requests

2 participants