Skip to content

Hide user emails and superuser flags from public API responses - #1288

Merged
anfimovdm merged 1 commit into
masterfrom
hide-user-emails-public-api
Dec 4, 2026
Merged

anfimovdm merged 1 commit into
masterfrom
hide-user-emails-public-api

Conversation

@anfimovdm

@anfimovdm anfimovdm commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The read-only endpoints made public in #218 return user records with email, is_active and is_superuser. Without logging in, anyone can get the email of every account, inactive ones included, and see which accounts are superusers. This comes from GET /users/all_users and from the users embedded in builds, releases, products and teams.

Embedded users. Build, release and product owners, and team owners and members, are now PublicUser, which has only id and username. The team-members update request also takes PublicUser; the server only ever read the ids from it.

/users/all_users stays public, but only superusers get the full records. Everyone else gets id and username. A logged-in user also gets is_superuser on their own record, which the frontend uses to detect admin rights.

Optional authentication. The endpoint resolves the caller with a new get_optional_user, which needs its own FastAPIUsers instance. The JWTBackend transport rejects a request without an Authorization header with 403 before fastapi-users can treat the caller as anonymous. So the optional instance uses the same backend with auto_error=False, and all other endpoints behave as before.

Compatibility

The frontend still works with this change. Owner links on public pages point to mailto:undefined until AlmaLinux/albs-frontend#616 is deployed. Admin detection and the build author filter keep working.

Deployment order

  1. This PR.
  2. Stop showing user emails on public pages albs-frontend#616.

Testing

  • tests/test_api/test_users.py tests all_users for anonymous, regular-user, superuser and invalid-token callers. It also walks the response models of the public build, release, product and team endpoints and fails if email, is_superuser or is_active appears in any of them.
  • Full test suite (pytest --ignore tests/test_oval): 600 passed, 10 skipped.

The read-only endpoints made public in #218 return user records with
email, is_active and is_superuser. Anyone can get the email of every
account, inactive ones included, and see which accounts are
superusers, from /users/all_users and from the owners and members
embedded in builds, releases, products and teams.

Embedded users (build, release and product owners, team owners and
members) are now PublicUser, with id and username only. The team
members update payload takes PublicUser as well; only the ids were
ever read from it.

/users/all_users stays public, but returns the full records to
superusers only. Everyone else gets id and username, and an
authenticated user also gets is_superuser of their own record, which
the frontend uses to detect admin rights.

The endpoint resolves the caller with a new get_optional_user. It
needs its own FastAPIUsers instance: the transport of JWTBackend
rejects a request without an Authorization header with 403 before
fastapi-users treats the caller as anonymous, so the optional
instance uses the same backend with auto_error=False. The other
endpoints keep the current behaviour.

Tests cover all_users for anonymous, regular, superuser and invalid
token callers, and check that no response model of the public build,
release, product and team endpoints includes private user fields.
@anfimovdm
anfimovdm merged commit 192e82f into master Dec 4, 2026
3 of 5 checks passed
@anfimovdm
anfimovdm deleted the hide-user-emails-public-api branch December 4, 2026 14:43
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.

1 participant