Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,14 @@ On Windows and Linux, use `--config FILE` to select another file. Command-line v
- When `agent.upstream` is empty, `UPSTREAM_SSH_AUTH_SOCK` takes precedence over `SSH_AUTH_SOCK`. If neither is set, the GUI uses the native OpenSSH agent endpoint: `\\.\pipe\openssh-ssh-agent` on Windows and `~/.ssh/ssh-agent.sock` on macOS and Linux.
- To keep the upstream endpoint tied to a changing environment variable, set `agent.upstream = "env:SSH_AUTH_SOCK"`, or choose Environment variable in GUI Settings and enter its name. The GUI resolves this reference at startup and when Settings are applied, while saving the `env:NAME` reference in the config file. The variable must be set and non-empty.
- Environment variables in ordinary paths and a leading `~` are expanded using the GUI process environment.
- `[agent].allow_unbound_signing_on_bind_failure` defaults to `false`; GUI Settings omits it from the configuration file unless it is enabled.
- `[history].path` selects the selection-history database when set. If omitted or empty, the GUI uses `history.sqlite` in the application data folder. Relative paths are resolved from that folder. GUI Settings leaves the field blank and shows the resolved default path as its placeholder. It saves `history.path` only when you enter or choose a path.
- `[history].enabled` controls whether the GUI records and shows selection history. `[history].remember_selection` controls whether it remembers the last selected key for each verified target host. Both default to `true`, can be changed in GUI Settings, and are written to the config only when set to `false`. When both are `false`, the GUI does not create or open the SQLite database.
- If the configured Listen endpoint is active or blocked by a non-socket file, the GUI starts with the proxy `Not configured`. A stale socket owned by the current user is replaced when KeySelect confirms that it is no longer listening.

The configuration loader rejects unknown keys. Logging is off by default. Set `log.level` to enable it and optionally set `log.file` to append logs to a file. When `log.file` is empty, logs go to standard error.
The configuration loader rejects unknown keys. Logging is off by default. Set `log.level` to enable it and optionally set `log.file` to choose a log destination. When `log.file` is empty, the GUI uses `ssh-keyselect.log` in its application data directory. Settings shows this default as a placeholder and leaves it out of the configuration file.

The key selection timeout defaults to 120 seconds. In GUI Settings, set `agent.selection_timeout`. For `ssh-keyselect ssh`, pass `--selection-timeout SECONDS`.
The key selection timeout defaults to 120 seconds. GUI Settings shows `120` as a placeholder; leave the field blank to use the default and omit `agent.selection_timeout` from the configuration file. Enter a value from 1 to 86,399 to override it. For `ssh-keyselect ssh`, pass `--selection-timeout SECONDS`.

If, after a timeout, the SSH client prints the errors below and the server's `/var/log/secure` contains `penalty: exceeded LoginGraceTime`, set the Key selection Timeout to match that server's `LoginGraceTime` value in seconds.

Expand All @@ -400,12 +401,11 @@ listen = 'C:\Users\USERNAME\.ssh\ssh-keyselect-agent.sock'

upstream_mode = "auto"
listen_mode = "cygwin"
selection_timeout = 120 # seconds (1 to 86399)
# selection_timeout = 120 # seconds (1 to 86399)
# Allows signing without upstream destination binding after an explicit refusal.
allow_unbound_signing_on_bind_failure = false
# allow_unbound_signing_on_bind_failure = true

[log]
file = ""
level = "off"

[history]
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssh-keyselect-gui/endpoint_display_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func guiFormatPathInput(path string) string { return path }

func guiFilePathFromDisplay(path string) string { return path }

func guiListenPathForConfig(endpoint string) string { return endpoint }
func guiEndpointPathForConfig(endpoint string) string { return endpoint }

