[Security Hardening] Reduce PostgreSQL runtime role privileges
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
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
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
- Native installer:
scripts/install.sh - All-in-one Docker entrypoint:
docker/aio-entrypoint.sh - macOS installer:
macos_postgres.py - Password sync:
_sync_postgres_password()
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 usingSET ROLE "unifi-protect"; ALTER ROLE "unifi-protect" WITH PASSWORD ...; RESET ROLE;because a role may change its own password. CREATE ROLEaskeystonefails:Only roles with the CREATEROLE attribute may create roles.GRANT "unifi-protect" TO another_roleaskeystonefails: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
keystonerole withoutCREATEROLEand runALTER ROLE keystone NOCREATEROLEon existing installs. - Replace the
ADMIN TRUEgrant with membership that hasSET TRUE, INHERIT FALSE, ADMIN FALSE, revoking the old grant withCASCADE. - Change the sync to enter the
unifi-protectrole before changing its password, and keep a transitional fallback to the directALTER ROLEfor installs created before this change. - Update the
keystone doctorrotation 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.
keystonecannot create a role or grantunifi-protectto another role.- Re-running the installer removes
CREATEROLEandADMINfrom an existingkeystonerole. - A code-only upgrade keeps password rotation working before the installer or entrypoint is rerun.
keystone doctorreports 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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from seeARMS/keystone
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
All issues in seeARMS/keystone
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day