Skip to content

Commit f3d2bd7

Browse files
brandonweeksdopey
authored andcommitted
Run on plaintext HTTP to support Cloud Run
1 parent 746ee2b commit f3d2bd7

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

authority/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ func (c *Config) Validate() error {
227227
}
228228

229229
// Validate address (a port is required)
230-
if _, _, err := net.SplitHostPort(c.Address); err != nil {
231-
return errors.Errorf("invalid address %s", c.Address)
230+
if c.Address != "" {
231+
if _, _, err := net.SplitHostPort(c.Address); err != nil {
232+
return errors.Errorf("invalid address %s", c.Address)
233+
}
232234
}
233235

234236
if c.TLS == nil {

ca/ca.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
238238
return nil, errors.Wrap(err, "error creating SCEP authority")
239239
}
240240

241-
// According to the RFC (https://tools.ietf.org/html/rfc8894#section-7.10),
242-
// SCEP operations are performed using HTTP, so that's why the API is mounted
243-
// to the insecure mux.
244-
insecureMux.Route("/"+scepPrefix, func(r chi.Router) {
245-
scepAPI.Route(r)
246-
})
247-
248241
// The RFC also mentions usage of HTTPS, but seems to advise
249242
// against it, because of potential interoperability issues.
250243
// Currently I think it's not bad to use HTTPS also, so that's
@@ -266,7 +259,6 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
266259
return nil, err
267260
}
268261
handler = m.Middleware(handler)
269-
insecureHandler = m.Middleware(insecureHandler)
270262
}
271263

272264
// Add logger if configured
@@ -276,25 +268,24 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
276268
return nil, err
277269
}
278270
handler = logger.Middleware(handler)
279-
insecureHandler = logger.Middleware(insecureHandler)
280271
}
281272

282273
// Create context with all the necessary values.
283274
baseContext := buildContext(auth, scepAuthority, acmeDB, acmeLinker)
284275

285-
ca.srv = server.New(cfg.Address, handler, tlsConfig)
286-
ca.srv.BaseContext = func(net.Listener) context.Context {
287-
return baseContext
276+
if cfg.Address != "" {
277+
ca.srv = server.New(cfg.Address, handler, tlsConfig)
278+
ca.srv.BaseContext = func(net.Listener) context.Context {
279+
return baseContext
280+
}
288281
}
289282

290-
// only start the insecure server if the insecure address is configured
291-
// and, currently, also only when it should serve SCEP endpoints.
292-
if ca.shouldServeSCEPEndpoints() && cfg.InsecureAddress != "" {
283+
if cfg.InsecureAddress != "" {
293284
// TODO: instead opt for having a single server.Server but two
294285
// http.Servers handling the HTTP and HTTPS handler? The latter
295286
// will probably introduce more complexity in terms of graceful
296287
// reload.
297-
ca.insecureSrv = server.New(cfg.InsecureAddress, insecureHandler, nil)
288+
ca.insecureSrv = server.New(cfg.InsecureAddress, handler, nil)
298289
ca.insecureSrv.BaseContext = func(net.Listener) context.Context {
299290
return baseContext
300291
}
@@ -335,11 +326,13 @@ func (ca *CA) Run() error {
335326
log.Printf("Current context: %s", step.Contexts().GetCurrent().Name)
336327
}
337328
log.Printf("Config file: %s", ca.opts.configFile)
338-
baseURL := fmt.Sprintf("https://%s%s",
339-
authorityInfo.DNSNames[0],
340-
ca.config.Address[strings.LastIndex(ca.config.Address, ":"):])
341-
log.Printf("The primary server URL is %s", baseURL)
342-
log.Printf("Root certificates are available at %s/roots.pem", baseURL)
329+
if ca.config.Address != "" {
330+
baseURL := fmt.Sprintf("https://%s%s",
331+
authorityInfo.DNSNames[0],
332+
ca.config.Address[strings.LastIndex(ca.config.Address, ":"):])
333+
log.Printf("The primary server URL is %s", baseURL)
334+
log.Printf("Root certificates are available at %s/roots.pem", baseURL)
335+
}
343336
if len(authorityInfo.DNSNames) > 1 {
344337
log.Printf("Additional configured hostnames: %s",
345338
strings.Join(authorityInfo.DNSNames[1:], ", "))
@@ -363,11 +356,13 @@ func (ca *CA) Run() error {
363356
}()
364357
}
365358

366-
wg.Add(1)
367-
go func() {
368-
defer wg.Done()
369-
errs <- ca.srv.ListenAndServe()
370-
}()
359+
if ca.srv != nil {
360+
wg.Add(1)
361+
go func() {
362+
defer wg.Done()
363+
errs <- ca.srv.ListenAndServe()
364+
}()
365+
}
371366

372367
// wait till error occurs; ensures the servers keep listening
373368
err := <-errs

0 commit comments

Comments
 (0)