func guiNormalizeListenPathForMode(endpoint string, _ transport.Mode) string { return endpoint }
4 changes: 2 additions & 2 deletions cmd/ssh-keyselect-gui/endpoint_display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func guiFilePathFromDisplay(path string) string {
return strings.ReplaceAll(path, "¥", `\`)
}

// guiListenPathForConfig writes filesystem endpoints in native Windows form while preserving named pipes.
func guiListenPathForConfig(endpoint string) string {
// guiEndpointPathForConfig writes filesystem endpoints in native Windows form while preserving named pipes.
func guiEndpointPathForConfig(endpoint string) string {
if endpoint == "" || winpath.IsNamedPipe(endpoint) {
return endpoint
}
Expand Down
51 changes: 28 additions & 23 deletions cmd/ssh-keyselect-gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ type guiApp struct {

type guiOptions struct {
Config *string `help:"TOML configuration file." placeholder:"FILE"`
Listen *string `help:"Frontend endpoint (default: HOME socket, or the fixed Windows OpenSSH named-pipe endpoint)." placeholder:"ENDPOINT"`
ListenMode *string `help:"Frontend protocol mode (auto, cygwin, unix, named-pipe, wsl1)." placeholder:"MODE"`
Upstream *string `help:"Upstream endpoint (default: UPSTREAM_SSH_AUTH_SOCK, then SSH_AUTH_SOCK)." placeholder:"ENDPOINT"`
UpstreamMode *string `help:"Upstream protocol mode (auto, cygwin, unix, named-pipe, wsl1)." placeholder:"MODE"`
Listen *string `help:"Frontend endpoint (default: HOME socket, or the fixed Windows OpenSSH named-pipe endpoint)." placeholder:"ENDPOINT"`
ListenMode *string `help:"Frontend protocol mode (auto, cygwin, unix, named-pipe, wsl1)." placeholder:"MODE"`
AllowUnboundSigningOnBindFailure *bool `help:"Allow signing without upstream session binding after an explicit upstream refusal (weakens upstream restrictions)."`
LogLevel *string `help:"Log level (off, debug, info, warn, error)." placeholder:"LEVEL"`
Version kong.VersionFlag `help:"Print version information and quit."`
Expand Down Expand Up @@ -132,16 +132,6 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
if err != nil {
return cmdutil.ReportError(stderr, guiCommandName, err)
}
if options.Listen != nil {
cfg.Agent.Listen = config.ExpandPath(*options.Listen)
}
if options.ListenMode != nil {
mode, modeErr := transport.ParseMode(*options.ListenMode)
if modeErr != nil {
return cmdutil.ReportError(stderr, guiCommandName, modeErr)
}
cfg.Agent.ListenMode = mode
}
if options.Upstream != nil {
cfg.Agent.Upstream = config.ExpandPath(*options.Upstream)
}
Expand All @@ -152,6 +142,16 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
}
cfg.Agent.UpstreamMode = mode
}
if options.Listen != nil {
cfg.Agent.Listen = config.ExpandPath(*options.Listen)
}
if options.ListenMode != nil {
mode, modeErr := transport.ParseMode(*options.ListenMode)
if modeErr != nil {
return cmdutil.ReportError(stderr, guiCommandName, modeErr)
}
cfg.Agent.ListenMode = mode
}
if options.LogLevel != nil {
cfg.Log.Level = *options.LogLevel
}
Expand Down Expand Up @@ -187,8 +187,18 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
return cmdutil.ReportError(stderr, guiCommandName, err)
}
}
mygo.App.SetName("SSH KeySelect")
mygo.App.SetVersion(version)
userDataPath, err := setGUIUserDataPath()
if err != nil {
return cmdutil.ReportError(stderr, guiCommandName, err)
}
logFilePath := cfg.Log.File
if logFilePath == "" {
logFilePath = guiDefaultLogFilePath(userDataPath)
}

logOutput, err := newGUILogOutput(stderr, cfg.Log.File)
logOutput, err := newGUILogOutput(stderr, logFilePath)
if err != nil {
return cmdutil.ReportError(stderr, guiCommandName, err)
}
Expand All @@ -207,7 +217,8 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
server.SetAllowUnboundSigningOnBindFailure(cfg.Agent.AllowUnboundSigningOnBindFailure)
app := &guiApp{
ctx: ctx, stop: stop, logger: logger, loggerOutput: logOutput, cfg: cfg,
configPath: configPath, actualListen: listenPath, listenMode: effectiveListenMode,
userDataPath: userDataPath,
configPath: configPath, actualListen: listenPath, listenMode: effectiveListenMode,
endpointAgent: endpointAgent, server: server, selector: guiSelector,
selectedIdentity: -1,
}
Expand All @@ -220,8 +231,9 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
})
app.runtime = &guiRuntime{
ctx: ctx, server: server, agent: endpointAgent, loggerOutput: logOutput, logOutput: logOutput, logLevel: &logLevel,
listenPath: listenPath, listenMode: effectiveListenMode, currentLogLevel: cfg.Log.Level,
currentLogFile: cfg.Log.File,
defaultLogFilePath: guiDefaultLogFilePath(userDataPath),
listenPath: listenPath, listenMode: effectiveListenMode, currentLogLevel: cfg.Log.Level,
currentLogFile: logFilePath,
}
app.runtime.onServeError = func(serveErr error) {
if window := app.mainWindow.Load(); window != nil {
Expand All @@ -236,13 +248,6 @@ func executeGUI(args []string, stdout, stderr io.Writer) int {
}
}

mygo.App.SetName("SSH KeySelect")
mygo.App.SetVersion(version)
userDataPath, err := setGUIUserDataPath()
if err != nil {
return cmdutil.ReportError(stderr, guiCommandName, err)
}
app.userDataPath = userDataPath
if cfg.History.Enabled || cfg.History.RememberSelection {
historyPath, pathErr := guiHistoryDatabasePath(userDataPath, cfg.History.Path)
if pathErr != nil {
Expand Down
49 changes: 35 additions & 14 deletions cmd/ssh-keyselect-gui/gui_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package main
import (
"errors"
"fmt"
"math"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/egoist/mygo"
Expand All @@ -27,7 +27,10 @@ import (

// guiConfigForDisk stores endpoint paths in the native format for this OS.
func guiConfigForDisk(cfg config.Config) config.Config {
cfg.Agent.Listen = guiListenPathForConfig(cfg.Agent.Listen)
if _, environmentBacked := config.UpstreamEnvironmentVariable(cfg.Agent.Upstream); !environmentBacked {
cfg.Agent.Upstream = guiEndpointPathForConfig(cfg.Agent.Upstream)
}
cfg.Agent.Listen = guiEndpointPathForConfig(cfg.Agent.Listen)
return cfg
}

Expand Down Expand Up @@ -600,7 +603,7 @@ type guiSettingsValues struct {
listenMode string
logLevel string
theme string
selectionTimeout float64
selectionTimeout string
allowUnboundSigningOnBindFailure bool
}

Expand All @@ -615,6 +618,7 @@ type guiSettingsState struct {
resolvedUpstream string
listenPath string
logFile string
logPlaceholder string
historyFile string
historyPlaceholder string
historyEnabled bool
Expand All @@ -623,7 +627,7 @@ type guiSettingsState struct {
listenMode string
logLevel string
theme string
selectionTimeout float64
selectionTimeout string
allowUnboundSigningOnBindFailure bool
initialListenMode transport.Mode
previousListenMode string
Expand Down Expand Up @@ -665,7 +669,7 @@ func (a *guiApp) openSettings() {
}
window := mygo.NewWindow(mygo.WindowOptions{
Title: "Settings", Parent: a.window, Modal: true,
Width: 600, Height: height, MinWidth: 580, MinHeight: minHeight,
Width: 620, Height: height, MinWidth: 580, MinHeight: minHeight,
Content: ui.View(state.view),
})
state.window = window
Expand Down Expand Up @@ -715,17 +719,18 @@ func newGUISettingsState(app *guiApp, cfg config.Config) (*guiSettingsState, err
if err != nil {
return nil, err
}
logPlaceholder := guiDisplayFilePath(guiDefaultLogFilePath(app.userDataPath))
state := &guiSettingsState{
app: app, cfg: cfg,
upstreamSource: upstreamSource, upstreamPath: guiDisplayEndpointPath(upstreamEndpoint),
upstreamEnvName: upstreamEnvName, resolvedUpstream: upstreamEndpoint,
listenPath: guiDisplayEndpointPath(listenEndpoint), logFile: guiDisplayFilePath(cfg.Log.File),
historyFile: guiDisplayFilePath(strings.TrimSpace(cfg.History.Path)),
logPlaceholder: logPlaceholder, historyFile: guiDisplayFilePath(strings.TrimSpace(cfg.History.Path)),
historyPlaceholder: guiDisplayFilePath(historyPlaceholder), historyEnabled: cfg.History.Enabled,
rememberSelection: cfg.History.RememberSelection,
upstreamMode: upstreamMode, listenMode: listenMode, logLevel: strings.ToLower(cfg.Log.Level),
theme: guiThemeLabel(cfg.GUI.Theme),
selectionTimeout: float64(cfg.Agent.SelectionTimeout),
selectionTimeout: guiSelectionTimeoutForDisplay(cfg.Agent.SelectionTimeout),
allowUnboundSigningOnBindFailure: cfg.Agent.AllowUnboundSigningOnBindFailure,
initialListenMode: initialListenMode, previousListenMode: listenMode,
lastFilesystemPath: func() string {
Expand Down Expand Up @@ -834,13 +839,21 @@ func (s *guiSettingsState) selectionSection(c *ui.Context, theme *ui.Theme) {
ui.Text(c, "Key selection").FontWeight(500)
ui.Row(c).Gap(theme.Space(2)).AlignItems(ui.Center).Children(func() {
ui.Text(c, "Timeout").Width(theme.Space(26)).Shrink(0)
// Keep 86400 editable so Apply can report the invalid endpoint instead of reverting it.
ui.NumberInput(c, &s.selectionTimeout, 1, 86400, 1).Label("Key selection timeout")
ui.TextInput(c, &s.selectionTimeout).
Label("Key selection timeout").Placeholder(strconv.Itoa(config.Default().Agent.SelectionTimeout)).Grow(1)
ui.Text(c, "seconds").TextColor(theme.TextMuted)
})
})
}

// guiSelectionTimeoutForDisplay leaves the default visible as an input placeholder.
func guiSelectionTimeoutForDisplay(seconds int) string {
if seconds == config.Default().Agent.SelectionTimeout {
return ""
}
return strconv.Itoa(seconds)
}

// endpointSection keeps each socket path and transport choice in a compact group.
func (s *guiSettingsState) endpointSection(c *ui.Context, theme *ui.Theme, title string, upstream bool) {
path, mode := &s.listenPath, &s.listenMode
Expand Down Expand Up @@ -919,7 +932,7 @@ func (s *guiSettingsState) loggingSection(c *ui.Context, theme *ui.Theme) {
ui.Text(c, "Logging").FontWeight(500)
ui.Row(c).Gap(theme.Space(2)).AlignItems(ui.Center).Children(func() {
ui.Text(c, "Log file").Width(theme.Space(26)).Shrink(0)
input := ui.TextInput(c, &s.logFile).Label("Log file").Placeholder("Leave blank to log to standard error").Grow(1)
input := ui.TextInput(c, &s.logFile).Label("Log file").Placeholder(s.logPlaceholder).Grow(1)
if input.Changed() {
s.logFile = guiFormatPathInput(s.logFile)
}
Expand Down Expand Up @@ -1056,9 +1069,6 @@ func (s *guiSettingsState) upstreamEndpoint() (string, error) {
}

func (s *guiSettingsState) buildConfig() (config.Config, error) {
if math.Trunc(s.selectionTimeout) != s.selectionTimeout {
return config.Config{}, fmt.Errorf("key selection timeout must be a whole number of seconds")
}
cfg := s.cfg
upstreamMode := guiModeFromDisplay(s.upstreamMode)
upstreamEndpoint := ""
Expand Down Expand Up @@ -1112,7 +1122,15 @@ func (s *guiSettingsState) buildConfig() (config.Config, error) {
cfg.Agent.UpstreamMode = upstreamMode
cfg.Agent.Listen = listenEndpoint
cfg.Agent.ListenMode = listenMode
cfg.Agent.SelectionTimeout = int(s.selectionTimeout)
selectionTimeout := config.Default().Agent.SelectionTimeout
if value := strings.TrimSpace(s.selectionTimeout); value != "" {
parsed, err := strconv.Atoi(value)
if err != nil {
return config.Config{}, fmt.Errorf("key selection timeout must be a whole number of seconds")
}
selectionTimeout = parsed
}
cfg.Agent.SelectionTimeout = selectionTimeout
cfg.Agent.AllowUnboundSigningOnBindFailure = s.allowUnboundSigningOnBindFailure
cfg.Log.File = config.ExpandPath(guiFilePathFromDisplay(s.logFile))
cfg.Log.Level = s.logLevel
Expand All @@ -1131,6 +1149,9 @@ func (s *guiSettingsState) browseLogFile() {
s.browsingLog = true
window := s.window
current := guiFilePathFromDisplay(s.logFile)
if current == "" {
current = guiFilePathFromDisplay(s.logPlaceholder)
}
go func() {
path, err := guiChooseLogFile(window, current)
if window == nil || window.IsDestroyed() {
Expand Down
5 changes: 5 additions & 0 deletions cmd/ssh-keyselect-gui/gui_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func newGUILogOutput(fallback io.Writer, path string) (*guiLogOutput, error) {
return output, nil
}

// guiDefaultLogFilePath keeps the default log beside the GUI's other application data.
func guiDefaultLogFilePath(userDataPath string) string {
return filepath.Join(userDataPath, "ssh-keyselect.log")
}

// newGUILogger shares a live level with the proxy and UI while keeping one destination writer.
func newGUILogger(output io.Writer, level *slog.LevelVar, configured string) *slog.Logger {
level.Set(guiSlogLevel(configured))
Expand Down
38 changes: 21 additions & 17 deletions cmd/ssh-keyselect-gui/gui_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,20 @@ type guiListenerState struct {

// guiRuntime restarts serving at a changed endpoint and invalidates old client selections.
type guiRuntime struct {
mu sync.Mutex
ctx context.Context
server *agentproxy.Server
agent *guiEndpointAgent
loggerOutput io.Writer
onServeError func(error)
listenerState *guiListenerState
listenPath string
listenMode transport.Mode
currentLogLevel string
currentLogFile string
logOutput *guiLogOutput
logLevel *slog.LevelVar
mu sync.Mutex
ctx context.Context
server *agentproxy.Server
agent *guiEndpointAgent
loggerOutput io.Writer
onServeError func(error)
listenerState *guiListenerState
listenPath string
listenMode transport.Mode
currentLogLevel string
currentLogFile string
defaultLogFilePath string
logOutput *guiLogOutput
logLevel *slog.LevelVar
}

func (r *guiRuntime) Apply(cfg config.Config) (string, transport.Mode, error) {
Expand All @@ -130,15 +131,18 @@ func (r *guiRuntime) Apply(cfg config.Config) (string, transport.Mode, error) {
if err != nil {
return "", "", err
}
cfg.Log.File = config.ExpandPath(cfg.Log.File)
logFileChanged := r.currentLogFile != cfg.Log.File
logFilePath := config.ExpandPath(cfg.Log.File)
if logFilePath == "" {
logFilePath = r.defaultLogFilePath
}
logFileChanged := r.currentLogFile != logFilePath
var preparedLogFile *os.File
if logFileChanged {
if r.logOutput == nil {
return "", "", errors.New("GUI log output is unavailable")
}
var err error
preparedLogFile, err = r.logOutput.open(cfg.Log.File)
preparedLogFile, err = r.logOutput.open(logFilePath)
if err != nil {
return "", "", err
}
Expand All @@ -155,7 +159,7 @@ func (r *guiRuntime) Apply(cfg config.Config) (string, transport.Mode, error) {
if logFileChanged {
r.logOutput.replace(preparedLogFile)
preparedLogFile = nil
r.currentLogFile = cfg.Log.File
r.currentLogFile = logFilePath
}
if r.currentLogLevel != cfg.Log.Level {
if r.logLevel != nil {
Expand Down
Loading
Loading