#SSH agent forwarding

1 messages · Page 1 of 1 (latest)

normal nebula
#

Hi all, I'm trying to forward SSH socket to a container. I have searched in Discord and tried everything but it still doesn't work. I can forward SSH socket to dagger to pull private repo using this guide https://docs.dagger.io/710884/private-repositories. But I can not forward it to a container. Can any help me?

olive geode
#

👋 here's an example on how to accomplish this:

package main

import (
    "context"
    "os"

    "dagger.io/dagger"
)

func main() {
    ctx := context.Background()
    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
    if err != nil {
        panic(err)
    }
    defer client.Close()

    sockPath := os.Getenv("SSH_AUTH_SOCK")

    sshSock := client.Host().UnixSocket(sockPath)

    _, err = client.Pipeline("ssh").
        Container().
        From("alpine").
        WithExec([]string{"apk", "add", "openssh-client"}).
        WithUnixSocket(sockPath, sshSock).
        WithEnvVariable("SSH_AUTH_SOCK", sockPath).
        WithExec([]string{"ssh", "-o", "StrictHostKeyChecking=accept-new", "git@github.com"}).
        ExitCode(ctx)
    if err != nil {
        panic(err)
    }
}
normal nebula
#

Thanks for your help @olive geode. Now I can forward SSH socket to the container.