[Security Hardening] Reduce PostgreSQL runtime role privileges

Open
#111 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@developingchet is already working on this.

Since Dec 4, 2026.

  • #118 by @developingchet — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
bash, docker, postgresql, python

Research direction

Start with scripts/install.sh, docker/aio-entrypoint.sh, macos_postgres.py, and _sync_postgres_password() in src/keystone/control.py, then locate the keystone doctor rotation probe. Run the relevant installer and rotation checks against PostgreSQL, including existing-install migration and retry scenarios. Done means password rotation and re-adoption still work while keystone can neither create roles nor grant unifi-protect; linked pull request #118 means this work is already underway.

Written by the indexing model from the issue text.

Description

needs-triage security

Summary

The native Linux, macOS and all-in-one Docker installers give the continuously running keystone database role CREATEROLE and ADMIN on the unifi-protect role. The only use is rotating the unifi-protect password when Protect adopts Keystone, which needs much less. A role with those attributes can create database roles and grant unifi-protect to them, so a compromise of the Keystone process reaches further in PostgreSQL than the one password change it performs.

Affected code

Evidence

Source inspection at dab11d2a37fa860b0bb6894fcd8a7f6451c54d0d. All three installers run CREATE ROLE keystone LOGIN CREATEROLE (or ALTER ROLE keystone CREATEROLE) and GRANT "unifi-protect" TO keystone WITH ADMIN TRUE, INHERIT FALSE, SET FALSE. _sync_postgres_password() then runs ALTER ROLE "unifi-protect" WITH PASSWORD ... as the keystone role.

Verified in a disposable PostgreSQL 16 container against the proposed least-privilege shape:

  • With GRANT "unifi-protect" TO keystone WITH ADMIN FALSE, INHERIT FALSE, SET TRUE, the sync succeeds using SET ROLE "unifi-protect"; ALTER ROLE "unifi-protect" WITH PASSWORD ...; RESET ROLE; because a role may change its own password.
  • CREATE ROLE as keystone fails: Only roles with the CREATEROLE attribute may create roles.
  • GRANT "unifi-protect" TO another_role as keystone fails: Only roles with the ADMIN option on role "unifi-protect" may grant this role.

The Docker Compose service uses a separate image and sets a superuser postgres_admin_url, so it does not use this role; the all-in-one image and both native installers do.

Impact

A compromise of the Keystone service can create additional database roles and grant them unifi-protect, which is more than the password rotation needs. This is defense in depth: the service already has enough access to change the password Protect uses, and no escalation beyond the local PostgreSQL instance is demonstrated. The change reduces the blast radius of a Keystone compromise and removes an unnecessary administrative capability from a long-running process.

Suggested remediation

  • Create the keystone role without CREATEROLE and run ALTER ROLE keystone NOCREATEROLE on existing installs.
  • Replace the ADMIN TRUE grant with membership that has SET TRUE, INHERIT FALSE, ADMIN FALSE, revoking the old grant with CASCADE.
  • Change the sync to enter the unifi-protect role before changing its password, and keep a transitional fallback to the direct ALTER ROLE for installs created before this change.
  • Update the keystone doctor rotation probe to test the same path, with the old probe only as a fallback.
  • Apply the same change to the native installer, the macOS installer and the all-in-one Docker entrypoint.

Acceptance criteria

  • Initial Protect adoption and password rotation succeed on a native install.
  • The retry path after a failed sync succeeds once PostgreSQL is reachable.
  • Re-adoption and a second rotation keep working.
  • keystone cannot create a role or grant unifi-protect to another role.
  • Re-running the installer removes CREATEROLE and ADMIN from an existing keystone role.
  • A code-only upgrade keeps password rotation working before the installer or entrypoint is rerun.
  • keystone doctor reports the rotation check as passing on a migrated install.
  • Docker Compose, the all-in-one image, native Debian/Ubuntu/Proxmox and macOS deployments keep working.

Compatibility considerations

The Docker Compose path uses a superuser admin URL and is unchanged. Existing native, macOS and all-in-one installs keep an ADMIN grant with SET disabled until the installer, macOS setup or container entrypoint runs again; during that window the sync uses its transitional direct ALTER ROLE fallback. The unifi-protect database, its TCP listener on 5432 and Protect's direct connection to it are unchanged.

Dominant language
Python
Stars
1k
Forks
114
Avg merge
1h
Merged PRs (30d)
115

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seeARMS/keystone

All issues in seeARMS/keystone

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.