Skip to content

Commit 8960de7

Browse files
committed
improvement(hostagent): link ssh agent socket to pre-determined location
This PR resolves issue rancher-sandbox/rancher-desktop#3042 and relates to the comment https://github.com/rancher-sandbox/rancher-desktop/issues/3488\#issuecomment-1406884439. This change ensures the ssh agent socket can be mounted into containers without having to determine the location first. The location will be in a static location /run/host-services/ssh-auth.sock. This is the same location as Docker Desktop uses. Signed-off-by: Ryan Currah <[email protected]>
1 parent 87ddded commit 8960de7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

examples/default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ ssh:
121121
# 🟢 Builtin default: true
122122
loadDotSSHPubKeys: null
123123
# Forward ssh agent into the instance.
124+
# The ssh agent socket can be mounted in a container at the path `/run/host-services/ssh-auth.sock`.
125+
# Set the environment variable `SSH_AUTH_SOCK` value to the path above.
126+
# The socket is accessible by the non-root user inside the Lima instance.
124127
# 🟢 Builtin default: false
125128
forwardAgent: null
126129
# Forward X11 into the instance

pkg/hostagent/hostagent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,19 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
317317
if err := a.waitForRequirements(ctx, "essential", a.essentialRequirements()); err != nil {
318318
mErr = multierror.Append(mErr, err)
319319
}
320+
if *a.y.SSH.ForwardAgent {
321+
faScript := `#!/bin/bash
322+
set -eux -o pipefail
323+
sudo mkdir -p -m 700 /run/host-services
324+
sudo ln -sf "${SSH_AUTH_SOCK}" /run/host-services/ssh-auth.sock
325+
sudo chown -R "${USER}" /run/host-services`
326+
faDesc := "linking ssh auth socket to static location /run/host-services/ssh-auth.sock"
327+
stdout, stderr, err := ssh.ExecuteScript("127.0.0.1", a.sshLocalPort, a.sshConfig, faScript, faDesc)
328+
logrus.Debugf("stdout=%q, stderr=%q, err=%v", stdout, stderr, err)
329+
if err != nil {
330+
mErr = multierror.Append(mErr, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
331+
}
332+
}
320333
if *a.y.MountType == limayaml.REVSSHFS {
321334
mounts, err := a.setupMounts(ctx)
322335
if err != nil {

0 commit comments

Comments
 (0)