Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Serve HTTPS on macOS with socket activation

54ccf66e63032dd8e5afd80f609d6e6be183e5f5 · Keenan Nemetz · 3d ago · parent 75478a9d

Serve HTTPS on macOS with socket activation

Let vole serve accept listeners the service manager already owns, so a launchd
LaunchDaemon can own ports 80/443 as root and hand the ready sockets to an
unprivileged serve for ACME. Reads LISTEN_FDS/LISTEN_PID (and launchd's
Listeners), defaults the platform contract to the host, and falls back to binding
http_addr/https_addr when no descriptors are inherited.

Add unit tests for the env contract and fd wrapping, plus an integration test that
execs the real binary with an inherited fd and completes a request. Document the
socket-activation choice in the macOS deploy guide.

server/server.go +5−9

@@ -325,10 +325,13 @@ func (s *Server) Run(ctx context.Context) error {
325 325 sshLn.Close()
326 326 }
327 327 }
328 httpLn, err := net.Listen("tcp", s.Cfg.HTTPAddr)
328 // A launchd or systemd unit that owns port 80 and 443 hands those listeners
329 // here; when it does, serve uses them instead of binding http_addr. Nothing
330 // else changes.
331 httpLn, httpsLn, err := httpListeners(os.Getenv, os.Getpid(), s.Cfg.HTTPAddr, s.Cfg.HTTPSAddr, s.acme != nil)
329 332 if err != nil {
330 333 closeSSH()
331 return fmt.Errorf("http listen %s: %w", s.Cfg.HTTPAddr, err)
334 return err
332 335 }
333 336
334 337 httpSrv := &http.Server{
@@ -346,16 +349,9 @@ func (s *Server) Run(ctx context.Context) error {
346 349 MaxHeaderBytes: 64 << 10,
347 350 IdleTimeout: 120 * time.Second,
348 351 }
349 var httpsLn net.Listener
350 352 var httpsSrv *http.Server
351 353 if s.acme != nil {
352 354 httpSrv.Handler = s.acme.httpHandler()
353 httpsLn, err = net.Listen("tcp", s.Cfg.HTTPSAddr)
354 if err != nil {
355 httpLn.Close()
356 closeSSH()
357 return fmt.Errorf("https listen %s: %w", s.Cfg.HTTPSAddr, err)
358 }
359 355 httpsSrv = &http.Server{
360 356 Handler: s.Handler(),
361 357 TLSConfig: s.acme.tlsConfig(),