Phase 9: application services and admin completion
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
Implements PLAN.md Phase 9. internal/appservice reads registration files (appservice.config_files), matches namespaces the way Synapse does (anchored at the start), and delivers events to each service as transactions read from the roomserver's event stream at a cursor kept in appservice_state. A transaction in flight is recorded, so after a restart it is resent under the same ID; failures back off from 2s to 5m, and a successful ping cuts the backoff short. In the Client-Server API an as_token acts as the service's sender or, with ?user_id=, as any existing user in its namespace. Services register and log in their users with m.login.application_service; exclusive user and alias namespaces are refused to everybody else with M_EXCLUSIVE. Unknown aliases and users in a namespace are asked of the service first. The ping endpoint reports M_URL_NOT_SET, M_BAD_STATUS, M_CONNECTION_FAILED and M_CONNECTION_TIMEOUT. Services' own requests, and their users' when rate_limited is false, skip the rate limiter. Users can change their password (POST /account/password) and deactivate their account (POST /account/deactivate), both behind the password. Deactivation revokes tokens, deletes devices, optionally erases the profile and leaves every room through a new userapi.AccountObserver. The admin API is complete: user detail, the admin flag, deactivation and reactivation, password resets, devices, media quotas (media.max_user_storage_bytes plus per-user overrides), registration tokens with use limits and expiry (registration.require_token), server notices (internal/servernotices, server_notices.*), an editor for the federation allow/deny lists persisted in server_settings, a delivery view of the application services, and an audit log of every change. Migration 0011 adds the registration token, server notice room, media quota, audit log and appservice cursor tables. Policy lists are now returned sorted. The Complement entrypoint loads the registrations Complement mounts in /complement/appservice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b507753172
commit
a94794b866
69 files changed
+6922
-124
No files matched your search
@@ -17,6 +17,7 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/dariuszjaniak/warp/server/internal/appservice"
|
||||
"github.com/dariuszjaniak/warp/server/internal/config"
|
||||
"github.com/dariuszjaniak/warp/server/internal/federation"
|
||||
"github.com/dariuszjaniak/warp/server/internal/httputil"
|
||||
@@ -44,7 +45,8 @@ type ClientAPI struct {
|
||||
settings *settings.Service
|
||||
federation *federation.Gate
|
||||
remoteProfile RemoteProfiles
|
||||
registration config.Registration
|
||||
regTokens *userapi.RegistrationTokens
|
||||
appservices *appservice.API
|
||||
log *slog.Logger
|
||||
now func() time.Time
|
||||
|
||||
@@ -127,6 +129,15 @@ type Options struct {
|
||||
// Registration is the file configuration of the registration flow.
|
||||
Registration config.Registration
|
||||
|
||||
// RegistrationTokens answers the m.login.registration_token stage.
|
||||
// Nil builds one from Registration's static tokens alone.
|
||||
RegistrationTokens *userapi.RegistrationTokens
|
||||
|
||||
// AppServices is the application service component: who may act as
|
||||
// whom, the exclusive namespaces, and the queries. Nil means no
|
||||
// application services are registered.
|
||||
AppServices *appservice.API
|
||||
|
||||
// RateLimit configures the per-endpoint buckets.
|
||||
RateLimit config.RateLimit
|
||||
|
||||
@@ -159,6 +170,20 @@ func New(opts Options) (*ClientAPI, error) {
|
||||
if opts.Now == nil {
|
||||
opts.Now = time.Now
|
||||
}
|
||||
if opts.RegistrationTokens == nil {
|
||||
now := opts.Now
|
||||
opts.RegistrationTokens = userapi.NewRegistrationTokens(userapi.RegistrationTokensOptions{
|
||||
Static: opts.Registration.Tokens,
|
||||
Required: opts.Registration.RequireToken,
|
||||
NowMS: func() int64 { return now().UnixMilli() },
|
||||
})
|
||||
}
|
||||
if opts.AppServices == nil {
|
||||
var err error
|
||||
if opts.AppServices, err = appservice.New(appservice.Options{Logger: opts.Logger}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
c := &ClientAPI{
|
||||
serverName: opts.ServerName,
|
||||
@@ -173,7 +198,8 @@ func New(opts Options) (*ClientAPI, error) {
|
||||
settings: opts.Settings,
|
||||
federation: opts.Federation,
|
||||
remoteProfile: opts.RemoteProfiles,
|
||||
registration: opts.Registration,
|
||||
regTokens: opts.RegistrationTokens,
|
||||
appservices: opts.AppServices,
|
||||
log: opts.Logger,
|
||||
now: opts.Now,
|
||||
uia: newUIAStore(uiaSessionTTL, opts.Now),
|
||||
@@ -232,6 +258,13 @@ func (c *ClientAPI) RegisterRoutes(r *httputil.Router) {
|
||||
|
||||
// Account.
|
||||
c.authed(r, "GET "+v3+"/account/whoami", c.limitDefault, c.handleWhoami)
|
||||
c.authed(r, "POST "+v3+"/account/password", c.limitLogin, c.handleChangePassword)
|
||||
c.authed(r, "POST "+v3+"/account/deactivate", c.limitLogin, c.handleDeactivate)
|
||||
|
||||
// Application services. The ping is the service checking that this
|
||||
// server can reach it, so it is authenticated with the service's own
|
||||
// token.
|
||||
c.authed(r, "POST "+v1+"/appservice/{appserviceID}/ping", c.limitDefault, c.handleAppServicePing)
|
||||
c.authed(r, "GET "+v3+"/capabilities", c.limitDefault, c.handleCapabilities)
|
||||
|
||||
// Devices.
|
||||
@@ -372,7 +405,7 @@ func (c *ClientAPI) registerRoomRoutes(r *httputil.Router) {
|
||||
|
||||
// public registers an endpoint that needs no access token.
|
||||
func (c *ClientAPI) public(r *httputil.Router, pattern string, limiter *ratelimit.Limiter, h httputil.Handler) {
|
||||
r.Handle(pattern, limiter.Middleware(c.clientIP)(httputil.Wrap(h)))
|
||||
r.Handle(pattern, limiter.MiddlewareUnless(c.clientIP, c.rateLimitExempt)(httputil.Wrap(h)))
|
||||
}
|
||||
|
||||
// authed registers an endpoint that needs one.
|
||||
@@ -381,5 +414,5 @@ func (c *ClientAPI) public(r *httputil.Router, pattern string, limiter *ratelimi
|
||||
// it runs before the token is resolved, and a limiter that had to hit the
|
||||
// database to find its own key would be a denial of service of its own.
|
||||
func (c *ClientAPI) authed(r *httputil.Router, pattern string, limiter *ratelimit.Limiter, h AuthedHandler) {
|
||||
r.Handle(pattern, limiter.Middleware(c.clientIP)(httputil.Wrap(c.withAuth(h))))
|
||||
r.Handle(pattern, limiter.MiddlewareUnless(c.clientIP, c.rateLimitExempt)(httputil.Wrap(c.withAuth(h))))
|
||||
}
|
||||
Reference in new issue
Block a user