From 704ac61a271f57c41ed8b99aa6b8e45cf761018c Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Sun, 1 Nov 2026 19:31:17 +0100 Subject: [PATCH] ca intermediate: the renewal hint names the region's HTTPS address, not loopback Co-Authored-By: Claude Opus 5.5 --- cmd/rollcall/intermediates.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/rollcall/intermediates.go b/cmd/rollcall/intermediates.go index 872094d..0c0a07d 100644 --- a/cmd/rollcall/intermediates.go +++ b/cmd/rollcall/intermediates.go @@ -30,6 +30,7 @@ import ( "math" "net" "net/http" + "net/url" "os" "path/filepath" "regexp" @@ -374,7 +375,7 @@ func caIntermediateCmd(name string, args []string) error { return err } fmt.Printf("wrote %s.pem and %s.token in %s: intermediate CA %q until %s, may issue for %s\n", name, name, *out, name, res.NotAfter.Format("2006-01-02"), strings.Join(permits, " ")) - fmt.Printf("the region renews it: on the host with its key, install deploy/rollcall-intermediate-renew with\n URL=%s NAME=%s TOKEN_FILE=<%s.token there> CERT= KEY=\n", c.base, name, name) + fmt.Printf("the region renews it: on the host with its key, install deploy/rollcall-intermediate-renew with\n URL=%s NAME=%s TOKEN_FILE=<%s.token there> CERT= KEY=\n", regionHTTPS(c.base), name, name) return nil } @@ -399,3 +400,26 @@ func caIntermediatesCmd() error { } return tw.Flush() } + +// regionHTTPS: the region's HTTPS address for another host, when the CLI +// talks to it over loopback HTTP on the region itself +func regionHTTPS(base string) string { + if !strings.HasPrefix(base, "http://") { + return base + } + cfg, err := loadConfig(envOr("ROLLCALL_CONFIG", "/etc/rollcall/config.json")) + if err != nil || cfg.TLSListen == "" { + return base + } + u, err := url.Parse(cfg.ServerURL) + if err != nil || u.Hostname() == "" { + return base + } + host := u.Hostname() + if _, port, _ := net.SplitHostPort(cfg.TLSListen); port != "" && port != "443" { + host = net.JoinHostPort(host, port) + } else if strings.Contains(host, ":") { + host = "[" + host + "]" + } + return "https://" + host +}