Commit Graph
515 Commits
Author SHA1 Message Date
Juan Denis 1205a2506d Use shared JWT helpers in 2FA tests
The new setup-endpoint tests minted tokens directly, which the
one-door ratchet rejects. They now use headers_for. The race path
for an already-confirmed user raises ConflictError instead of
returning a hand-shaped error body, so the inventory count stays
at 849. The setup route reads the optional regenerate flag through
json_object.
2026-11-26 02:55:32 -05:00
Juan Denis 9bb3672551 Reuse the pending 2FA setup secret
initiate_setup minted and committed a new secret on every call, so a
second Enable click, a double-click or reopening the setup window threw
away the secret the user had just scanned and the authenticator's code
never verified.

Reuse the unconfirmed secret unless none exists or the caller sends
{"regenerate": true}. The user row is locked for the call so concurrent
/auth/2fa/setup requests cannot both invent a secret. Confirmed users
still get 400 and are never rotated. TOTP parameters are unchanged.

Tests cover reuse, confirm with the reused secret, regenerate, the 400
for confirmed users, and the QR being built from the otpauth URI.
2026-11-26 02:38:47 -05:00
Juan Denis 2366d8b9bf Mount site adoption on the apps blueprint
The adoption routes added a blueprint to the curated core
registry, which is kept exact on purpose. They now register on
the existing apps blueprint as an area module, the way the
server area modules do, under /apps/host-sites.

The host-managed check becomes a function that compares the
attribute, so services handed a stand-in app object (as the
lifecycle tests do) get False instead of an AttributeError.
2026-11-22 02:44:27 -05:00
Juan Denis ebb19c8444 Read through services in the scoped routes
The workspace-scoped mobile and shared-variable routes queried
models in the controller, which the boundary inventory counts
as new crossings. They now go through WorkspaceService and
ManagedDatabaseService; the baseline drops the two crossings
the mobile routes no longer make.
2026-11-22 02:41:56 -05:00
Juan Denis 7768318e31 Raise typed errors from site adoption
The adoption routes shaped their own error bodies, which the
hand-shaped-error ratchet counts. The service now raises the
typed application errors and the global handler owns the body.
PHP_ETC_DIR stops reading the environment: nothing sets it.
2026-11-22 02:41:54 -05:00
Juan Denis 64181c5520 Hold workspace viewers to read-only on servers
GHSA-m72h-hc66-5jwx: server routes checked that the caller could
reach the server but not that they could write in its workspace,
so a member capped to viewer there could still re-pair the agent,
rename the server or edit its IP allow-list.

The write check now lives in the one helper every server route
resolves its server through, applied to mutating requests, so a
new route cannot forget it.
2026-11-22 02:30:16 -05:00
Juan Denis 1c6c43326e Authorize resolved shared-variable reads
GHSA-893r-j92f-5q9x: both resolved-variables routes took the
resource id, and the hierarchical one its workspace, project and
environment ids, straight from the query string and checked none
of them. Any account could name another workspace's id and read
its variable groups.

The caller must now be able to read the target resource and
every scope asked for; unknown resource types fail closed.
2026-11-22 02:30:14 -05:00
Juan Denis 60030b0b4e Keep backup hooks and app creation from viewers
GHSA-vrwv-j8w5-p94q: POST /apps took any authenticated account,
so a read-only viewer could create an app, own it, and set its
pre-backup hook, which the panel runs as a shell command on its
own host.

Creating a service now needs a developer or admin. Changing a
hook needs an admin, and the service refuses it by default, so
a new caller that forwards request data cannot hand out shell
access. Sending a hook back unchanged is not a change, so a
policy read by its owner still round-trips.
2026-11-22 02:30:11 -05:00
Juan Denis 4ba435243f Adopt sites already running on the host
A site set up by hand or by a migration serves traffic but has
no application, domain or WordPress row, so the panel cannot
see it. Every existing entry point creates something (a vhost,
a copy of the files), which is wrong for a site that is live.

Discovery reads the live nginx config, the PHP-FPM pools, the
certificate and wp-config.php. Adopting writes rows only, as a
dry run unless asked otherwise. The app is managed_by 'host',
and the vhost writer, drift repair, lifecycle and delete paths
leave its running config alone. The doctor reports sites nginx
serves that no application accounts for.

Part of #269.
2026-11-22 02:02:44 -05:00
Juan Denis 43c87cd5eb Scope fleet-wide server reads to the workspace
GHSA-qcjj-hf95-6rgw: the workspace check landed on every
<server_id> route, but the routes that list, search or export
across the fleet take no id in the path, so they kept answering
from unfiltered Server and ServerMetrics queries. Any account,
down to a viewer in no workspace, could enumerate other
workspaces' servers and read their metric history.

