CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
Archive-Schnittstellen-Vertragstests / contract-tests (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
AI-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
Archive-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (pull_request) Canceled after 0s
Archive-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Connect-Schnittstellen-Vertragstests / contract-tests (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
Workflow-Schnittstellen-Vertragstests / contract-tests (push) Canceled after 0s
Connect-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Canceled after 0s
Mail-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Mail-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
Workflow-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Canceled after 0s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Canceled after 0s
CI / Web (dms-browser) (pull_request) Canceled after 0s
CI / Web (pdf-viewer) (pull_request) Canceled after 0s
CI / Web (shl) (pull_request) Canceled after 0s
Mail-Schnittstellen-Vertragstests / contract-tests (push) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Canceled after 0s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Canceled after 0s
Workflow-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Nur Pakete, deren Code ohne Kommentare/Importpfade byte-gleich ist: - httpclient: ai, connect (Root behaelt eigene Kopie wegen strengerem Waechtertest) - svcauth: archive, ai, workflow - auditclient: ai, connect, archive - tenantregistryclient: dms, ai, workflow (archive weicht ab, bleibt) - policyclient: mail, connect (dms weicht ab, bleibt) - httpharden: Root, archive (dms weicht ab, bleibt) - loadtest: mail, ai (archive, connect weichen ab, bleiben) go.mod (require + replace) fuer ai, connect, workflow; Pflichttest-Gates von ai/workflow und CI-Pfadfilter um common/ erweitert, damit die sicherheitskritischen Pakete (svcauth, tenantregistryclient) weiter gegated werden. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
107 lines
4.2 KiB
Go
107 lines
4.2 KiB
Go
package moduleadapter
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"gitea.perlbach24.de/scripte/nexarch/common/svcauth"
|
|
)
|
|
|
|
const (
|
|
// HeaderServiceToken ist der Header, mit dem sich ein Modul beim
|
|
// Registrieren als Dienst ausweist (wie bei /legal-hold, RET-13).
|
|
HeaderServiceToken = "X-Service-Token"
|
|
|
|
maxRegisterBodyBytes = 64 << 10
|
|
)
|
|
|
|
// RegisterConfig steuert die Absicherung von POST /register (QA-15 F-08).
|
|
// ServiceToken: ist es gesetzt, verlangt /register den Header X-Service-Token.
|
|
// Ohne Token antwortet /register 503 (fail closed), ausser
|
|
// AllowUnauthenticated ist ausdruecklich gesetzt (Uebergang, mit Warnlog).
|
|
// Callback legt fest, welche Rueckruf-Adressen registriert werden duerfen.
|
|
type RegisterConfig struct {
|
|
ServiceToken string
|
|
AllowUnauthenticated bool
|
|
Callback CallbackPolicy
|
|
}
|
|
|
|
type registerRequest struct {
|
|
TenantSlug string `json:"tenant_slug"`
|
|
ModuleName string `json:"module_name"`
|
|
ObjectType string `json:"object_type"`
|
|
RetentionClass string `json:"retention_class"`
|
|
CallbackURL string `json:"callback_url"`
|
|
}
|
|
|
|
// RegisterHandler ist die REST-Schnittstelle (Ticket-Technikvorgabe), über
|
|
// die ein Modul einen Objekttyp registriert (Akzeptanzkriterium 1).
|
|
// POST /register mit JSON-Body {tenant_slug, module_name, object_type,
|
|
// retention_class, callback_url}. RET-12: verifiziert tenant_slug gegen
|
|
// verifier (Core-Tenant-Registry), bevor die Registrierung uebernommen
|
|
// wird - unabhaengig davon, was DMS/Mail selbst behaupten.
|
|
func RegisterHandler(pool *pgxpool.Pool, verifier TenantVerifier, cfg RegisterConfig) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
switch {
|
|
case cfg.ServiceToken != "":
|
|
if !svcauth.Equal(r.Header.Get(HeaderServiceToken), cfg.ServiceToken) {
|
|
log.Printf("moduleadapter: registrierung ohne gueltiges service-token abgelehnt")
|
|
http.Error(w, "nicht autorisiert", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
case cfg.AllowUnauthenticated:
|
|
log.Printf("moduleadapter: WARNUNG: registrierung ohne dienstauthentifizierung angenommen (NEXARCH_MODULEADAPTER_ALLOW_UNAUTHENTICATED)")
|
|
default:
|
|
log.Printf("moduleadapter: registrierung abgelehnt, kein service-token konfiguriert")
|
|
http.Error(w, "registrierung nicht konfiguriert", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
var req registerRequest
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxRegisterBodyBytes)
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
http.Error(w, "ungültiger request-body", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if req.TenantSlug == "" || req.ModuleName == "" || req.ObjectType == "" || req.RetentionClass == "" || req.CallbackURL == "" {
|
|
http.Error(w, "tenant_slug, module_name, object_type, retention_class und callback_url sind pflichtfelder", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
if err := cfg.Callback.ValidateCallbackURL(r.Context(), req.CallbackURL); err != nil {
|
|
log.Printf("moduleadapter: registrierung abgelehnt modul=%s objekttyp=%s: %v", req.ModuleName, req.ObjectType, err)
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
valid, err := verifier.VerifyTenant(r.Context(), req.TenantSlug)
|
|
if err != nil {
|
|
log.Printf("moduleadapter: tenant-verifikation fehlgeschlagen fuer modul=%s tenant=%s objekttyp=%s: %v", req.ModuleName, req.TenantSlug, req.ObjectType, err)
|
|
http.Error(w, "tenant-verifikation nicht moeglich", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
if !valid {
|
|
log.Printf("moduleadapter: registrierung abgelehnt - unbekannter tenant-kontext modul=%s tenant=%s objekttyp=%s", req.ModuleName, req.TenantSlug, req.ObjectType)
|
|
http.Error(w, "unbekannter tenant-kontext", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
reg, err := Register(r.Context(), pool, req.TenantSlug, req.ModuleName, req.ObjectType, req.RetentionClass, req.CallbackURL)
|
|
if err != nil {
|
|
log.Printf("moduleadapter: registrierung speichern: %v", err)
|
|
http.Error(w, "interner fehler", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
_ = json.NewEncoder(w).Encode(reg)
|
|
}
|
|
}
|