Skip to content

Commit a250961

Browse files
authored
Merge pull request #877 from jordemort/forward-x11
Allow forwarding X11 to VM
2 parents 78e5366 + 6c7969b commit a250961

File tree

9 files changed

+45
-5
lines changed

9 files changed

+45
-5
lines changed

cmd/limactl/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func copyAction(cmd *cobra.Command, args []string) error {
108108
// arguments such as ControlPath. This is preferred as we can multiplex
109109
// sessions without re-authenticating (MaxSessions permitting).
110110
for _, instDir := range instDirs {
111-
sshOpts, err = sshutil.SSHOpts(instDir, false, false)
111+
sshOpts, err = sshutil.SSHOpts(instDir, false, false, false, false)
112112
if err != nil {
113113
return err
114114
}

cmd/limactl/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
131131
return err
132132
}
133133

134-
sshOpts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent)
134+
sshOpts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent, *y.SSH.ForwardX11, *y.SSH.ForwardX11Trusted)
135135
if err != nil {
136136
return err
137137
}

cmd/limactl/show_ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func showSSHAction(cmd *cobra.Command, args []string) error {
8787
if err != nil {
8888
return err
8989
}
90-
opts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent)
90+
opts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent, *y.SSH.ForwardX11, *y.SSH.ForwardX11Trusted)
9191
if err != nil {
9292
return err
9393
}

examples/default.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ ssh:
106106
# Forward ssh agent into the instance.
107107
# 🟢 Builtin default: false
108108
forwardAgent: null
109+
# Forward X11 into the instance
110+
# 🟢 Builtin default: false
111+
forwardX11: null
112+
# Trust forwarded X11 clients
113+
# 🟢 Builtin default: false
114+
forwardX11Trusted: null
109115

110116
# ===================================================================== #
111117
# ADVANCED CONFIGURATION

pkg/hostagent/hostagent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
120120
return nil, err
121121
}
122122

123-
sshOpts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent)
123+
sshOpts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent, *y.SSH.ForwardX11, *y.SSH.ForwardX11Trusted)
124124
if err != nil {
125125
return nil, err
126126
}

pkg/limayaml/defaults.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
206206
y.SSH.ForwardAgent = pointer.Bool(false)
207207
}
208208

209+
if y.SSH.ForwardX11 == nil {
210+
y.SSH.ForwardX11 = d.SSH.ForwardX11
211+
}
212+
if o.SSH.ForwardX11 != nil {
213+
y.SSH.ForwardX11 = o.SSH.ForwardX11
214+
}
215+
if y.SSH.ForwardX11 == nil {
216+
y.SSH.ForwardX11 = pointer.Bool(false)
217+
}
218+
219+
if y.SSH.ForwardX11Trusted == nil {
220+
y.SSH.ForwardX11Trusted = d.SSH.ForwardX11Trusted
221+
}
222+
if o.SSH.ForwardX11Trusted != nil {
223+
y.SSH.ForwardX11Trusted = o.SSH.ForwardX11Trusted
224+
}
225+
if y.SSH.ForwardX11Trusted == nil {
226+
y.SSH.ForwardX11Trusted = pointer.Bool(false)
227+
}
228+
209229
hosts := make(map[string]string)
210230
// Values can be either names or IP addresses. Name values are canonicalized in the hostResolver.
211231
for k, v := range d.HostResolver.Hosts {

pkg/limayaml/defaults_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func TestFillDefault(t *testing.T) {
6565
LocalPort: pointer.Int(0),
6666
LoadDotSSHPubKeys: pointer.Bool(true),
6767
ForwardAgent: pointer.Bool(false),
68+
ForwardX11: pointer.Bool(false),
69+
ForwardX11Trusted: pointer.Bool(false),
6870
},
6971
Firmware: Firmware{
7072
LegacyBIOS: pointer.Bool(false),
@@ -230,6 +232,8 @@ func TestFillDefault(t *testing.T) {
230232
LocalPort: pointer.Int(888),
231233
LoadDotSSHPubKeys: pointer.Bool(false),
232234
ForwardAgent: pointer.Bool(true),
235+
ForwardX11: pointer.Bool(false),
236+
ForwardX11Trusted: pointer.Bool(false),
233237
},
234238
Firmware: Firmware{
235239
LegacyBIOS: pointer.Bool(true),
@@ -376,6 +380,8 @@ func TestFillDefault(t *testing.T) {
376380
LocalPort: pointer.Int(4433),
377381
LoadDotSSHPubKeys: pointer.Bool(true),
378382
ForwardAgent: pointer.Bool(true),
383+
ForwardX11: pointer.Bool(false),
384+
ForwardX11Trusted: pointer.Bool(false),
379385
},
380386
Firmware: Firmware{
381387
LegacyBIOS: pointer.Bool(true),

pkg/limayaml/limayaml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ type SSH struct {
9696
// LoadDotSSHPubKeys loads ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
9797
LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty" json:"loadDotSSHPubKeys,omitempty"` // default: true
9898
ForwardAgent *bool `yaml:"forwardAgent,omitempty" json:"forwardAgent,omitempty"` // default: false
99+
ForwardX11 *bool `yaml:"forwardX11,omitempty" json:"forwardX11,omitempty"` // default: false
100+
ForwardX11Trusted *bool `yaml:"forwardX11Trusted,omitempty" json:"forwardX11Trusted,omitempty"` // default: false
99101
}
100102

101103
type Firmware struct {

pkg/sshutil/sshutil.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func CommonOpts(useDotSSH bool) ([]string, error) {
201201
}
202202

203203
// SSHOpts adds the following options to CommonOptions: User, ControlMaster, ControlPath, ControlPersist
204-
func SSHOpts(instDir string, useDotSSH, forwardAgent bool) ([]string, error) {
204+
func SSHOpts(instDir string, useDotSSH, forwardAgent bool, forwardX11 bool, forwardX11Trusted bool) ([]string, error) {
205205
controlSock := filepath.Join(instDir, filenames.SSHSock)
206206
if len(controlSock) >= osutil.UnixPathMax {
207207
return nil, fmt.Errorf("socket path %q is too long: >= UNIX_PATH_MAX=%d", controlSock, osutil.UnixPathMax)
@@ -223,6 +223,12 @@ func SSHOpts(instDir string, useDotSSH, forwardAgent bool) ([]string, error) {
223223
if forwardAgent {
224224
opts = append(opts, "ForwardAgent=yes")
225225
}
226+
if forwardX11 {
227+
opts = append(opts, "ForwardX11=yes")
228+
}
229+
if forwardX11Trusted {
230+
opts = append(opts, "ForwardX11Trusted=yes")
231+
}
226232
return opts, nil
227233
}
228234

0 commit comments

Comments
 (0)