-
Notifications
You must be signed in to change notification settings - Fork 18
Bound the keyring probe on headless sessions #581
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
edb710f
Bound the keyring probe on headless sessions (Refs #568)
jeremy b2b72bf
Treat only fully detached sessions as headless (Refs #568)
jeremy ced0cbc
Recognize GUI sessions before bounding the probe (Refs #568)
jeremy 4eb0779
Split the Windows GUI-session stub into its own file (Refs #568)
jeremy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "context" | ||
| "os/exec" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // guiSessionAvailable reports whether the process runs inside a macOS Aqua | ||
| // (GUI) session, where the keychain unlock prompt appears as a WindowServer | ||
| // dialog even with every standard stream detached — GUI-launched apps and | ||
| // IDE task runners. `launchctl managername` prints "Aqua" there; ssh and CI | ||
| // run under StandardIO or Background. launchctl only inspects the launchd | ||
| // session — it cannot touch the keychain — but is bounded anyway, and any | ||
| // failure counts as no GUI so genuinely headless sessions keep the bounded | ||
| // probe. | ||
| func guiSessionAvailable() bool { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) | ||
| defer cancel() | ||
| out, err := exec.CommandContext(ctx, "/bin/launchctl", "managername").Output() | ||
| return err == nil && strings.TrimSpace(string(out)) == "Aqua" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //go:build !darwin && !windows | ||
|
|
||
| package auth | ||
|
|
||
| import "os" | ||
|
|
||
| // guiSessionAvailable reports a display server the keyring's unlock prompt | ||
| // could use even with every standard stream detached. | ||
| func guiSessionAvailable() bool { | ||
| return os.Getenv("DISPLAY") != "" || os.Getenv("WAYLAND_DISPLAY") != "" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //go:build !darwin && !windows | ||
|
|
||
| package auth | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestGUISessionAvailableTracksDisplayEnv(t *testing.T) { | ||
| t.Setenv("DISPLAY", "") | ||
| t.Setenv("WAYLAND_DISPLAY", "") | ||
| assert.False(t, guiSessionAvailable()) | ||
|
|
||
| t.Setenv("DISPLAY", ":0") | ||
|
jeremy marked this conversation as resolved.
|
||
| assert.True(t, guiSessionAvailable()) | ||
|
|
||
| t.Setenv("DISPLAY", "") | ||
| t.Setenv("WAYLAND_DISPLAY", "wayland-0") | ||
| assert.True(t, guiSessionAvailable(), "Wayland-only sessions have no DISPLAY") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package auth | ||
|
|
||
| // guiSessionAvailable is always false on Windows: Credential Manager | ||
| // operates without prompting, so a bounded probe cannot cut off an | ||
| // interaction, and misclassifying a GUI-launched session as headless is | ||
| // harmless here. | ||
| func guiSessionAvailable() bool { | ||
| return false | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.