@@ -41,10 +41,11 @@ func agentCmd() *cobra.Command {
41
41
42
42
func startCmd () * cobra.Command {
43
43
var (
44
- token string
45
- coderURL string
46
- logFile string
47
- pullCert bool
44
+ token string
45
+ sessionToken string
46
+ coderURL string
47
+ logFile string
48
+ pullCert bool
48
49
)
49
50
cmd := & cobra.Command {
50
51
Use : "start --coder-url=<coder_url> --token=<token> --log-file=<path>" ,
@@ -107,9 +108,9 @@ coder agent start --log-file=/tmp/coder-agent.log
107
108
}
108
109
}
109
110
110
- // First inject certs
111
+ // First inject certs if enabled
111
112
if pullCert {
112
- count , err := writeCoderdCerts (ctx )
113
+ count , err := writeCoderdCerts (ctx , sessionToken )
113
114
if err != nil {
114
115
return xerrors .Errorf ("trust certs: %w" , err )
115
116
}
@@ -139,16 +140,17 @@ coder agent start --log-file=/tmp/coder-agent.log
139
140
}
140
141
141
142
cmd .Flags ().StringVar (& token , "token" , "" , "coder agent token" )
143
+ cmd .Flags ().StringVar (& sessionToken , "session-token" , "" , "coder session token to auth as user" )
142
144
cmd .Flags ().StringVar (& coderURL , "coder-url" , "" , "coder access url" )
143
145
cmd .Flags ().StringVar (& logFile , "log-file" , "" , "write a copy of logs to file" )
144
146
cmd .Flags ().BoolVar (& pullCert , "pull-cert" , true , "pulls the tls certificate from coderd to ensure the cert is trusted" )
145
147
146
148
return cmd
147
149
}
148
150
149
- func writeCoderdCerts (ctx context.Context ) (int , error ) {
151
+ func writeCoderdCerts (ctx context.Context , sessionToken string ) (int , error ) {
150
152
// Inject certs to custom dir and concat with : with existing dir.
151
- certs , err := trustCertificate (ctx )
153
+ certs , err := trustCertificate (ctx , sessionToken )
152
154
if err != nil {
153
155
return 0 , xerrors .Errorf ("trust cert: %w" , err )
154
156
}
@@ -187,7 +189,7 @@ func writeCoderdCerts(ctx context.Context) (int, error) {
187
189
// It will then extend the certs to trust to include this directory.
188
190
// This only happens if coderd can answer the challenge to prove
189
191
// it has the shared secret.
190
- func trustCertificate (ctx context.Context ) ([][]byte , error ) {
192
+ func trustCertificate (ctx context.Context , sessionToken string ) ([][]byte , error ) {
191
193
conf := & tls.Config {InsecureSkipVerify : true }
192
194
hc := & http.Client {
193
195
Timeout : time .Second * 3 ,
@@ -196,7 +198,7 @@ func trustCertificate(ctx context.Context) ([][]byte, error) {
196
198
},
197
199
}
198
200
199
- c , err := newClient (ctx , false , withHTTPClient (hc ))
201
+ c , err := newClient (ctx , false , withHTTPClient (hc ), withSessionToken ( sessionToken ) )
200
202
if err != nil {
201
203
return nil , xerrors .Errorf ("new client: %w" , err )
202
204
}
0 commit comments