chore: refactor instance identity to be a SessionTokenProvider (#19566)

Refactors Agent instance identity to be a SessionTokenProvider.

Refactors the CLI to create Agent clients via a centralized function, rather than add-hoc via individual command handlers and their flags.

This allows commands besides `coder agent`, but which still use the agent identity, to support instance identity authentication.

Fixes #19111 by unifying all API requests to go thru the SessionTokenProvider for auth credentials.
This commit is contained in:
Spike Curtis
2025-09-03 10:38:42 +04:00
committed by GitHub
parent ee35ad3a57
commit 1354d84eb4
35 changed files with 640 additions and 478 deletions
+5 -3
View File
@@ -18,8 +18,8 @@ import (
// gitAskpass is used by the Coder agent to automatically authenticate
// with Git providers based on a hostname.
func (r *RootCmd) gitAskpass() *serpent.Command {
return &serpent.Command{
func gitAskpass(agentAuth *AgentAuth) *serpent.Command {
cmd := &serpent.Command{
Use: "gitaskpass",
Hidden: true,
Handler: func(inv *serpent.Invocation) error {
@@ -33,7 +33,7 @@ func (r *RootCmd) gitAskpass() *serpent.Command {
return xerrors.Errorf("parse host: %w", err)
}
client, err := r.tryCreateAgentClient()
client, err := agentAuth.CreateClient(ctx)
if err != nil {
return xerrors.Errorf("create agent client: %w", err)
}
@@ -90,4 +90,6 @@ func (r *RootCmd) gitAskpass() *serpent.Command {
return nil
},
}
agentAuth.AttachOptions(cmd, false)
return cmd
}