Skip to content

Commit 6ae40d3

Browse files
authored
Merge pull request #1335 from ryancurrah/create-link-to-ssh-agent-socket-in-vm
improvement(hostagent): link ssh agent socket to predetermined location
2 parents f7e7add + 8960de7 commit 6ae40d3

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
@@ -343,6 +343,19 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
343343
if err := a.waitForRequirements(ctx, "essential", a.essentialRequirements()); err != nil {
344344
mErr = multierror.Append(mErr, err)
345345
}
346+
if *a.y.SSH.ForwardAgent {
347+
faScript := `#!/bin/bash
348+
set -eux -o pipefail
349+
sudo mkdir -p -m 700 /run/host-services
350+
sudo ln -sf "${SSH_AUTH_SOCK}" /run/host-services/ssh-auth.sock
351+
sudo chown -R "${USER}" /run/host-services`
352+
faDesc := "linking ssh auth socket to static location /run/host-services/ssh-auth.sock"
353+
stdout, stderr, err := ssh.ExecuteScript("127.0.0.1", a.sshLocalPort, a.sshConfig, faScript, faDesc)
354+
logrus.Debugf("stdout=%q, stderr=%q, err=%v", stdout, stderr, err)
355+
if err != nil {
356+
mErr = multierror.Append(mErr, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
357+
}
358+
}
346359
if *a.y.MountType == limayaml.REVSSHFS {
347360
mounts, err := a.setupMounts(ctx)
348361
if err != nil {

0 commit comments

Comments
 (0)