The fleet-monitor reads (heatmap, comparison, alerts, thresholds,
anomalies, search, both exports) and the mobile summary and
offline cache now take the caller and apply the rule GET /servers
uses. A sweep over every parameterless GET route found three more
of the same shape, fixed here too: the proxy overview, the
metrics retention stats, and server-group membership.
2026-11-22 01:44:59 -05:00
Juan Denis 4fa5caef79 Report services and domains per server
The server list could not say what a server carries. It now returns
services_count and domains_count for every row, computed for the whole
list in two queries and limited to the services the caller may see, so
a count never reveals something they have no access to.
2026-11-14 14:37:33 -05:00
Juan Denis e1972e7ee9 Store overview layouts as scoped boards
A user can now save the Overview layout of a kind of detail page
(server, service). It is an ordinary dashboard board whose slug names
the kind, so it reuses the existing storage, validation and ownership
rules and needs no new routes or migration: POST with a scope upserts
it, GET ?scope= reads it, DELETE returns to the shipped layout. Scoped
boards are never listed among the dashboard tabs.
2026-11-14 13:59:00 -05:00
Juan Denis 63b73c9fdb Merge dev into feat/ui-security-polish 2026-11-04 10:13:24 -05:00
Juan Denis c5a90e2c82 feat(extensions): solid update detection (builtin sources, trust hints, refresh, count) 2026-11-03 20:20:35 -05:00
Juan Denis 2802913419 fix(security): log instead of echoing exception text in sso, ssl, waf and buildpack routes 2026-11-03 13:10:27 -05:00
Juan Denis 60a5e0a18a fix(backups): answer 503 backup_dir_unavailable when the backup dir is not writable 2026-11-03 13:10:27 -05:00
Juan Denis 9b93cb34ef fix(backups): degrade gracefully when the backup dir is not accessible 2026-11-03 12:57:58 -05:00
Juan Denis dd9003d458 fix(security): replace bare excepts, stop leaking exception text
Bare excepts in sockets/servers/system now catch specific errors and log;
malformed metrics from/to returns 400. docker cleanup and update-check no
longer echo str(e).
2026-11-03 12:57:58 -05:00
Juan DenisandClaude Sonnet 5.5 0aab404e35 refactor(agents): raise typed errors from the report endpoint
Keeps the hand-shaped error-body ratchet at its ceiling.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:31:21 -05:00
Juan DenisandClaude Sonnet 5.5 a4d2ea37ef feat(agents): permission levels, signed report endpoint, health alerts
Agent-reported monitor/protect/full level (never settable from the panel),
POST /api/v1/agent/report for report-only agents, silence-based offline
detection, service-check alerts via MetricAlert, a panel-side command gate,
docs, and a demo seed script. Migration 112.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:04:58 -05:00
Juan Denis 2521da0e46 Add an SSH Access server permission profile
Faro access grants install keys through the agent's ssh:keys
actions. A locked-down server had no canned profile for that short
of Full Access; ssh_access grants ssh:keys:* plus the health reads.
2026-10-26 11:16:21 -04:00
Juan Denis a9668000da Keep the new route logic behind services
The SSL-enable and server-overview changes put session and query
calls in the routes, tripping the controller-boundary ratchet. Move
them into SiteDomainService and WorkspaceService, raise a typed error
for bad allowed_ips, point the ACME-contact test at the new vhost
door, and regenerate the baseline and inventory (476 -> 453).
2026-10-26 01:43:12 -04:00
Juan Denis 1fe8ada10d Look up agent registration tokens by digest
POST /servers/register needs no login and ran a slow PBKDF2 check
against every pending server per request, so a few IPs under the
5/min limit could keep the single worker's CPU busy. Tokens carry 256
random bits, so store a SHA-256 digest and find the row directly;
hashes issued before this still verify until they expire.
2026-10-26 01:00:48 -04:00
Juan Denis cb93120bac Keep custom-domain HTTPS across vhost rebuilds
Enabling SSL on a custom domain edited the vhost in place, but every
later rewrite (deploy, slot switch, domain attach, drift repair,
restore) rebuilt it from Domain rows that only knew wildcard certs,
so HTTPS silently disappeared while the row still said enabled.

