about summary refs log tree commit diff
AgeCommit message (Collapse)Author
2026-10-22Change to error logging rather than debug. HEAD mainFrederick Muriuki Muriithi
If a token-related error occurs, log it out as an error log, rather than debug, so that we can track them and fix the causes (where we can) whenever they occur.
2026-10-14Bugfix: Ensure user details are present in results.Frederick Muriuki Muriithi
2026-10-07Make all fixtures 'function' scoped.Frederick Muriuki Muriithi
2026-10-07Ignore .git and .venv directories when scanning for tests.Frederick Muriuki Muriithi
2026-10-07Reactivate tests and add warningsFrederick Muriuki Muriithi
Reactivate tests to ensure they are not skipped any longer. Add warnings for the parts of the tests that have not been handled to completion.
2026-10-07Only rollback the privileges introduced in this specific migration.Frederick Muriuki Muriithi
2026-10-05Add sanity checks at service initialisation.Frederick Muriuki Muriithi
We need that there is at least one system administrator defined at service startup. We also verify that the 'GeneNetwork System' resource exists, and is created by the system administrator. If these invariants are not fulfilled, then the service should not run.
2026-10-05docs: Add RELEASE_NOTES.md documenting the fresh-deployment fixes fix-fresh-deployment-bugsClaude Sonnet 5
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-10-05fix(resources/views): don't crash on an invalid (not just missing) tokenClaude Sonnet 5
resources_authorisation()'s except _HTTPException branch only set `resp` when err_msg["error"] == "missing_authorization", leaving it unset for any other token-related _HTTPException -- in particular "invalid_token", raised for a malformed or otherwise invalid bearer token (as opposed to no Authorization header at all). `return resp` then raised UnboundLocalError, a 500, instead of the same anonymous public-only fallback this endpoint already gives a request with no token. Reproduced: POST /auth/resource/authorisation with "Authorization: Bearer not-a-real-token" raised UnboundLocalError before this change, and now returns the same {"public-read": ...} shape a request with no Authorization header gets. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-10-05fix (resources/base): Make `created_by` mandatory.Frederick Muriuki Muriithi
The `created_by` field is mandatory, and every resource should have a creator, including the system itself. Any chicken/egg situation that arises from this situation should be resolved by manually editing the data or building code to initialise the application at startup, not by ignoring this invariant.
2026-10-04fix(wsgi): hash the dev client's secret before storing itClaude Sonnet 5
init-dev-clients stored the dev client's secret ("yadabadaboo") as plain text, but OAuth2Client.check_client_secret always runs the stored value through the Argon2 verifier, which raises InvalidHashError on a non-hash string. Every grant type requiring client_secret_post -- i.e. all of them -- failed for the dev client as a result. create-oauth2-client already hashes its secret correctly via hash_password(); init-dev-clients now does the same. Reproduced: flask init-dev-clients, then POST /auth/token with the dev client's credentials raised a 500 (argon2.exceptions.InvalidHashError) before this change, and returns a token after it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-10-04fix(resource_server): refresh JWKS cache when empty, not just staleClaude Sonnet 5
JWTBearerTokenValidator caches its JWKS key set and only refreshes it every jwt_refresh_frequency_hours (default 6). On a fresh deployment, no JWK exists until the first token is issued (keys are generated lazily in jwks.py), which can happen after the validator was already constructed with an empty key set -- every token issued before the next scheduled refresh then failed to validate, even though a usable key existed on disk by the time the token arrived. Also fixes _last_jwks_update never being updated after a refresh, which meant that once the 6-hour window first elapsed, every later token validation re-read the JWKS directory from disk instead of using the cache. Reproduced against a from-scratch instance: clear the JWKS directory, start the server, issue a token via the password grant, then use that same token immediately on another endpoint -- it was rejected with invalid_token before this change, and is accepted after it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-09-29Do better content negotiation: prefer 'Accept' to 'Content-Type'.Frederick Muriuki Muriithi
2026-09-29Replace deprecated module and functions with newer versions.Frederick Muriuki Muriithi
2026-09-29Pass the 'AUTH_DB' config to the SQLite function(s).Frederick Muriuki Muriithi
The `with_db_connection(...)` function in this module is the SQLite version, not the MariaDB version, therefore we need to pass the file to the SQLite database file and not the MariaDB connection string.
2026-09-02refactor(system/views): remove dead deprecation-check codeClaude Sonnet 4.6
The /auth/system/roles endpoint has no active blueprint registration — the system Blueprint is only reachable via /auth/resource/system/roles. The `if "/resource/" not in request.path` branch could never fire, so remove it along with _SUCCESSOR, and the warnings import. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-09-01Bugfix: Use correct spec strings.Frederick Muriuki Muriithi
These bugs were introduced by Claude, and I missed them during review.
2026-09-01fix(auth): check system:user:list against system resource in resource_usersClaude
The HACK block in resource_users() was checking the system:user:list privilege against the requested resource_id rather than the system resource. This made the sysadmin branch a dead leg: sysadmins hold system:user:list on the system resource, not on individual data resources. Fix: pass system_resource(conn).resource_id for the system-level check. Also restructure to early-return on auth failure (cleaner control flow). Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-09-01refactor(auth): remove deprecated authorised_for and authorised_for2Claude
All callers have been migrated to authorised_for_spec (previous commit). Remove the two deprecated functions and their now-orphaned helpers: - authorised_for() and authorised_for2() deleted - __organise_privileges_by_resource_id__() deleted (only used by authorised_for) - Orphaned imports removed: reduce, Sequence, Resource, User, db_row_to_privilege Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-09-01refactor(auth): migrate authorised_for/2 -> authorised_for_specClaude
Replace all uses of the deprecated authorised_for() and authorised_for2() helpers with authorised_for_spec() across resources/views.py and data/phenotypes.py. - resources/views.py (resource_users HACK block): two authorised_for() calls replaced; the intermediate dict merge collapsed into a plain boolean since authorised_for_spec returns bool directly. - resources/views.py (assign_role_to_user, unassign_role_to_user): authorised_for() was called but its return value was discarded, making the check a silent no-op. Now replaced with authorised_for_spec() and a proper if/raise guard. Also fixes a typo: the privilege string was "resource:role:assign-role" (non-existent); corrected to the real privilege "resource:user:assign-role". - resources/views.py (unassign_resource_role_privilege): direct replacement; intermediate _authorised variable removed. - data/phenotypes.py (link_phenotype_data): two authorised_for2() calls replaced; .resource_id extracted from the Resource objects to satisfy authorised_for_spec's UUID argument. User type annotation added. Reivewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-09-01Revoke 'system-administrator' role on non-system resources.Frederick Muriuki Muriithi
2026-08-31refactor(auth): remove deprecated /auth/system/roles registrationClaude
All consumers have been updated to use /auth/resource/system/roles. Remove the legacy oauth2.register_blueprint(system, url_prefix="/system") registration and its accompanying import from views.py. The /auth/resource/system/roles path remains live via the existing resources.register_blueprint(system, ...) in resources/views.py.
2026-08-31Use `gn_libs.sqlite3 instead of deprecated `gn_auth.auth.db.sqlite3`.Frederick Muriuki Muriithi
2026-08-31refactor(admin/users): replace authorised_for2 with can_create_or_delete_userClaude
Use gn-libs' can_create_or_delete_user() + user_roles_on_system() for the privilege check in delete_users(), matching the pattern already used by create_user(). Removes the authorised_for2, system_resource, and AuthorisationError imports that are no longer needed. Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-31refactor(users): move delete_users to admin users blueprintClaude
Move POST /auth/user/delete to POST /auth/system/administration/users/delete, consistent with the create endpoint already living there. gn_auth/auth/system/admin/users.py: - Add imports for sqlite3, reduce, Sequence, AuthorisationError, authorised_for2, and system_resource. - Move __delete_users_individually__, __fetch_non_deletable_users__, __non_deletable_with_reason__, and delete_users() from users/views.py. gn_auth/auth/authorisation/users/views.py: - Remove the four functions moved to admin/users.py. The sole known caller (GN2 wqflask/oauth2/users.py) is updated in the accompanying genenetwork2 patch. Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-31feat(system/roles): add Deprecation header on old pathClaude
GET /auth/system/roles is superseded by GET /auth/resource/system/roles, which has been live since the system Blueprint was registered under the resources Blueprint. Add Deprecation: true and a Link successor-version header when the endpoint is reached via the old path, so callers can discover the new URL. The old registration in auth/views.py already carries a TODO noting it should be removed once consumers are updated. Callers to migrate: - GN2: wqflask/views.py, metadata_edits.py (×3), flask_extensions.py, oauth2/ui.py, oauth2/request_utils.py, oauth2/resources.py (×2) - GN3: gn3/api/metadata.py, gn3/api/case_attributes.py - gn-integration-tests: tests/test_gn_auth_smoke.py Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-31Enable more roles for users on CLI commands.Frederick Muriuki Muriithi
Enable the "batch-editors", "systemwide-docs-editor", and/or "systemwide-data-curator" roles.
2026-08-31Migration: Assign 'resource:user:assign-role' privilege to sysadmins.Frederick Muriuki Muriithi
Allow system administrators to assign roles against the system itself.
2026-08-31Bugfix: Use AUTH_DB rather than SQL_URI for SQLite connections.Frederick Muriuki Muriithi
2026-08-31Update test_admin_users.py for new admin users endpointClaude Sonnet 4.6
Update HTTP endpoint tests to use the new URL POST /auth/system/administration/users/create and the new mock path gn_auth.auth.system.admin.users.require_oauth.acquire Model-level tests (create_verified_user) are unchanged. Reviewed-By: Frederick M. Muriith <fredmanglis@gmail.com>
2026-08-31Move create_new_user to gn_auth/auth/system/admin/users.pyClaude Sonnet 4.6
Move the user-creation endpoint from gn_auth/auth/authorisation/users/views.py into the new sysadmin package at gn_auth/auth/system/admin/users.py. New URL: POST /auth/system/administration/users/create Old URL: POST /auth/user/create now issues a 308 Permanent Redirect. The admin blueprint is updated to register the new users blueprint at /users. Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-28Implement assign-owner / revoke-owner in system admin resourcesClaude Sonnet 4.6
The system-administrator role carries system:resource:assign-owner (migration 20250729_02), but no endpoint used it. Sysadmins had no API path to bootstrap ownership on a resource that has no owner yet. Implement two endpoints in gn_auth/auth/system/admin/resources.py (the blueprint skeleton was already wired in a preceding commit): POST /auth/system/administration/resources/<resource_id>/assign-owner Body: {"user_id": "<uuid>"} Assigns the resource-owner role to the named user on the resource. POST /auth/system/administration/resources/<resource_id>/revoke-owner Body: {"user_id": "<uuid>"} Revokes the resource-owner role from the named user on the resource. Both check system:resource:assign-owner on the *system* resource, so a sysadmin can grant/revoke ownership without being resource-owner themselves. Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-28Add unit tests for system admin resource-ownership endpointsClaude Sonnet 4.6
Four tests covering the two new endpoints added in the previous commit: POST /auth/system/administration/resources/<id>/assign-owner POST /auth/system/administration/resources/<id>/revoke-owner Tests: - assign-owner returns 401 when no Authorization header is sent - revoke-owner returns 401 when no Authorization header is sent - assign-owner returns 403 for a user without system:resource:assign-owner - revoke-owner returns 403 for a user without system:resource:assign-owner The 401 tests exercise the @require_oauth decorator directly. The 403 tests mock require_oauth.acquire (same pattern as test_admin_user_roles.py) and use unaff@iliated.user (TEST_USERS[3]) who has no roles and therefore no system:resource:assign-owner privilege on the system resource. Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-28Add package for administrative endpoints.Frederick Muriuki Muriithi
2026-08-28fix(jwt-bearer-token): use AUTH_DB instead of SQL_URI for user/client lookupFrederick Muriuki Muriithi
JWTBearerToken.__init__ was calling with_db_connection with app.config["SQL_URI"] (the GeneNetwork MariaDB URI) to look up the authenticated user and OAuth2 client. gn_libs.sqlite3.with_db_connection expects a SQLite file path, so passing a MySQL URI causes an OperationalError: unable to open database file every time a JWT is validated through require_oauth.acquire(). Use app.config["AUTH_DB"] (the gn-auth SQLite database) for both lookups. Also normalise the whitespace in the user lookup lambda while here. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-27Cleanup deprecation warnings: Switch to gn_libs.sqlite3Frederick Muriuki Muriithi
The gn_auth.auth.db.sqlite3 module is deprecated and should be removed. This cleanup goes a ways towards that goal.
2026-08-27Deprecate endpoint /auth/resources/<uuid:resource_id>/user/unassign.Frederick Muriuki Muriithi
Prefer the endpoint `/auth/users/<uuid:user_id/roles/revoke` that conforms to the Subject-Verb-Object paradigm, i.e. Revoke from a user (subject), the specified role acting on the specified resource (object) -- revoke a role would be the 'Verb'.
2026-08-27feat(users/admin): implement POST /auth/user/<uid>/roles/revokeClaude Sonnet 4.6
Adds unassign_user_role_by_name to roles/models.py — mirrors assign_user_role_by_name but issues a resource-scoped DELETE, resolving the TODO on the older revoke_user_role_by_name which lacked the resource_id filter. The new revoke_user_role endpoint checks resource:user:assign-role (same privilege as assign) via can_assign_role, then calls unassign_user_role_by_name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-27tests(admin): add TDD tests for POST /auth/user/<uid>/roles/revokeClaude Sonnet 4.6
Four tests covering the revoke endpoint (401/403/200/DB removal). Success tests pre-assign the role via _assign_target_role and use try/finally with _cleanup_target_role to restore DB state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-27Deprecate endpoint /auth/resources/<uuid:resource_id>/user/assign.Frederick Muriuki Muriithi
2026-08-27feat(users/admin): implement POST /auth/user/<uid>/roles/assignClaude Sonnet 4.6
Checks resource:user:assign-role via can_assign_role (gn_libs.privileges.resources) on the caller's roles for the request's resource_id — caller must hold resource-owner (or masquerade as one) on that resource. Updates test setup to grant resource-owner on SYSTEM_RESOURCE instead of system-administrator, matching the actual privilege model. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-26tests(admin): success-path tests for POST /auth/user/<uid>/roles/assignClaude Sonnet 4.6
Adds 200-status and DB-persistence checks. Both use try/finally to call _revoke_assigned_role so the DB is left in the state the fixtures expect, preventing surprises in teardown or future tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-26tests(admin): auth-guard tests for POST /auth/user/<uid>/roles/assignClaude Sonnet 4.6
401 (no token) and 403 (non-admin token) — both expect 404 until the stub endpoint is added. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-26Fix error codes for various input validation errors.Frederick Muriuki Muriithi
2026-08-26feat(users/admin): implement POST /auth/user/create endpointClaude Sonnet 4.6
Parses email/name/password from the JSON body, calls create_verified_user, and returns 201 with the new user's user_id, email, and name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com> Added input validation.
2026-08-26Assign 'system:user:create-user' privilege to 'system-administrator' role.Frederick Muriuki Muriithi
2026-08-26tests(admin): success-path tests for POST /auth/user/createClaude Sonnet 4.6
Two TDD tests for the admin create-user endpoint success case: - Valid admin token + valid body → 201 - Response body contains the new user's email and name Both fail (501) until the endpoint body is implemented. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-26feat(admin/users): wire auth guards on POST /auth/user/createClaude Sonnet 4.6
Adds @require_oauth("profile") for 401 on unauthenticated requests and an authorised_for2 check for the system:user:create-user privilege, raising ForbiddenAccess (403) for non-admin callers. Returns 501 for the success path until the body logic is implemented. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
2026-08-26tests(admin): HTTP integration tests for POST /auth/user/createClaude Sonnet 4.6
Two TDD tests that define the expected auth behaviour of the new create-user endpoint before it is implemented: - No Authorization header → 401 - Valid token for a non-admin user → 403 Both tests fail (404) until the endpoint exists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com> Add's aso a dummy endpoint.
2026-08-26feat(admin/users): implement create_verified_userClaude
Replaces the dummy stub with a real implementation that: - calls save_user(cursor, email, name, verified=True) to create the user with the verified flag set, bypassing the email verification flow - calls set_user_password to store the hashed credential in user_credentials - returns the newly created User with no roles assigned Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>