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

Socket truncated with long user names using default $XDG_RUNTIME_DIR #8798

Closed
fool65c opened this issue Dec 21, 2020 · 20 comments · Fixed by #8933
Closed

Socket truncated with long user names using default $XDG_RUNTIME_DIR #8798

fool65c opened this issue Dec 21, 2020 · 20 comments · Fixed by #8933
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@fool65c
Copy link

fool65c commented Dec 21, 2020

Is this a BUG REPORT or FEATURE REQUEST?

/kind bug

Socket truncated with long user names using default $XDG_RUNTIME_DIR

Steps to reproduce the issue:

  1. have a long username such as 11111111

  2. run podman run -it ubuntu

Describe the results you received:
podman fails to attach to the running container

DEBU[0003] Received: 20102
INFO[0003] Got Conmon PID as 20092
DEBU[0003] Created container 7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e in OCI runtime
DEBU[0003] Attaching to container 7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e
DEBU[0003] connecting to socket /var/run/user/11111111/libpod/tmp/socket/7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e/a
DEBU[0003] ExitCode msg: "failed to connect to container's attach socket: /var/run/user/11111111/libpod/tmp/socket/7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e/a: dial unixpacket /var/run/user/11111111/libpod/tmp/socket/7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e/a: connect: no such file or directory"
Error: failed to connect to container's attach socket: /var/run/user/11111111/libpod/tmp/socket/7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e/a: dial unixpacket /var/run/user/11111111/libpod/tmp/socket/7e19533164c776b5965dfb17891efd6d2eda50059190d00e5e2765c60323d38e/a: connect: no such file or directory

Describe the results you expected:
user able to attach to the container

Additional information you deem important (e.g. issue happens only occasionally):

This appears to be because of a system limit addr.sun_path because the socket is truncated:
https://github.com/containers/podman/blob/master/libpod/oci_attach_linux.go#L187

Based on addr.sun_path here:

// extern int unix_path_length(){struct sockaddr_un addr; return sizeof(addr.sun_path) - 1;}

Is this a system setting we can change?

Also, will a truncated socket ever work after it was created? The File not found error is true, however a bit misleading because the real issue is the socket that was created exceeded system limits.

Output of podman version:

podman -v
podman version 2.2.1

Output of podman info --debug:

(paste your output here)

Package info (e.g. output of rpm -q podman or apt list podman):

apt list podman
Listing... Done
podman/unknown,now 2.2.1~4 amd64 [installed]

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes

Additional environment details (AWS, VirtualBox, physical, etc.):
Setting the XDG_RUNTIME_DIR to a shorter string solves the issue

echo $XDG_RUNTIME_DIR
/var/qt/user

DEBU[0000] Received: 19653
INFO[0000] Got Conmon PID as 19642
DEBU[0000] Created container 7ccae949dc82d7a88b6f1acdfdf9e7c9abbcc472583ee57e990da816c19252f6 in OCI runtime
DEBU[0000] Attaching to container 7ccae949dc82d7a88b6f1acdfdf9e7c9abbcc472583ee57e990da816c19252f6
DEBU[0000] connecting to socket /var/qt/user/libpod/tmp/socket/7ccae949dc82d7a88b6f1acdfdf9e7c9abbcc472583ee57e990da816c19252f6/attach
DEBU[0000] Starting container 7ccae949dc82d7a88b6f1acdfdf9e7c9abbcc472583ee57e990da816c19252f6 with command [bash]
DEBU[0000] Received a resize event: {Width:217 Height:45}
DEBU[0000] Started container 7ccae949dc82d7a88b6f1acdfdf9e7c9abbcc472583ee57e990da816c19252f6
DEBU[0000] Enabling signal proxying
root@7ccae949dc82:/#
@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 21, 2020
@rhatdan
Copy link
Member

rhatdan commented Dec 21, 2020

@giuseppe @mheon I thought we dealt with something like this before?

@mheon
Copy link
Member

mheon commented Dec 22, 2020

Can't locate the PR, but I know we have hit this before. I believe the fix was to truncate container ID to ensure maximum length restriction was satisfied?

