Repository navigation
Conversation
9105c73 to
573cbc2
Compare
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
| if mgr.passwords[newKey] == nil { | ||
| mgr.passwords[newKey] = make(map[string]*apppb.AppPassword) | ||
| } |
There was a problem hiding this comment.
Mutating a map while ranging over it migrateLegacyKeys adds new keys to mgr.passwords while iterating over that same map rather than building the merged result in a separate map and swapping it in afterward. It is not a robust solution.
There was a problem hiding this comment.
Agreed. The startup migration is gone (see the top-level comment). The per-user replacement builds the merged bucket in a separate map and swaps it in after the loop (4d8cbe6).
| defer mgr.Unlock() | ||
|
|
||
| mgr.purgeExpiredUserTokens(userID.String()) | ||
| mgr.purgeExpiredUserTokens(userKey(userID)) |
There was a problem hiding this comment.
Could the uKey := userKey(userID) be called once and then the uKey?
There was a problem hiding this comment.
Done, uKey is computed once in each method (4d8cbe6).
|
Something to note is that the migration code will run on each startup, whether we want it or not. While it makes sense now, it won't in some months when all the keys have been migrated. I think a better approach is, first, to start using the new format unconditionally, and second, when we check for a key, check the new format first and then the old format. We still need to deal with the space difference. Do we have any data on the usage of the app-auth? As annoying as it is, the easiest solution is to let the users regenerate the app passwords if something goes wrong. |
The json manager keyed each user's bucket by UserId.String(), the protobuf text format. protobuf-go deliberately varies that output's whitespace from one binary to the next (internal/detrand), so a bucket written by one build was not found by the next and every existing app password silently stopped working after an upgrade, although still present in the file and unexpired. State files written by several builds held the same user under several keys. Key buckets by <idp>|<opaque id>. On load, parse buckets stored under the old text-format keys, re-key and merge them, and persist the result. Signed-off-by: Paul Faure <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
…artup Review feedback on owncloud#755: the load-time migration ran on every startup and changed the passwords map while ranging over it. - New app passwords are always stored under userKey. - Legacy UserId.String() keys are matched by parsing them back into a user id (the text cannot be recomputed, since its whitespace varies between builds). - GetAppPassword checks the stable key first; only a miss falls back to the user's legacy buckets. Generate, List, Invalidate and a successful Get move that user's legacy buckets under userKey (built in a separate map, then swapped in) and save. - Nothing is rewritten on load; the expired-token purge is as before. - userKey is computed once per call. Tests cover load (no rewrite), Get, a wrong password and another user's token, List, Invalidate and Generate; the adoption tests fail with the legacy lookup disabled. go test -race and go vet pass. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Paul Faure <[email protected]>
573cbc2 to
4d8cbe6
Compare
|
@jvillafanez thanks, I agree. I've followed your first suggestion, with one twist that the old key needs (4d8cbe6):
On usage data: I don't have any beyond our own server. If you'd rather not carry the fallback, letting users regenerate is fine with me too. I'd then drop the legacy lookup and say so in the changelog. A console command could come later if more key formats are ever needed. Also rebased onto main. |
|
I would like to include the fix in the recent releases, but I would prefer a different implementation. @paul43210, thank you for your contribution. |
|
Closed it to favor #777 |
Summary
pkg/appauth/manager/jsonstores each user's app passwords underUserId.String(). That is the protobuf text format, and protobuf-go deliberately varies its whitespace between binaries (internal/detrand: one or two spaces between fields, chosen per binary) precisely so that nobody depends on it. The result: a bucket written by one build is not found by the next, and every existing app password silently stops working after an upgrade — still in the file, not expired,password not found.Seen in production on 2026-09-30: an oCIS 8.0.0 build wrote
idp:"…" opaque_id:"…" type:USER_TYPE_PRIMARY(two spaces); the 8.2.0 build looks up the one-space form. A service account's one-year token minted hours before the upgrade returned 401 right after it. The state file already held the same users under both key shapes from an earlier build change.Changes
userKey(id)=<idp>|<opaque id>replaces everyuserID.String()lookup.migrateLegacyKeys()runs once on load: buckets whose key parses as protobuf text (prototext.UnmarshalintoUserId) are re-keyed, buckets that differ only in whitespace are merged, the file is rewritten. Existing tokens keep working across the upgrade that ships this.userKey(...); newTestLegacyKeysAreMigratedloads a file holding one-space, two-space and already-stable keys for the same user and asserts all three tokens authenticate and list, only the stable key survives on disk, and new tokens land under it.How tested
go test ./pkg/appauth/...— passes;TestLegacyKeysAreMigratedadded.golangci-lint run --new-from-rev=origin/main ./pkg/appauth/...with this repo's.golangci.yaml— no new findings (the Makefile's pinned v1.61.0 refuses to run against the current Go toolchain locally; CI will run its own).appauth.json, confirmed the detrand branch invendor/google.golang.org/protobuf/internal/encoding/text/encode.go.Related
changelog/unreleased/fix-appauth-stable-user-key.md🤖 Generated with Claude Code
https://claude.ai/code/session_01WpoeSoKYEdgQcWjEzTVKpT