attach: fix attach when cuid is too long

conmon creates a symlink to avoid using a too long UNIX path.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1641800

There is still one issue when the path length of the symlink has the
same length of the attach socket parent directory since conmon fails
to create the symlink, but that must be addressed in conmon first.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2018-10-23 11:20:01 +02:00
parent f6e7807fa5
commit f77d846536
No known key found for this signature in database
GPG key ID: E4730F97F60286ED

View file

@ -16,6 +16,10 @@ import (
"k8s.io/client-go/tools/remotecommand"
)
//#include <sys/un.h>
// extern int unix_path_length(){struct sockaddr_un addr; return sizeof(addr.sun_path) - 1;}
import "C"
/* Sync with stdpipe_t in conmon.c */
const (
AttachPipeStdin = 1
@ -81,11 +85,19 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
logrus.Warnf("Failed to write to control file to resize terminal: %v", err)
}
})
logrus.Debug("connecting to socket ", c.AttachSocketPath())
conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: c.AttachSocketPath(), Net: "unixpacket"})
socketPath := c.AttachSocketPath()
maxUnixLength := int(C.unix_path_length())
if maxUnixLength < len(socketPath) {
socketPath = socketPath[0:maxUnixLength]
}
logrus.Debug("connecting to socket ", socketPath)
conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: socketPath, Net: "unixpacket"})
if err != nil {
return errors.Wrapf(err, "failed to connect to container's attach socket: %v", c.AttachSocketPath())
return errors.Wrapf(err, "failed to connect to container's attach socket: %v", socketPath)
}
defer conn.Close()