@rhatdan rhatdan added the Good First Issue This issue would be a good issue for a first time contributor to undertake. label Dec 23, 2020
@faulesocke
Copy link

Having the same problem. This also happens with short usernames (5 chars) and my XDG_RUNTIME_DIR=/tmp/runtime-$USER. In my case the last character got stripped.

@faulesocke
Copy link

faulesocke commented Dec 27, 2020

I can also confirm that the socket was successfully created. So having longer paths isn't a problem. Instead of doing any kind of truncation logic I would suggest to simply chdir into the correct directory. Then the path becomes a fixed string ("attach").

@rhatdan
Copy link
Member

rhatdan commented Dec 28, 2020

Interested in opening a PR to do this?

@faulesocke
Copy link

Sorry, my go knowledge is practically nonexistent and it would certainly take multiple iterations for me to get this right and nice while someone else with knowledge of go and probably the codebase can do it in 2 minutes. Would it have been in some other language like C or Rust - I would have opened a PR in the first place without even commenting here.

@rhatdan
Copy link
Member

rhatdan commented Dec 29, 2020

No problem, hopefully someone from the community will pick this up. Most of Red Hat is supposed to be on PTO this week.

@stephankoelle
Copy link

stephankoelle commented Jan 4, 2021

Same issue here, uid is very long, socket name is over 108 chars, podman does not start.

@stephankoelle
Copy link

Changing XDG_RUNTIME_DIR does not help in our case, the data is there, but the path to the socket is not altered.

@mheon
Copy link
Member

mheon commented Jan 7, 2021

@haircommander Is this related to the Conmon change we were discussing yesterday?

@haircommander
Copy link
Collaborator

yes most likely!

@fool65c
Copy link
Author

fool65c commented Jan 8, 2021

I'm interested in taking a stab at this, is the preferred approach still changing the directory?

@rhatdan
Copy link
Member

rhatdan commented Jan 10, 2021

I believe so.
@haircommander WDYT?

@rhatdan
Copy link
Member

rhatdan commented Jan 10, 2021

@mheon is this something we need to fix before 3.0?

@mheon
Copy link
Member

mheon commented Jan 10, 2021 via email

@stephankoelle
Copy link

Is there an attack point for a work around? (beside running podman as root - short uid user)

@giuseppe
Copy link
Member

could you please try if #8933 solves the issue you are seeing?

giuseppe added a commit to giuseppe/libpod that referenced this issue Jan 12, 2021
instead of opening directly the UNIX socket path, grab a reference to
it through a O_PATH file descriptor and use the fixed size string
"/proc/self/fd/%d" to open the UNIX socket.  In this way it won't hit
the 108 chars length limit.

Closes: containers#8798

Signed-off-by: Giuseppe Scrivano <[email protected]>
@stephankoelle
Copy link

The fix in podman 3 works, the bug is gone with a freshly built podman and very long uid.

giuseppe added a commit to giuseppe/libpod that referenced this issue Mar 16, 2021
instead of opening directly the UNIX socket path, grab a reference to
it through a O_PATH file descriptor and use the fixed size string
"/proc/self/fd/%d" to open the UNIX socket.  In this way it won't hit
the 108 chars length limit.

Closes: containers#8798

Signed-off-by: Giuseppe Scrivano <[email protected]>
(cherry picked from commit fdbc278)
giuseppe added a commit to giuseppe/libpod that referenced this issue Mar 17, 2021
instead of opening directly the UNIX socket path, grab a reference to
it through a O_PATH file descriptor and use the fixed size string
"/proc/self/fd/%d" to open the UNIX socket.  In this way it won't hit
the 108 chars length limit.

Closes: containers#8798

Signed-off-by: Giuseppe Scrivano <[email protected]>
(cherry picked from commit fdbc278)
@thoniTUB
Copy link

Is this going to be fix for podman 2 since it comes with RHEL 8.3?

@mheon
Copy link
Member

mheon commented Apr 22, 2021

We discussed an async release for this, but it appeared too late in the release cycle to be worth it. RHEL 8.4 should be releasing soon with a fixed Podman.

@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 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants