privileged: ${VAR:-false} runs the container with --privileged

Open Beginner friendly
#1,652 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli, devops, security

Research direction

Start in podman_compose.py at container_to_args and inspect how the privileged value is converted into command-line arguments. Run the provided Compose-file reproduction against up and run; the fix is done when false-like interpolated values omit --privileged, while true-like values still enable it.

Written by the indexing model from the issue text.

Description

Hi! privileged: ${VAR:-false} ends up running the container with --privileged when VAR isn't set.

Interpolation turns the value into the string "false", and container_to_args only checks truthiness:

https://github.com/containers/podman-compose/blob/8063daedbddaab033002f018b3226c7b84a36258/podman_compose.py#L1590-L1595

So any non-empty string, including "false" and "0", adds --privileged. It goes through the same builder for up and run. A plain YAML privileged: false works fine since that's a real bool.

To reproduce with podman-compose 1.6.0:

services:
  app:
    image: docker.io/library/alpine:3.20
    command: ["true"]
    privileged: ${PRIV:-false}
  ctl_bool:
    image: docker.io/library/alpine:3.20
    command: ["true"]
    privileged: false

With a stub podman that logs its arguments, podman-compose up -d and podman-compose run --rm app gave:

PRIV unset   app: --privileged   ctl_bool: no flag   run app: --privileged
PRIV=        app: --privileged   ctl_bool: no flag   run app: --privileged
PRIV=false   app: --privileged   ctl_bool: no flag   run app: --privileged
PRIV=true    app: --privileged   ctl_bool: no flag   run app: --privileged

I'd expect the first three to leave the flag off. Same code on main at 8063daed.

It's a security-relevant default since the container gets full privileges the user meant to turn off. The fix can reuse the existing try_parse_bool helper:

--- a/podman_compose.py
+++ b/podman_compose.py
@@ -1589,7 +1589,7 @@ async def container_to_args(
 
     if cnt.get("tty"):
         podman_args.append("--tty")
-    if cnt.get("privileged"):
+    if try_parse_bool(cnt.get("privileged")) is True:
         podman_args.append("--privileged")
     if cnt.get("pid"):
         podman_args.extend(["--pid", cnt["pid"]])

Happy to open a PR with a test if that helps!

Dominant language
Python
Stars
6.3k
Forks
647
Avg merge
3d 8h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from containers/podman-compose

All issues in containers/podman-compose

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.