Learn AuthGuard/CarrierNode URLs from ProjectConfigurator's push
Lint / Lint (push) Successful in 39s
Tests / Go backend (push) Successful in 42s
Tests / Dashboard checks (push) Successful in 46s
Docker / Docker Build & Push (push) Successful in 3m37s

Adds the receiving end of ProjectConfigurator's core-services push
(PUT /api/core-services/internal, X-Internal-Auth-gated) via the shared
coreconfig package, so this service's AUTHGUARD_URL/CARRIERNODE_URL env
vars become just the bootstrap/fallback value instead of the permanent
source of truth. authclient.Client gains a concurrency-safe SetBaseURL
so a later push retargets it in place with no restart.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-10 11:56:17 +02:00
1 parent 20e9461d46
commit 7c4a903f59
7 files changed
+323 -11

No files matched your search

+14
View File
@@ -18,6 +18,20 @@ COOKIE_SECURE=false
# Only run without it for local development or a deployment you are certain
# does not need access control.
# Base URL of a CarrierNode instance, for the generic per-project mount API
# (not used by any feature here yet).
# CARRIERNODE_URL=https://carrier.example.com
# Shared secret CarrierNode and ProjectConfigurator were also configured with,
# sent/checked as X-Internal-Auth. AUTHGUARD_URL and CARRIERNODE_URL above are
# only the bootstrap fallback: once this project is registered in
# ProjectConfigurator's Projects workspace, it pushes both values here
# automatically (PUT /api/core-services/internal) and keeps them current --
# see Core/ProjectConfigurator/README.md's "Pushing core service info to
# other projects". That push is itself authenticated with this secret, so it
# still needs to be set even though AUTHGUARD_URL/CARRIERNODE_URL don't.
# INTERNAL_SERVICE_SECRET=
#################################################################
# PostgreSQL configuration
#################################################################
+37 -4
View File
@@ -17,6 +17,8 @@ import (
_ "github.com/joho/godotenv/autoload"
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
"repos.gfranz.ch/Gabriel20xx/shared/backend/carriernodeclient"
"repos.gfranz.ch/Gabriel20xx/shared/backend/coreconfig"
)
// The SvelteKit build is copied here by the Docker builder before go build.
@@ -27,9 +29,12 @@ import (
var webFS embed.FS
type Server struct {
db *DB
auth *AuthService
startTime time.Time
db *DB
auth *AuthService
startTime time.Time
internalServiceSecret string
coreConfig *coreconfig.Store
carrierNode *carriernodeclient.Client
}
func main() {
@@ -65,8 +70,33 @@ func main() {
fmt.Println("auth: DISABLED (AUTHGUARD_URL not set) -- every request is treated as authenticated")
}
// coreConfig holds the AuthGuard/CarrierNode URLs ProjectConfigurator pushes once this project
// is registered there (PUT /api/core-services/internal, see registerRoutes) -- AUTHGUARD_URL and
// CARRIERNODE_URL above/below are only the bootstrap fallback used until the first push arrives.
// See Core/ProjectConfigurator/README.md's "Pushing core service info to other projects".
internalServiceSecret := strings.TrimSpace(os.Getenv("INTERNAL_SERVICE_SECRET"))
carrierNodeURL := strings.TrimSpace(os.Getenv("CARRIERNODE_URL"))
coreConfig := coreconfig.NewStore(coreconfig.Info{AuthGuardURL: authGuardURL, CarrierNodeURL: carrierNodeURL})
if authGuard != nil {
coreConfig.OnUpdate(func(info coreconfig.Info) {
if info.AuthGuardURL != "" {
authGuard.SetBaseURL(info.AuthGuardURL)
}
})
}
carrierNode := carriernodeclient.New(internalServiceSecret, func(context.Context) string {
return coreConfig.CarrierNodeURL()
})
auth := newAuthService(authGuard, database, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"))
server := &Server{db: database, auth: auth, startTime: time.Now()}
server := &Server{
db: database,
auth: auth,
startTime: time.Now(),
internalServiceSecret: internalServiceSecret,
coreConfig: coreConfig,
carrierNode: carrierNode,
}
webRoot, err := fs.Sub(webFS, "web")
if err != nil {
@@ -132,6 +162,9 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
// Health and auth bootstrap routes are intentionally public.
mux.HandleFunc("GET /health", s.handleHealth)
mux.HandleFunc("GET /api/info", s.handleInfo)
// X-Internal-Auth-gated, not browser-session-gated -- ProjectConfigurator calls this directly
// to push a fresh AuthGuard/CarrierNode URL (see coreConfig's construction in main above).
mux.Handle("PUT /api/core-services/internal", coreconfig.Handler(s.internalServiceSecret, s.coreConfig))
mux.HandleFunc("GET /api/auth/status", s.auth.handleStatus)
mux.HandleFunc("POST /api/auth/setup", s.auth.handleSetup)
mux.HandleFunc("POST /api/auth/login", s.auth.handleLogin)