Skip to content

Commit b70ce5a

Browse files
committed
feat(cli): auto-detect SSH sessions and use headless auth login
Detect SSH sessions via SSH_CLIENT/SSH_TTY/SSH_CONNECTION env vars and automatically use headless authentication, avoiding a localhost callback URL that is unreachable from the user's browser. Closes #2990 Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent b200376 commit b70ce5a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app/cli/cmd/auth_login.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import (
2323
"net"
2424
"net/http"
2525
"net/url"
26+
"os"
2627
"os/exec"
2728
"runtime"
2829
"time"
@@ -75,7 +76,7 @@ func interactiveAuth(forceHeadless bool) error {
7576
q.Set(oauth.QueryParamLongLived, "true")
7677
serverLoginURL.RawQuery = q.Encode()
7778

78-
if forceHeadless {
79+
if forceHeadless || isRemoteSession() {
7980
return headlessAuth(serverLoginURL)
8081
}
8182

@@ -185,6 +186,17 @@ func openbrowser(url string) error {
185186
return cmd.Wait()
186187
}
187188

189+
// isRemoteSession returns true if the CLI is running inside an SSH session
190+
// where a local browser callback would not be reachable.
191+
func isRemoteSession() bool {
192+
for _, key := range []string{"SSH_CLIENT", "SSH_TTY", "SSH_CONNECTION"} {
193+
if os.Getenv(key) != "" {
194+
return true
195+
}
196+
}
197+
return false
198+
}
199+
188200
// Retrieve loginURL from the control plane
189201
func retrieveLoginURL() (string, error) {
190202
client := pb.NewStatusServiceClient(ActionOpts.CPConnection)

0 commit comments

Comments
 (0)