@@ -44,6 +44,7 @@ func startCmd() *cobra.Command {
44
44
token string
45
45
coderURL string
46
46
logFile string
47
+ pullCert bool
47
48
)
48
49
cmd := & cobra.Command {
49
50
Use : "start --coder-url=<coder_url> --token=<token> --log-file=<path>" ,
@@ -107,9 +108,11 @@ coder agent start --log-file=/tmp/coder-agent.log
107
108
}
108
109
109
110
// First inject certs
110
- err = writeCoderdCerts (ctx )
111
- if err != nil {
112
- return xerrors .Errorf ("trust certs: %w" , err )
111
+ if pullCert {
112
+ err = writeCoderdCerts (ctx )
113
+ if err != nil {
114
+ return xerrors .Errorf ("trust certs: %w" , err )
115
+ }
113
116
}
114
117
115
118
log .Info (ctx , "starting wsnet listener" , slog .F ("coder_access_url" , u .String ()))
@@ -137,6 +140,7 @@ coder agent start --log-file=/tmp/coder-agent.log
137
140
cmd .Flags ().StringVar (& token , "token" , "" , "coder agent token" )
138
141
cmd .Flags ().StringVar (& coderURL , "coder-url" , "" , "coder access url" )
139
142
cmd .Flags ().StringVar (& logFile , "log-file" , "" , "write a copy of logs to file" )
143
+ cmd .Flags ().BoolVar (& pullCert , "pull-cert" , true , "pulls the tls certificate from coderd to ensure the cert is trusted" )
140
144
141
145
return cmd
142
146
}
@@ -148,6 +152,11 @@ func writeCoderdCerts(ctx context.Context) error {
148
152
return xerrors .Errorf ("trust cert: %w" , err )
149
153
}
150
154
155
+ // No certs to write
156
+ if len (certs ) == 0 {
157
+ return nil
158
+ }
159
+
151
160
err = os .MkdirAll (coderdCertDir , 0666 )
152
161
if err != nil {
153
162
return xerrors .Errorf ("mkdir %s: %w" , coderdCertDir , err )
@@ -186,11 +195,16 @@ func trustCertificate(ctx context.Context) ([][]byte, error) {
186
195
},
187
196
}
188
197
189
- c , err := newClient (ctx , true , withHTTPClient (hc ))
198
+ c , err := newClient (ctx , false , withHTTPClient (hc ))
190
199
if err != nil {
191
200
return nil , xerrors .Errorf ("new client: %w" , err )
192
201
}
193
202
203
+ // Non-https won't have any tls certs
204
+ if c .BaseURL ().Scheme != "https" {
205
+ return nil , nil
206
+ }
207
+
194
208
id := os .Getenv ("CODER_WORKSPACE_ID" )
195
209
challenge , err := c .TrustEnvironment (ctx , id )
196
210
if err != nil {
0 commit comments