Skip to content

feat: add support for X11 forwarding #7205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix comments
  • Loading branch information
kylecarbs committed Apr 21, 2023
commit fe62b40e51ebd12d3d40b81d543b9a061265530c
6 changes: 5 additions & 1 deletion agent/agentssh/x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool {
s.trackListener(listener, true)

go func() {
defer listener.Close()
defer s.trackListener(listener, false)
handledFirstConnection := false

Expand Down Expand Up @@ -120,11 +121,14 @@ func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string
xauthPath := filepath.Join(homeDir, ".Xauthority")

lock := flock.New(xauthPath)
defer lock.Close()
ok, err := lock.TryLockContext(ctx, 100*time.Millisecond)
if !ok {
return xerrors.Errorf("failed to lock Xauthority file: %w", err)
}
defer lock.Close()
if err != nil {
return xerrors.Errorf("failed to lock Xauthority file: %w", err)
}

// Open or create the Xauthority file
file, err := fs.OpenFile(xauthPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider flock-ing the file so we're the only one writing to it? Not sure if xauth respects that though.

How about multiple SSH connections with X11 forwarding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this works either actually... I suppose we should flock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a flock!

Expand Down