Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
407966fc94 | ||
|
|
ec82a8a8b9 |
No files matched your search
+4
-6
@@ -69,12 +69,10 @@ const (
|
||||
legacySessionCookieName = "collabtable_session"
|
||||
)
|
||||
|
||||
// collabTableAuthStore adapts *DB to sharedauth.ProxyStore. CollabTable never
|
||||
// had an independent "require login" toggle (a session was always required
|
||||
// whenever AUTHGUARD_URL was configured at all) so LoginRequired always
|
||||
// reports true and SetLoginRequired is a no-op -- server.go correspondingly
|
||||
// wires sharedauth.Service.Require rather than the *IfLoginRequired
|
||||
// middleware family. IsSetupClaimed/TryClaimSetup/UnclaimSetup delegate
|
||||
// collabTableAuthStore adapts *DB to sharedauth.ProxyStore. The login
|
||||
// requirement is runtime-controlled by ProjectConfigurator through
|
||||
// sharedauth.Service's internal endpoint; this store supplies the conservative
|
||||
// required-by-default fallback. IsSetupClaimed/TryClaimSetup/UnclaimSetup delegate
|
||||
// straight through to *DB's existing methods of the same name/signature (see
|
||||
// db.go), reusing the collabtable_setup_state table/queries verbatim.
|
||||
type collabTableAuthStore struct {
|
||||
|
||||
+16
-15
@@ -175,19 +175,20 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
|
||||
mux.HandleFunc("GET /api/auth/status", s.auth.Status)
|
||||
mux.HandleFunc("POST /api/auth/setup", s.auth.Signup)
|
||||
mux.HandleFunc("POST /api/auth/login", s.auth.Login)
|
||||
mux.Handle("POST /api/auth/logout", s.auth.Require(http.HandlerFunc(s.auth.Logout)))
|
||||
mux.Handle("POST /api/auth/credentials", s.auth.Require(http.HandlerFunc(s.auth.UpdateMe)))
|
||||
mux.Handle("GET /api/auth/users", s.auth.Require(http.HandlerFunc(s.auth.ManagedUsers)))
|
||||
mux.Handle("POST /api/auth/users", s.auth.Require(http.HandlerFunc(s.auth.ManagedCreateUser)))
|
||||
mux.Handle("PUT /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedUpdateUser)))
|
||||
mux.Handle("PATCH /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedUpdateUser)))
|
||||
mux.Handle("DELETE /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedDeleteUser)))
|
||||
mux.Handle("GET /api/auth/totp/status", s.auth.Require(http.HandlerFunc(s.auth.TOTPStatus)))
|
||||
mux.Handle("POST /api/auth/totp/setup", s.auth.Require(http.HandlerFunc(s.auth.TOTPInitiate)))
|
||||
mux.Handle("POST /api/auth/totp/enable", s.auth.Require(http.HandlerFunc(s.auth.TOTPVerify)))
|
||||
mux.Handle("POST /api/auth/totp/disable", s.auth.Require(http.HandlerFunc(s.auth.TOTPDisable)))
|
||||
mux.Handle("GET /api/auth/token/status", s.auth.Require(http.HandlerFunc(s.handleTokenStatus)))
|
||||
mux.Handle("POST /api/auth/token/regenerate", s.auth.Require(http.HandlerFunc(s.handleTokenRegenerate)))
|
||||
mux.Handle("PUT /api/auth/access/internal", s.auth.SetLoginRequiredInternal(s.internalServiceSecret))
|
||||
mux.Handle("POST /api/auth/logout", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.Logout)))
|
||||
mux.Handle("POST /api/auth/credentials", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.UpdateMe)))
|
||||
mux.Handle("GET /api/auth/users", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUsers)))
|
||||
mux.Handle("POST /api/auth/users", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedCreateUser)))
|
||||
mux.Handle("PUT /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUpdateUser)))
|
||||
mux.Handle("PATCH /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUpdateUser)))
|
||||
mux.Handle("DELETE /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedDeleteUser)))
|
||||
mux.Handle("GET /api/auth/totp/status", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPStatus)))
|
||||
mux.Handle("POST /api/auth/totp/setup", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPInitiate)))
|
||||
mux.Handle("POST /api/auth/totp/enable", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPVerify)))
|
||||
mux.Handle("POST /api/auth/totp/disable", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPDisable)))
|
||||
mux.Handle("GET /api/auth/token/status", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTokenStatus)))
|
||||
mux.Handle("POST /api/auth/token/regenerate", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTokenRegenerate)))
|
||||
|
||||
// Sync/collaboration API routes use a long-lived bearer token shared by the
|
||||
// user's devices. This is deliberately separate from browser sessions.
|
||||
@@ -217,8 +218,8 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
|
||||
|
||||
// The dashboard is a public SPA shell, but its data and tech-stack endpoints
|
||||
// are protected by the browser session.
|
||||
mux.Handle("GET /api/tech-stack", s.auth.Require(http.HandlerFunc(s.handleTechStack)))
|
||||
mux.Handle("GET /web/data", s.auth.Require(http.HandlerFunc(s.handleWebData)))
|
||||
mux.Handle("GET /api/tech-stack", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTechStack)))
|
||||
mux.Handle("GET /web/data", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleWebData)))
|
||||
mux.Handle("/", spaFileServer(webRoot))
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -276,6 +277,12 @@ type Service struct {
|
||||
// real base URL.
|
||||
authGuard *authclient.Client
|
||||
configurationError error
|
||||
// loginRequiredOverride is populated by the internal ProjectConfigurator
|
||||
// endpoint. Some legacy consumers intentionally use a no-op ProxyStore for
|
||||
// this setting because they historically had no local toggle; the live
|
||||
// override lets those services still honor the central setting immediately.
|
||||
loginRequiredMu sync.RWMutex
|
||||
loginRequiredOverride *bool
|
||||
}
|
||||
|
||||
// ServiceOption configures optional New/NewWithStore construction behavior.
|
||||
@@ -750,6 +757,15 @@ func (s *Service) AdminNeeded(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Service) LoginRequired(ctx context.Context) (bool, error) {
|
||||
s.loginRequiredMu.RLock()
|
||||
override := s.loginRequiredOverride
|
||||
s.loginRequiredMu.RUnlock()
|
||||
if override != nil {
|
||||
return *override, nil
|
||||
}
|
||||
if s.store == nil {
|
||||
return true, nil
|
||||
}
|
||||
return s.store.LoginRequired(ctx)
|
||||
}
|
||||
|
||||
@@ -783,7 +799,40 @@ func (s *Service) UpdateAccessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// central "Require Login" toggle (ConfigWorkspace.svelte's loginControls) apply here without an
|
||||
// admin session of its own.
|
||||
func (s *Service) SetLoginRequired(ctx context.Context, required bool) error {
|
||||
return s.store.SetLoginRequired(ctx, required)
|
||||
if s.store != nil {
|
||||
if err := s.store.SetLoginRequired(ctx, required); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.loginRequiredMu.Lock()
|
||||
s.loginRequiredOverride = &required
|
||||
s.loginRequiredMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetLoginRequiredInternal returns the X-Internal-Auth-gated handler used by
|
||||
// ProjectConfigurator to apply its per-project "Require Login" setting. It
|
||||
// lives on the shared service so projects outside the core-service family can
|
||||
// expose the same propagation endpoint without duplicating its JSON handling.
|
||||
func (s *Service) SetLoginRequiredInternal(secret string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.TrimSpace(secret) == "" || r.Header.Get("X-Internal-Auth") != secret {
|
||||
writeProxyError(w, http.StatusUnauthorized, "internal service authentication required")
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
LoginRequired *bool `json:"loginRequired"`
|
||||
}
|
||||
if err := decodeProxyJSON(r, &input); err != nil || input.LoginRequired == nil {
|
||||
writeProxyError(w, http.StatusBadRequest, "loginRequired must be a boolean")
|
||||
return
|
||||
}
|
||||
if err := s.SetLoginRequired(r.Context(), *input.LoginRequired); err != nil {
|
||||
writeProxyError(w, http.StatusInternalServerError, "access setting could not be saved")
|
||||
return
|
||||
}
|
||||
writeProxyJSON(w, http.StatusOK, map[string]bool{"loginRequired": *input.LoginRequired})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) Status(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -32,6 +32,10 @@ func (s *fakeProxyStore) UnclaimSetup(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type noOpLoginProxyStore struct{ fakeProxyStore }
|
||||
|
||||
func (s *noOpLoginProxyStore) SetLoginRequired(context.Context, bool) error { return nil }
|
||||
|
||||
// TestPendingModeStillGatesRequests locks in the fix that made an empty
|
||||
// authGuardURL at construction mean "pending" (auth still enabled, calls
|
||||
// fail closed until a real URL arrives via SetAuthGuardBaseURL) instead of
|
||||
@@ -91,6 +95,19 @@ func TestLoginDisabledUsesAdminIdentityWithoutCredentials(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalLoginOverrideWorksWithNoOpStore(t *testing.T) {
|
||||
store := &noOpLoginProxyStore{fakeProxyStore: fakeProxyStore{loginRequired: true}}
|
||||
service := NewWithStore(store, "session", false, "", "testproject")
|
||||
if err := service.SetLoginRequired(context.Background(), false); err != nil {
|
||||
t.Fatalf("SetLoginRequired() error = %v", err)
|
||||
}
|
||||
|
||||
user, err := service.CurrentUser(httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
if err != nil || user == nil || user.Username != "Admin" {
|
||||
t.Fatalf("no-op store override resolved user=%+v err=%v, want Admin", user, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxyCredentials(t *testing.T) {
|
||||
email, username, password, err := normalizeProxyCredentials(" User@Example.com ", "user", "correct horse battery staple")
|
||||
if err != nil {
|
||||
|
||||
@@ -123,6 +123,11 @@
|
||||
editUser.projects = checked ? [...current, key] : current.filter((project) => project !== key);
|
||||
}
|
||||
|
||||
function toggleNewProject(key: string, checked: boolean): void {
|
||||
const current = newUser.projects ?? [];
|
||||
newUser.projects = checked ? [...current, key] : current.filter((project) => project !== key);
|
||||
}
|
||||
|
||||
function projectLabel(key: string): string {
|
||||
return projects?.find((project) => project.key === key)?.label ?? key;
|
||||
}
|
||||
@@ -198,6 +203,21 @@
|
||||
{#if canAssignAdmin}<option value="admin">Admin</option>{/if}
|
||||
</select>
|
||||
</div>
|
||||
{#if projects && projects.length > 0}
|
||||
<fieldset class="sc-user-projects">
|
||||
<legend>Projects (none checked = all projects)</legend>
|
||||
{#each projects as project (project.key)}
|
||||
<label class="sc-user-project-option">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={(newUser.projects ?? []).includes(project.key)}
|
||||
onchange={(event) => toggleNewProject(project.key, event.currentTarget.checked)}
|
||||
/>
|
||||
{project.label}
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
{/if}
|
||||
<div class="sc-form-actions"><Button disabled={saving} type="submit">Add user</Button></div>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -85,6 +85,12 @@ export interface UserCreateInput {
|
||||
email: string;
|
||||
password: string;
|
||||
role?: UserRole;
|
||||
/**
|
||||
* Project keys this new account is restricted to. An empty array means
|
||||
* unrestricted; omitted when the host application does not expose project
|
||||
* scoping.
|
||||
*/
|
||||
projects?: string[];
|
||||
}
|
||||
|
||||
export interface UserUpdateInput {
|
||||
|
||||
Reference in new issue
Block a user