Rebuilds now resolve each domain's own cert and render one server set
per certificate when domains differ. Enable/attach publish through
write_app_vhost and only claim SSL when nginx accepted it, the key
path is stored under its real column (legacy rows fall back to
certbot's privkey.pem), disable drops the HTTPS block, and a repeat
add_ssl_to_site swaps the cert instead of breaking nginx -t.
2026-10-26 00:49:57 -04:00
Juan Denis 475add2674 Validate Postgres helper SQL and report user errors
pg_create_database/user and pg_grant/revoke built superuser SQL from
raw names and passwords, unlike the MySQL helpers beside them. A quote
in a password broke CREATE USER, and the create routes ignored that
and returned credentials for a user that did not exist. Validate
identifiers and privilege lists, escape the password, and surface a
failed user as user_error instead of fake credentials.
2026-10-26 00:43:13 -04:00
Juan Denis 9b85952b5f Enforce workspace access on every server route
Only three routes checked can_access_server; the rest loaded the server
by id, so a developer outside a workspace could run cron, write files,
install packages or widen agent permissions on its servers, and the
list/overview/docker picker showed every server. Every <server_id>
route now resolves through the workspace check, lists filter in SQL,
and PUT /servers/<id> validates allowed_ips like PUT /allowed-ips.
A sweep test walks the URL map so a new unguarded route fails CI.
2026-10-26 00:35:55 -04:00
Juan Denis c0dbb921e1 feat: queue preview automation and preserve cleanup ownership through app deletion 2026-10-24 06:21:26 -04:00
Juan Denis 5a13a0dfb1 feat: provision isolated generic previews with retryable resource cleanup 2026-10-24 06:11:46 -04:00
Juan Denis d4f6b2af55 feat: expose value-free effective environment provenance through app access boundary 2026-10-24 05:58:02 -04:00
Juan Denis 6400b76a7d Drop imports that shadowed module-level names
Function-local re-imports of User, WorkspaceService and secrets, and a
local list named secrets, hid the module names they duplicated.
2026-10-10 22:20:03 -04:00
Juan Denis 9d750a4f6f Remove the /system process and service routes
Both used psutil without importing it, so every call has been a 500
since they were written. Nothing calls them: the process list and
service status come from /processes and /processes/services.
2026-10-10 21:51:15 -04:00
Juan Denis 99a19c2fb7 Read 40 more route bodies through json_object()
The first pass left routes that hand the body straight to a service
(create_zone(data), MonitorService.create(data), ...). Those services
read it as a dict, so a body of null, [] or a bare string still
crashed them into a 500. Agent long-poll, external webhook receivers
and the routes that already type-check their body are left alone.
2026-10-10 21:48:18 -04:00
Juan Denis b35f6df97a Validate the journal priority parameter
The value went straight to a privileged journalctl -p. As its own argv
element it could not inject options, but anything other than levels
0-7 now gets a 400 instead of a journalctl error.
2026-10-10 20:54:45 -04:00
Juan Denis 55d8fb1e44 Read route bodies through json_object()
328 more routes used a JSON body as a dict straight from
request.get_json(), so a body of null, [] or a bare string crashed them
into a 500. Bare reads become json_object(); the
'get_json(silent=True) or {}' reads of action routes become
json_object(optional=True), which still treats a missing body as {}.
Routes that take arrays or pass the body through untouched are left
alone. The full backend suite shows no new failures.

Also carries three files' bare section citations (apps, backups,
notifications) and the extended citation guard, which needed them.
2026-10-10 20:53:43 -04:00
Juan Denis ddaeb549ad Remove bare plan-section citations
Comments cited plan sections as "(§G3)" or "(§8 unification)", which
point into the same git-ignored plans the plan-number citations did.
References next to a real document (docs/REDESIGN_MAP.md §3) stay. Code
and runtime strings are unchanged (AST and token comparison).
2026-10-10 20:25:49 -04:00
Juan Denis 166e9acabf Split servers.py into area modules
The 3,000-line file mixed core server routes with Docker, agent
install/update/fleet and remote host operations. Those sections move
verbatim into servers_docker, servers_agents and servers_remote on the
same blueprint; the registered route map (127 rules, methods and
endpoint names) is identical before and after.

