fix: Use instance identity session token for git subcommands (#4884)

This broke using gitssh with instance identity!
This commit is contained in:
Kyle Carberry
2022-11-04 09:44:36 -07:00
committed by GitHub
parent 3f6c4486f7
commit 8e743d28c8
3 changed files with 27 additions and 22 deletions
+5 -8
View File
@@ -156,22 +156,19 @@ func workspaceAgent() *cobra.Command {
closer := agent.New(agent.Options{
Client: client,
Logger: logger,
ExchangeToken: func(ctx context.Context) error {
ExchangeToken: func(ctx context.Context) (string, error) {
if exchangeToken == nil {
return nil
return client.SessionToken, nil
}
resp, err := exchangeToken(ctx)
if err != nil {
return err
return "", err
}
client.SessionToken = resp.SessionToken
return nil
return "", nil
},
EnvironmentVariables: map[string]string{
// Override the "CODER_AGENT_TOKEN" variable in all
// shells so "gitssh" and "gitaskpass" works!
"CODER_AGENT_TOKEN": client.SessionToken,
"GIT_ASKPASS": executablePath,
"GIT_ASKPASS": executablePath,
},
})
<-cmd.Context().Done()