about summary refs log tree commit diff
path: root/RELEASE_NOTES.md
blob: 32b013afe50d2a77d9125d0ea2d1363351d2e589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Release Notes

## Unreleased

Found and fixed while standing up a from-scratch gn-auth instance (fresh
SQLite database, migrations applied, no prior data) to test a new
external client (GeneNetwork4) against the OAuth2 token and resource
authorisation endpoints. The first three bugs below only show up on a
fresh deployment with no existing JWK/users/sysadmins -- an
already-running instance with data from before these fixes will not
have hit them. The fourth is independent of deployment age -- any
instance, old or new, hits it whenever a client sends a malformed or
otherwise invalid bearer token to `/auth/resource/authorisation`.

### Fixed

- **`JWTBearerTokenValidator` could reject every token for hours after
  a fresh start.** Its JWKS key set is cached in memory and only
  refreshed every `jwt_refresh_frequency_hours` (default 6). On a
  fresh deployment, no JWK exists until the first token is ever
  issued (keys are generated lazily, see `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. The validator now also refreshes
  immediately whenever its cached key set is empty, not only when it
  is stale. (This fix also corrects a second, smaller issue in the
  same function: `_last_jwks_update` was never actually updated after
  a refresh, so once the 6-hour window first elapsed, every later
  token validation would re-read the JWKS directory from disk.)
  -- `gn_auth/auth/authentication/oauth2/resource_server.py`

- **`flask init-dev-clients` could not actually authenticate its own
  dev client.** The command stored the dev client's secret
  (`yadabadaboo`) as plain text, but client secret verification
  (`OAuth2Client.check_client_secret`) always runs the stored value
  through the Argon2 verifier, which raised `InvalidHashError` on a
  non-hash string. Every grant type requiring `client_secret_post` --
  i.e. all of them -- failed for the dev client. `create-oauth2-client`
  already hashed its secret correctly; `init-dev-clients` now does the
  same. -- `gn_auth/wsgi.py`

- **Make `Resource.created_by` mandatory**; Originally, the fix
  generated by Claude was to allow a `None` for the `created_by`
  attribute. This was fundamentally wrong, though it was not Claude's
  fault, since the typing was wrong too.
  The fix was updating the typing to make `created_by` a mandatory
  attribute, and adding some notes to the effect that the
  "GeneNetwork System" resource (and any other existing resources at
  the point of setup) should be manually updated to have the
  system-administrator user as their creator.

- **`POST /auth/resource/authorisation` crashed on an invalid bearer
  token instead of degrading to the public-only view.** Its exception
  handling only set the response for an authlib error of
  `missing_authorization` (no `Authorization` header at all); a
  present-but-invalid token raises `invalid_token` instead, which fell
  through without setting the response variable, raising
  `UnboundLocalError` (a 500). Any token-related failure now gets the
  same anonymous/public-only fallback. -- `gn_auth/auth/authorisation/resources/views.py`

### Verified by hand against a fresh instance

- `POST /auth/token` (password grant) issues a JWT; `GET
  /auth/public-jwks` lists the key once one has been generated.
- `POST /auth/resource/populations/create` links an InbredSet group to
  a new `inbredset-group` resource; `GET
  /auth/resource/populations/resource-id/<speciesid>/<inbredsetid>`
  resolves it back to the same `resource-id`.
- `POST /auth/resource/authorisation` returns the full role/privilege
  list for the resource's owner, and just `{"public-read": false}` for
  an anonymous *or* invalid-token caller on a non-public resource --
  the cases an external resource server (e.g. GeneNetwork4) needs to
  distinguish from "authorized".
- This is also exercised automatically: GeneNetwork4's
  `tests/auth.rs` runs its full token-verification and
  resource-authorization flow (including the caching layer) against a
  real gn-auth instance.

### Noted, not changed here

- The `system-administrator` role's broad `system:*` privileges are
  special-cased as globally applicable only inside gn-auth's own
  `@authorised_p`-protected endpoints
  (`gn_auth/auth/authorisation/checks.py`'s
  `__system_privileges_in_roles__`). `POST /auth/resource/authorisation`
  -- the endpoint an external resource server actually calls -- does
  not use that special case; it reflects only `user_roles` rows tied
  to the specific resource queried. A sysadmin therefore does not
  automatically show up with privileges on a resource created after
  migration `20250729_03` ran (which only granted the role on
  resources that existed at the time). Worth a decision before any
  external client relies on "sysadmin" meaning "full access
  everywhere".
  *fredm* (on review of this) notes that this code is an artifact of a
  previous state of affairs that has long been resolved, and thus,
  this code (especially the `__system_privileges_in_roles__` function)
  can be removed. This is because at this point, everything (except
  users), is considered and treated as some form (or other) of a
  resource.