Skip to content

feat(security): fleet-wide default for require-verified-email — secure-by-default (#1129) - #1132

Merged
vybe merged 3 commits into
devfrom
feature/1129-require-email-default
Jun 11, 2026
Merged

vybe merged 3 commits into
devfrom
feature/1129-require-email-default

Conversation

@dolho

@dolho dolho commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Promotes the per-agent require_email access-policy flag (#311) to an admin-controlled fleet-wide default that defaults ON, so new agents are secure-by-default instead of opt-in per agent. Mirrors the RES-001 agent-defaults/resources pattern.

Changes

  • settings_service.py — AGENT_DEFAULT_REQUIRE_EMAIL_KEY + get_agent_default_require_email() (default ON; resolved from system_settings, with a code fallback so fresh installs are secure without a data migration).
  • routers/settings.py — GET/PUT /api/settings/agent-defaults/access-policy (admin-only) + AgentDefaultAccessPolicyUpdate model. Registered before the /{key} catch-all (Invariant fix: add missing logging_config.py to backend Dockerfile #4).
  • register_agent_owner (db/agents.py + database.py facade) — new require_email param, written explicitly in the INSERT (same SQLite-baked-default reasoning as feat: increase default chat execution timeout from 15m to 60m #665's execution_timeout_seconds). Defaults False, so the system agent is unaffected.
  • crud.py — seeds require_email from the platform default at user-agent creation.
  • Settings UI — admin toggle in the Platform section, consistent with the Default Model control.

No schema change

The agent_ownership.require_email column (#311) and system_settings both already exist — zero DDL, no migration. The default is read only at creation time; existing agents are never rewritten.

Acceptance criteria

  • Admin-only platform setting for the fleet-wide require_email default, stored in system_settings, defaulting ON.
  • Agent creation seeds agent_ownership.require_email from the default (not hard-coded 0).
  • Per-agent override preserved (PUT /api/agents/{name}/access-policy unchanged).
  • Settings UI exposes the toggle (admin-only), consistent with agent-defaults resources.
  • Default affects newly created agents only; existing agents unchanged (no retroactive rewrite).
  • Backend default ON for fresh installs via code fallback; no per-agent rows touched.
  • Scoped to require_email only (per the grooming note); open_access left out.

Verification (live)

Step Result
GET /agent-defaults/access-policy require_email: true (default ON, key unset)
Create agent (default ON) seeded require_email: true
Flip default OFF → create agent seeded require_email: false
Existing agent after the flip unchanged (still its prior value)
Per-agent PUT /access-policy still works (flipped an agent independently)
Settings UI toggle renders under Platform, checked ON by default, no page errors

Throwaway agents deleted; default restored ON. Backend py_compile + frontend vue/compiler-sfc clean.

Related to #1129

🤖 Generated with Claude Code

…-by-default (#1129)

Promote the per-agent `require_email` access-policy flag (#311) to an
admin-controlled fleet-wide default that defaults ON, so new agents are
secure-by-default instead of opt-in per agent. Mirrors the RES-001
agent-defaults/resources pattern.

- settings_service: AGENT_DEFAULT_REQUIRE_EMAIL_KEY + get_agent_default_require_email()
  (default ON; resolved from system_settings, code fallback so fresh installs
  are secure without a data migration).
- routers/settings: GET/PUT /api/settings/agent-defaults/access-policy (admin-only)
  + AgentDefaultAccessPolicyUpdate model.
- register_agent_owner (db/agents + database facade): new require_email param,
  written explicitly in the INSERT (same SQLite-baked-default reasoning as #665's
  execution_timeout_seconds). Defaults False so the system agent is unaffected.
- crud: seed require_email from the platform default at user-agent creation.
- Settings UI: admin toggle in the Platform section, consistent with Default Model.
- No schema change (column + system_settings already exist); existing agents are
  never rewritten — the default is read only at creation time.

Verified live: default GET = ON; new agent seeds require_email ON; flip default
OFF → next new agent OFF; existing agent unaffected by the flip; per-agent
override still works; UI toggle renders + reflects the default. Throwaway agents
deleted, default restored ON.

Related to #1129

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

updated = []
if body.require_email is not None:
db.set_setting(AGENT_DEFAULT_REQUIRE_EMAIL_KEY, "1" if body.require_email else "0")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing audit log on a security-relevant setting change. This endpoint writes the fleet-wide email-verification default via db.set_setting(...) directly, with no platform_audit_service.log(...). Everywhere else in this router that mutates a setting audit-logs it — API-key change (L222), GitHub PAT (L380), and the generic PUT /{key} (L1454) all emit AuditEventType.CONFIGURATION. An admin flipping the fleet-wide require_email default OFF (weakening the platform security posture for every future agent) currently leaves no trace.

It mirrors the agent-defaults/resources PUT, which also doesn't audit — but resources isn't security-sensitive and this is (theme-security, P1). Suggest adding an audit call after the write, e.g.:

await platform_audit_service.log(
    event_type=AuditEventType.CONFIGURATION,
    event_action="update_agent_default_access_policy",
    actor_id=str(current_user.id), actor_email=current_user.email,
    details={"require_email": body.require_email}, source="api",
    request=request,
)

(make the handler async-friendly — it already is). Non-blocking, but worth closing the gap given the security theme.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 11a5abc — added the platform_audit_service.log(AuditEventType.CONFIGURATION, ...) call (same shape as the API-key/generic-setting writes) after the set_setting. Verified live: flipping the default writes a settings_change audit row with {setting: agent_default_require_email, require_email: <new>}.

@dolho

dolho commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

🔎 Code review (high-effort, recall-biased) — 1 non-blocking finding

Clean, well-scoped diff that faithfully mirrors the RES-001 agent-defaults pattern; live-verified end-to-end. No correctness bugs. One security-theme gap worth closing.

Finding (low/medium, non-blocking)

  • No audit log on the security-relevant default change — PUT /agent-defaults/access-policy writes via db.set_setting() with no platform_audit_service.log(...), while API-key/GitHub-PAT/generic-{key} settings writes all audit AuditEventType.CONFIGURATION. An admin weakening the fleet-wide require_email default OFF leaves no trace. Mirrors the (non-security) resources PUT, but this one is theme-security/P1. (inline)

Checked & cleared

  • System agent unaffected — register_agent_owner(require_email=False) default; the two system-agent call sites don't pass it (verified). The IntegrityError re-register path UPDATEs is_system only, never touching require_email — correct.
  • Default parsing — get_agent_default_require_email: None → code-default ON; "0" → False; flexible truthy set is harmless (writer only emits "1"/"0").
  • Route ordering — /agent-defaults/access-policy registered before the /{key} catch-all (Invariant fix: add missing logging_config.py to backend Dockerfile #4); also distinct by segment count.
  • Facade + callers — database.py forwards require_email; all 4 callers consistent; no broken call sites.
  • No lockout — require_email gates incoming channel/shared access per feat: Unified channel access control — verified-email identity, per-agent allow-list, access requests (web / Telegram / Slack) #311; the owner via web JWT and admins aren't gated, so flipping it ON at creation doesn't lock owners out of their own agents.
  • No schema change (column + system_settings pre-exist); existing rows never rewritten — confirmed live (existing agent unchanged after a default flip).

✅ Ready to merge; the audit-log addition is a nice defense-in-depth follow-up.

Reviewed with the code-review skill.

…review)

PUT /api/settings/agent-defaults/access-policy wrote the fleet-wide
require_email default via db.set_setting() with no audit trail, while every
other settings write in the router (API-key, GitHub PAT, generic /{key})
emits AuditEventType.CONFIGURATION. Flipping a security default must leave a
trace — add the same platform_audit_service.log() call.

Verified live: flipping the default writes a `settings_change` audit row with
{setting: agent_default_require_email, require_email: <new>}.

Related to #1129

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

Resolved docs/memory/architecture.md: dev's restructure made the Platform
Settings catalog terse (GET/PUT collapsed rows); re-added the #1129
agent-defaults/access-policy endpoint as one combined row in that style.

Co-Authored-By: Claude Fable 5 <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: verified require_admin local-helper pattern, get_setting_value facade method, and that the single user-agent creation path is covered (system-agent sites intentionally excluded). Explicit-INSERT seed reasoning sound (#665 pattern), zero DDL, default flip audit-logged. Resolved the architecture.md conflict against the dev restructure. CI green. Approving.

@vybe
vybe merged commit 89339a7 into dev Jun 11, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants