mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-25 07:09:11 +00:00
Sign-in - One sign-in path (SignInService) for password, 2FA, recovery code, signup and OIDC. It emits puter.signin.attempt (before the account lookup on POST /login), puter.signin.validate (before the session is created) and puter.signin. Listeners can refuse or require phone or card verification; a listener that throws is ignored. - POST /login keeps a wrong-password budget per account across all networks, 20 an hour and 50 a day. A browser that has signed in to the account before is not refused, and the budget belongs to the current password. - An account unused for dormantSignInDays (default 180) confirms an unconfirmed email at sign-in, where the deployment can send mail. - New account emails: sign-in from a new browser, sign-in attempts blocked, password reset completed. - pwnedPasswords (off by default): a k-anonymity range lookup after a successful password sign-in, with a notice to the owner. - requestSignalHeaders and requestSignalValue turn configured request headers into req.requestSignals and a puter.request.flagged event. Sessions - web and app sessions end after 180 days without activity; accounts with no password and no email keep 365 days. A missing expiry on web, app and asset rows no longer means no expiry, and ended rows are purged. - The cookie a private hosted site sets from ?auth_token= is tied to the token's session row and carries a 7-day expiry. Email confirmation codes - A 6-digit code is valid for 60 minutes and has a wrong-code budget. Mailbox ingress - email.ingress.validate runs before a message is stored; a listener can refuse it or record a sender check. X-Puter-Sender-Auth is written by the server only. Header blocks over 256 KiB are refused. GUI - Login sends the device fingerprint, can show the captcha widget (gui_params.turnstileLogin), offers a password reset when sign-in is locked, and runs pending verification windows after a popup sign-in or signup.
180 lines
8.3 KiB
TypeScript
180 lines
8.3 KiB
TypeScript
/*
|
|
* Copyright (C) 2024-present Puter Technologies Inc.
|
|
*
|
|
* This file is part of Puter.
|
|
*
|
|
* Puter is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import { AppOriginBlocklistService } from './abuse/AppOriginBlocklistService';
|
|
import { AlarmCallService } from './alarm/AlarmCallService';
|
|
import { ACLService } from './acl/ACLService';
|
|
import { AppIconService } from './appIcon/AppIconService';
|
|
import { AppPermissionService } from './apps/AppPermissionService';
|
|
import { AppService } from './apps/AppService';
|
|
import { RecommendedAppsService } from './apps/RecommendedAppsService';
|
|
import { SuggestedAppsService } from './apps/SuggestedAppsService';
|
|
import { AuthService } from './auth/AuthService';
|
|
import { OIDCService } from './auth/OIDCService';
|
|
import { SignInService } from './auth/SignInService';
|
|
import { TokenService } from './auth/TokenService';
|
|
import { BroadcastService } from './broadcast/BroadcastService';
|
|
import { CacheReplicationService } from './cache/CacheReplicationService';
|
|
import { EventForwardService } from './events/EventForwardService';
|
|
import { EventsService } from './events/EventsService';
|
|
import { AppFeedbackService } from './feedback/AppFeedbackService';
|
|
import { FSService } from './fs/FSService';
|
|
import { KvShareService } from './kvShare/KvShareService';
|
|
import { ServerHealthService } from './health/ServerHealthService';
|
|
import { PuterHomepageService } from './homepage/PuterHomepageService';
|
|
import { JobScheduler } from './jobs/JobScheduler';
|
|
import { LocalWorkerService } from './localworker/LocalWorkerService';
|
|
import { MeteringService } from './metering/MeteringService';
|
|
import { NotificationService } from './notification/NotificationService';
|
|
import { PermissionService } from './permission/PermissionService';
|
|
import { ProfileService } from './profile/ProfileService';
|
|
import { OpenAIRealtimeRelayService } from './realtime/OpenAIRealtimeRelayService';
|
|
import { DefaultUserService } from './selfhosted/DefaultUserService';
|
|
import { ShareNotificationService } from './share/ShareNotificationService';
|
|
import { ShareService } from './share/ShareService';
|
|
import { SocketService } from './socket/SocketService';
|
|
import { SubdomainPermissionService } from './subdomain/SubdomainPermissionService';
|
|
import type { IPuterServiceRegistry } from './types';
|
|
import { SignupService } from './user/SignupService';
|
|
import { UserAccountService } from './user/UserAccountService';
|
|
|
|
/**
|
|
* Populate `IPuterServiceInstances` (declared in `./types`) with the concrete
|
|
* types of built-in services. Done via declaration merging instead of
|
|
* `LayerInstances<typeof puterServices>` because every concrete service extends
|
|
* `PuterService`, whose `protected services` field references this type — a
|
|
* direct `typeof puterServices` lookup would self-cycle.
|
|
*/
|
|
declare module './types' {
|
|
interface IPuterServiceInstances {
|
|
jobs: JobScheduler;
|
|
metering: MeteringService;
|
|
appOriginBlocklist: AppOriginBlocklistService;
|
|
permission: PermissionService;
|
|
acl: ACLService;
|
|
share: ShareService;
|
|
shareNotification: ShareNotificationService;
|
|
profile: ProfileService;
|
|
token: TokenService;
|
|
auth: AuthService;
|
|
fs: FSService;
|
|
appPermission: AppPermissionService;
|
|
subdomainPermission: SubdomainPermissionService;
|
|
recommendedApps: RecommendedAppsService;
|
|
suggestedApps: SuggestedAppsService;
|
|
app: AppService;
|
|
socket: SocketService;
|
|
kvShare: KvShareService;
|
|
events: EventsService;
|
|
eventForward: EventForwardService;
|
|
notification: NotificationService;
|
|
appFeedback: AppFeedbackService;
|
|
broadcast: BroadcastService;
|
|
cacheReplication: CacheReplicationService;
|
|
oidc: OIDCService;
|
|
appIcon: AppIconService;
|
|
defaultUser: DefaultUserService;
|
|
homepage: PuterHomepageService;
|
|
health: ServerHealthService;
|
|
userAccount: UserAccountService;
|
|
signup: SignupService;
|
|
signIn: SignInService;
|
|
openaiRealtime: OpenAIRealtimeRelayService;
|
|
alarmCalls: AlarmCallService;
|
|
}
|
|
}
|
|
|
|
// Ordering matters: services declared later see earlier ones as peers.
|
|
// ACLService depends on PermissionService (for scan + grant/revoke), so
|
|
// PermissionService must be constructed first.
|
|
// AuthService depends on TokenService (JWT verify).
|
|
// FSService constructs its own internal repo + S3 provider in onServerStart.
|
|
// SocketService depends on AuthService (for handshake auth).
|
|
// NotificationService depends on notification store (for DB) + event client (for socket push).
|
|
// BroadcastService is independent — only needs the event client.
|
|
export const puterServices = {
|
|
// First, so every later service can register jobs with it. Reaches
|
|
// `broadcast` at call time only.
|
|
jobs: JobScheduler,
|
|
metering: MeteringService,
|
|
// Declared before `auth` so AuthService sees it as a prior peer — it
|
|
// queries the blocklist on app-token acquisition and per-request app
|
|
// token validation.
|
|
appOriginBlocklist: AppOriginBlocklistService,
|
|
permission: PermissionService,
|
|
acl: ACLService,
|
|
token: TokenService,
|
|
auth: AuthService,
|
|
fs: FSService,
|
|
// Needs acl (setUserUser), permission (canManagePermission) and fs
|
|
// (ancestor chains), so it follows all three.
|
|
share: ShareService,
|
|
// Delivery only; it reaches `notification` at call time, so its position
|
|
// relative to that service does not matter.
|
|
shareNotification: ShareNotificationService,
|
|
// Reads and writes profile files through `fs` and asks `metering` about
|
|
// the owner's plan, so it follows both.
|
|
profile: ProfileService,
|
|
// Declared after `fs` — account teardown tears the user's filesystem down
|
|
// first.
|
|
userAccount: UserAccountService,
|
|
// Reaches `team` and `socket` at call time only.
|
|
signup: SignupService,
|
|
// Reaches `signup` at call time only.
|
|
signIn: SignInService,
|
|
// AppPermissionService + SubdomainPermissionService register permission
|
|
// rewriters/implicators only; no runtime state. Placed after fsEntry so
|
|
// the FS rewriter runs first for `fs:/path` → `fs:<uuid>` before any
|
|
// downstream check that might chain app-root-dir → fs.
|
|
appPermission: AppPermissionService,
|
|
subdomainPermission: SubdomainPermissionService,
|
|
recommendedApps: RecommendedAppsService,
|
|
suggestedApps: SuggestedAppsService,
|
|
// Reaches `auth` and `permission` at call time only.
|
|
app: AppService,
|
|
socket: SocketService,
|
|
// Registers the share-grant implicators with `permission`, and reaches
|
|
// `permission`, `metering` and `notification` at call time only.
|
|
kvShare: KvShareService,
|
|
// Delivers through `socket` and resolves paths through `fs`, so it follows
|
|
// both; `fs` reaches back for dispatch at call time only.
|
|
events: EventsService,
|
|
notification: NotificationService,
|
|
// Declared after `auth` (origin → app uid resolution happens through
|
|
// AuthService.appUidFromOrigin).
|
|
appFeedback: AppFeedbackService,
|
|
broadcast: BroadcastService,
|
|
// Forwards through `broadcast` and puts deliveries down through `socket`,
|
|
// so it follows both; `events` reaches it at call time only.
|
|
eventForward: EventForwardService,
|
|
// Independent — only needs the event client and redis.
|
|
cacheReplication: CacheReplicationService,
|
|
oidc: OIDCService,
|
|
appIcon: AppIconService,
|
|
defaultUser: DefaultUserService,
|
|
homepage: PuterHomepageService,
|
|
// Health comes after socket so its default `socket-initialized`
|
|
// check can reference the peer.
|
|
health: ServerHealthService,
|
|
localworkerservice: LocalWorkerService,
|
|
// Authenticates through `auth` and meters through `metering`.
|
|
openaiRealtime: OpenAIRealtimeRelayService,
|
|
alarmCalls: AlarmCallService,
|
|
} satisfies IPuterServiceRegistry;
|