Repository navigation
Hide user emails and superuser flags from public API responses - #1288
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The read-only endpoints made public in #218 return user records with
email,is_activeandis_superuser. Without logging in, anyone can get the email of every account, inactive ones included, and see which accounts are superusers. This comes fromGET /users/all_usersand 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 onlyidandusername. The team-members update request also takesPublicUser; the server only ever read the ids from it./users/all_usersstays public, but only superusers get the full records. Everyone else getsidandusername. A logged-in user also getsis_superuseron 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 ownFastAPIUsersinstance. TheJWTBackendtransport rejects a request without anAuthorizationheader with 403 before fastapi-users can treat the caller as anonymous. So the optional instance uses the same backend withauto_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:undefineduntil AlmaLinux/albs-frontend#616 is deployed. Admin detection and the build author filter keep working.Deployment order
Testing
tests/test_api/test_users.pytestsall_usersfor 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 ifemail,is_superuseroris_activeappears in any of them.pytest --ignore tests/test_oval): 600 passed, 10 skipped.