The controller-boundary scan only treated files that create a
Blueprint as controllers, so an area module would have escaped it; it
now also counts files that register routes.
2026-10-10 18:49:59 -04:00
Juan Denis bf5405df9e Move the health check's database probe into a service
The previous commit ran SELECT 1 directly in the route, a new
persistence crossing in the API layer that the controller-boundary
ratchet rejects.
2026-10-10 18:48:53 -04:00
Juan Denis 587dcec12a Make the health check probe the database
/system/health always said healthy, even with the database gone, so
container healthchecks and the installer trusted a panel that could not
serve; it now answers 503 when SELECT 1 fails. It also gave anonymous
callers the canonical domain and whether secrets encryption is set up;
those details now need a valid token (the Settings page sends one).
2026-10-10 18:23:24 -04:00
Juan Denis d134af25ae Drop route try/excepts the 500 handler duplicates
33 routes wrapped their body in try/except Exception only to return
unexpected_response(e), which records the crash and answers the same
body the global 500 handler already does. Every site was directly in a
route function, so the handler sees the same exceptions. SAML metadata
relied on its wrapper for an unconfigured IdP; that is now a typed 404
instead of a logged crash on a public, probed route.
2026-10-10 18:14:28 -04:00
Juan Denis 98bc6946f9 Bound the generate-password length parameter
Any signed-in user could pass ?length=1000000000 and make the server
build a gigabyte-long password string. Lengths are clamped to 8-128.
2026-10-10 18:02:03 -04:00
Juan Denis e40e24b4f1 Map remote agent failures to one status rule
The cron proxy answered an offline agent with 503 and a refused command
with 403, while 22 of the 24 Docker proxy routes answered 500 for both,
so the UI could not tell an offline agent from a crash. Every remote
handler now uses the same rule.
2026-10-10 18:01:02 -04:00
Juan Denis 3e1a264ee4 Reject non-object JSON bodies with a 400
Eleven routes passed request.get_json() straight to data.get(...), so
a body of null, [] or a bare string crashed them into a 500. They now
read the body through json_object(), which answers a typed 400.
2026-10-10 17:04:21 -04:00
Juan Denis d8f1d5b2d5 Let the global handler render queue-bus errors
QueueBusError is an expected, caller-actionable failure, so it now
subclasses ApplicationError and the global handler answers it with its
own status. The 21 queue-bus routes each wrapped their whole body in
try/except only to do that by hand. Also records the two workspace
queries the previous commit moved out of the API layer.
2026-10-10 16:57:29 -04:00
Juan Denis cc8c74e1ef Compute visible workspace ids in one place
The same "active workspace, else my workspaces, else all for an admin"
rule was written out in projects, environments and search. It now lives
in WorkspaceService, with a request-aware wrapper for routes.
2026-10-10 16:56:42 -04:00
Juan Denis 6068b099dc Replace nine per-app access helpers with one
Nine route files each loaded the live app and checked access, with
four return shapes, docstrings promising error tuples the code never
returned, and 41 dead 'if err: return err' branches. require_app()
backed by ResourceGrantService.get_app_for does it once; conceal=True
keeps the 404-for-denied answer the previews, WAF and slot routes
already gave, so no route's status changes. Nine query sites leave the
API layer.
2026-10-10 16:36:01 -04:00
Juan Denis 6296887bad Remove internal plan citations from app code
Comments, docstrings and a few strings cited plan numbers ("plan 29
#9", "plan 86 §B2") from a git-ignored folder, so they pointed at
nothing; one reached users in a bottleneck hint. Code and frontend
strings are unchanged apart from those citations (checked by AST and
token comparison). A vhost still carrying the old asset comment reads
as undrifted, and a guard test keeps new citations out.
2026-10-10 15:50:45 -04:00
Juan Denis 4e45ecb5f5 Move the new auth lookups behind the model/service
The server access helper and the app-name clash checks queried the DB
from the API layer, which the controller-boundary scan rejects. They
now go through WorkspaceService.get_accessible_server and
Application.name_clash_error; the baseline drops by three.
2026-10-10 09:56:44 -04:00
Juan Denis bd850adfb3 Raise typed errors from the new auth checks
The checks added to apps, servers and 2FA verify returned hand-shaped
{'error'} bodies, pushing that census past its ceiling. They now raise
the typed errors (a RateLimitedError joins them for 429). create_app
loads the user once through get_current_user(), which drops the
identity census to 68. Regenerates the migration inventory, stale since
the raw-subprocess ceiling fell to 23.
2026-10-10 09:47:11 -04:00
Juan Denis f6ee8befa1 Enforce lockout and single use at 2FA verify
Failed codes counted toward the account lockout, but verify never
checked it, so guessing could continue past the lock from fresh IPs.
A TOTP code also stayed reusable for its whole window, and a pending-
login token could complete more than one login. Spent codes and tokens
are now recorded in-process (the panel runs one worker) until they
would have expired anyway.
2026-10-10 09:35:08 -04:00
Juan Denis 38810ae25b Mask secret env values for read-only app grants
Masking was opt-in from the client (?mask=true), so a viewer grant on
an app read every secret value through the list, the single-variable
read and the .env export. Secret values now go only to users who can
edit the app.
2026-10-10 09:28:32 -04:00