fix(sites): let the ask endpoint approve the news host (#141)

news.bbs.profullstack.com has its own Caddy site block so Caddy can get
it a Let's Encrypt cert for NNTPS on :563. But it also falls under the
*.bbs.profullstack.com on-demand-TLS block, so Caddy asks agentbbs before
issuing, and the ask handler only approved members and mapped custom
domains. "news" is neither, so it got a 404 and never got a cert. The
news-certs timer then failed forever, and :563 kept serving the
self-signed bootstrap cert, which expired on 2026-09-12.

The handler now also approves the BBS's own service hosts. For now that
is only AGENTBBS_NEWS_HOST. Arbitrary names still 404, so this is still
not an open cert relay.

Co-authored-by: riotcoder <riotcoder@profullstack.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-05 22:21:56 -07:00 • committed by GitHub
parent 7d86e0ad1e
commit 6b5ce8f4be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View file

@ -49,6 +49,11 @@ type Manager struct {
usersDir string // <data>/users
domDir string // <data>/domains (the symlink farm Caddy serves)
baseHost string // AGENTBBS_HOST, e.g. bbs.profullstack.com (for <name>.<host>)
// Hosts the BBS itself serves under the *.<baseHost> wildcard, which Caddy
// therefore routes through on-demand TLS too (news.bbs.profullstack.com).
// They are not members, so without this the ask query 404s them and they
// never get a certificate.
serviceHosts map[string]struct{}
}
// NewManager prepares the symlink farm under dataDir/domains.
@ -57,11 +62,16 @@ func NewManager(st store.Store, dataDir string) (*Manager, error) {
if err := os.MkdirAll(domDir, 0o755); err != nil {
return nil, err
}
svc := map[string]struct{}{}
if h := Normalize(os.Getenv("AGENTBBS_NEWS_HOST")); h != "" {
svc[h] = struct{}{}
}
return &Manager{
st: st,
usersDir: filepath.Join(dataDir, "users"),
domDir: domDir,
baseHost: strings.ToLower(strings.TrimSpace(os.Getenv("AGENTBBS_HOST"))),
st: st,
usersDir: filepath.Join(dataDir, "users"),
domDir: domDir,
baseHost: strings.ToLower(strings.TrimSpace(os.Getenv("AGENTBBS_HOST"))),
serviceHosts: svc,
}, nil
}
@ -159,6 +169,10 @@ func (m *Manager) AskHandler() http.Handler {
http.Error(w, "bad domain", http.StatusBadRequest)
return
}
if _, ok := m.serviceHosts[d]; ok {
w.WriteHeader(http.StatusOK)
return
}
// Free user-homepage subdomain: <name>.<baseHost> for any registered
// member (e.g. alice.bbs.profullstack.com). Single label only.
if m.baseHost != "" && strings.HasSuffix(d, "."+m.baseHost) {

View file

@ -205,6 +205,7 @@ func TestSyncRemovesStaleDomainEntries(t *testing.T) {
func TestAskUserSubdomain(t *testing.T) {
t.Setenv("AGENTBBS_HOST", "bbs.profullstack.com")
t.Setenv("AGENTBBS_NEWS_HOST", "news.bbs.profullstack.com")
dir := t.TempDir()
st, err := store.Open(filepath.Join(dir, "test.db"))
if err != nil {
@ -229,6 +230,7 @@ func TestAskUserSubdomain(t *testing.T) {
{"nobody.bbs.profullstack.com", http.StatusNotFound}, // no such user
{"a.b.bbs.profullstack.com", http.StatusNotFound}, // multi-label, not a user subdomain
{"bbs.profullstack.com", http.StatusNotFound}, // apex is not a user subdomain
{"news.bbs.profullstack.com", http.StatusOK}, // the BBS's own news host, not a member
} {
rec := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/check?domain="+c.domain, nil)