@@ -29,6 +29,7 @@ import NIO
2929import NIOFoundationCompat
3030import SocketForwarder
3131import Synchronization
32+ import SystemPackage
3233
3334import struct ContainerizationOCI. Mount
3435import struct ContainerizationOCI. Process
@@ -51,7 +52,7 @@ public actor SandboxService {
5152 private static let sshAuthSocketGuestPath = " /run/host-services/ssh-auth.sock "
5253 private static let sshAuthSocketEnvVar = " SSH_AUTH_SOCK "
5354
54- private static func hostSocketUrl ( config: ContainerConfiguration ) -> URL ? {
55+ private static func sshAuthSocketHostUrl ( config: ContainerConfiguration ) -> URL ? {
5556 if config. ssh, let sshSocket = Foundation . ProcessInfo. processInfo. environment [ Self . sshAuthSocketEnvVar] {
5657 return URL ( fileURLWithPath: sshSocket)
5758 }
@@ -793,11 +794,16 @@ public actor SandboxService {
793794 czConfig. sockets. append ( socketConfig)
794795 }
795796
796- if let socketUrl = Self . hostSocketUrl ( config: config) {
797+ if let socketUrl = Self . sshAuthSocketHostUrl ( config: config) {
798+ let socketPath = socketUrl. path ( percentEncoded: false )
799+ let attrs = try ? FileManager . default. attributesOfItem ( atPath: socketPath)
800+ let permissions = ( attrs ? [ . posixPermissions] as? NSNumber )
801+ . map { FilePermissions ( rawValue: mode_t ( $0. intValue) ) }
797802 let socketConfig = UnixSocketConfiguration (
798803 source: socketUrl,
799804 destination: URL ( fileURLWithPath: Self . sshAuthSocketGuestPath) ,
800- direction: . into
805+ permissions: permissions,
806+ direction: . into,
801807 )
802808 czConfig. sockets. append ( socketConfig)
803809 }
@@ -835,7 +841,7 @@ public actor SandboxService {
835841 czConfig. process. arguments = [ process. executable] + process. arguments
836842 czConfig. process. environmentVariables = process. environment
837843
838- if Self . hostSocketUrl ( config: config) != nil {
844+ if Self . sshAuthSocketHostUrl ( config: config) != nil {
839845 if !czConfig. process. environmentVariables. contains ( where: { $0. starts ( with: " \( Self . sshAuthSocketEnvVar) = " ) } ) {
840846 czConfig. process. environmentVariables. append ( " \( Self . sshAuthSocketEnvVar) = \( Self . sshAuthSocketGuestPath) " )
841847 }
@@ -877,7 +883,7 @@ public actor SandboxService {
877883 proc. arguments = [ config. executable] + config. arguments
878884 proc. environmentVariables = config. environment
879885
880- if Self . hostSocketUrl ( config: containerConfig) != nil {
886+ if Self . sshAuthSocketHostUrl ( config: containerConfig) != nil {
881887 if !proc. environmentVariables. contains ( where: { $0. starts ( with: " \( Self . sshAuthSocketEnvVar) = " ) } ) {
882888 proc. environmentVariables. append ( " \( Self . sshAuthSocketEnvVar) = \( Self . sshAuthSocketGuestPath) " )
883889 }
0 commit comments