CI / skip-ci-check (pull_request) Successful in 30s
CI / docker-ci (pull_request) Successful in 32s
CI / python-lint (pull_request) Successful in 32s
CI / secret-scan (pull_request) Successful in 39s
CI / viewer-unit (pull_request) Successful in 2m21s
CI / admin-unit (pull_request) Successful in 2m43s
CI / e2e (pull_request) Successful in 3m22s
Stop shipping punimtag_password / admin defaults in install helpers and docs; generate secrets at install time; require ADMIN_PASSWORD from env (with test-only bootstrap in conftest).
2.9 KiB
2.9 KiB
Granting Database Permissions
This document describes how to grant read-only permissions to the viewer_readonly user on the main punimtag database tables.
Quick Reference
✅ WORKING METHOD (tested and confirmed):
PGPASSWORD=<choose-a-password> psql -h localhost -U punimtag -d punimtag -f grant_readonly_permissions.sql
When to Run This
Run this script when you see errors like:
permission denied for table photospermission denied for table peoplepermission denied for table faces- Any other "permission denied" errors when accessing database tables
This typically happens when:
- Database tables are recreated/dropped
- Database is restored from backup
- Permissions are accidentally revoked
- Setting up a new environment
Methods
Method 1: Using punimtag user (Recommended - Tested)
PGPASSWORD=<choose-a-password> psql -h localhost -U punimtag -d punimtag -f grant_readonly_permissions.sql
Method 2: Using postgres user
PGPASSWORD=postgres_password psql -h localhost -U postgres -d punimtag -f grant_readonly_permissions.sql
Method 3: Using sudo
sudo -u postgres psql -d punimtag -f grant_readonly_permissions.sql
Method 4: Manual connection
psql -U punimtag -d punimtag
Then paste these commands:
GRANT CONNECT ON DATABASE punimtag TO viewer_readonly;
GRANT USAGE ON SCHEMA public TO viewer_readonly;
GRANT SELECT ON TABLE photos TO viewer_readonly;
GRANT SELECT ON TABLE people TO viewer_readonly;
GRANT SELECT ON TABLE faces TO viewer_readonly;
GRANT SELECT ON TABLE person_encodings TO viewer_readonly;
GRANT SELECT ON TABLE tags TO viewer_readonly;
GRANT SELECT ON TABLE phototaglinkage TO viewer_readonly;
GRANT SELECT ON TABLE photo_favorites TO viewer_readonly;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO viewer_readonly;
Verification
After granting permissions, verify they work:
-
Check permissions script:
npm run check:permissions -
Check health endpoint:
curl http://localhost:3001/api/health -
Test the website:
- Refresh the browser
- Photos should load without permission errors
- Search functionality should work
What Permissions Are Granted
The script grants the following permissions to viewer_readonly:
- CONNECT on database
punimtag - USAGE on schema
public - SELECT on tables:
photospeoplefacesperson_encodingstagsphototaglinkagephoto_favorites
- USAGE, SELECT on all sequences in schema
public - Default privileges for future tables (optional)
Notes
- Replace
<choose-a-password>with the actual password for thepunimtaguser (found in.envfile) - The
viewer_readonlyuser should only have SELECT permissions (read-only) - If you need write access, use
DATABASE_URL_WRITEwith a different user (viewer_write)