Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b785e99

Browse files
authored
chore: explain GIT_ASKPASS behavior in docs (#12784)
* chore: docs explaining GIT_ASKPASS behavior - VSCode configuration requirements
1 parent 79441e3 commit b785e99

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

cli/externalauth.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package cli
22

33
import (
44
"encoding/json"
5+
"fmt"
56

67
"golang.org/x/xerrors"
78

89
"github.com/tidwall/gjson"
910

1011
"github.com/coder/coder/v2/cli/cliui"
1112
"github.com/coder/coder/v2/codersdk/agentsdk"
13+
"github.com/coder/pretty"
1214
"github.com/coder/serpent"
1315
)
1416

@@ -68,6 +70,11 @@ fi
6870
ctx, stop := inv.SignalNotifyContext(ctx, StopSignals...)
6971
defer stop()
7072

73+
if r.agentToken == "" {
74+
_, _ = fmt.Fprint(inv.Stderr, pretty.Sprintf(headLineStyle(), "No agent token found, this command must be run from inside a running workspace.\n"))
75+
return xerrors.Errorf("agent token not found")
76+
}
77+
7178
client, err := r.createAgentClient()
7279
if err != nil {
7380
return xerrors.Errorf("create agent client: %w", err)

cli/externalauth_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestExternalAuth(t *testing.T) {
2424
}))
2525
t.Cleanup(srv.Close)
2626
url := srv.URL
27-
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token", "github")
27+
inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github")
2828
pty := ptytest.New(t)
2929
inv.Stdout = pty.Output()
3030
waiter := clitest.StartWithWaiter(t, inv)
@@ -40,7 +40,7 @@ func TestExternalAuth(t *testing.T) {
4040
}))
4141
t.Cleanup(srv.Close)
4242
url := srv.URL
43-
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token", "github")
43+
inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github")
4444
pty := ptytest.New(t)
4545
inv.Stdout = pty.Output()
4646
clitest.Start(t, inv)
@@ -55,7 +55,7 @@ func TestExternalAuth(t *testing.T) {
5555
}))
5656
t.Cleanup(srv.Close)
5757
url := srv.URL
58-
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token")
58+
inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token")
5959
watier := clitest.StartWithWaiter(t, inv)
6060
watier.RequireContains("wanted 1 args but got 0")
6161
})
@@ -71,7 +71,7 @@ func TestExternalAuth(t *testing.T) {
7171
}))
7272
t.Cleanup(srv.Close)
7373
url := srv.URL
74-
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token", "github", "--extra", "hey")
74+
inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github", "--extra", "hey")
7575
pty := ptytest.New(t)
7676
inv.Stdout = pty.Output()
7777
clitest.Start(t, inv)

docs/admin/external-auth.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,46 @@ you can require users authenticate via git prior to creating a workspace:
212212

213213
![Git authentication in template](../images/admin/git-auth-template.png)
214214

215-
The following example will require users authenticate via GitHub and auto-clone
216-
a repo into the `~/coder` directory.
215+
### Native git authentication will auto-refresh tokens
216+
217+
<blockquote class="info">
218+
<p>
219+
This is the preferred authentication method.
220+
</p>
221+
</blockquote>
222+
223+
By default, the coder agent will configure native `git` authentication via the
224+
`GIT_ASKPASS` environment variable. Meaning, with no additional configuration,
225+
external authentication will work with native `git` commands.
226+
227+
To check the auth token being used **from inside a running workspace**, run:
228+
229+
```shell
230+
# If the exit code is non-zero, then the user is not authenticated with the
231+
# external provider.
232+
coder external-auth access-token <external-auth-id>
233+
```
234+
235+
Note: Some IDE's override the `GIT_ASKPASS` environment variable and need to be
236+
configured.
237+
238+
**VSCode**
239+
240+
Use the
241+
[Coder](https://marketplace.visualstudio.com/items?itemName=coder.coder-remote)
242+
extension to automatically configure these settings for you!
243+
244+
Otherwise, you can manually configure the following settings:
245+
246+
- Set `git.terminalAuthentication` to `false`
247+
- Set `git.useIntegratedAskPass` to `false`
248+
249+
### Hard coded tokens do not auto-refresh
250+
251+
If the token is required to be inserted into the workspace, for example
252+
[GitHub cli](https://cli.github.com/), the auth token can be inserted from the
253+
template. This token will not auto-refresh. The following example will
254+
authenticate via GitHub and auto-clone a repo into the `~/coder` directory.
217255

218256
```hcl
219257
data "coder_external_auth" "github" {

0 commit comments

Comments
 (0)