Add per-user API keys with global fallback - #46
Conversation
smileBeda
left a comment
There was a problem hiding this comment.
Code wise all OK, now testing locally and will merge if passed
|
I see one issue which is not related to functionality or code, but safety:
However, there is only ONE true safe approach to this, which is, the user has to input a decryption key EVERY TIME the api key is used. Then, the api keys could be stored encrypted and NO ONE could read them. This is cumbersome UI. So I propose this:
What do you think? |
|
I agree with your assessment and a warning for now is the easiest workaround. I'll sort it in the coming days :) |
|
Ah right, I did not think of that! Although I can reset that password as machine owner, it is as close as it gets to real security. There is another UI issue, when you add a BYO OpenAI api key and do NOT add the URL for the endpoint - but global overwrites it with something else (custom url), then it tries to use that URL So I think after adding these 2 warnings (phrase them as you like, above are just a mix of AI and my own wording) we can release this. Then, probably after that add a new ticket for handling the security aspect. |
c889592 to
fe2bbdb
Compare
fe2bbdb to
a52ffd2
Compare
|
@smileBeda Hiya :) sorry for the delay! I update the PR. all the best :) |
|
Hi @tinkermesomething - sorry the delay too, lol. I then tested the new BYO key features and they seem to work for example for YT, but not for LastFM, which still requires a global key (even if I set my own, it will say Looking at the code it seems
As such the lastFM button will always be disabled (unless using global keys if provided). I did not physically test the other keys (Openai, Listebrainz user, and so on), but looking at the code this is what I see:
|
|
PS I made a release which has yet another alembic migration so my edits to your PR will be wrong as well now. |
Users can now configure their own Last.fm, YouTube, and LLM API keys in their Profile page. When set, user keys override the global keys for that user's sessions. If not set, falls back to admin-configured global keys automatically. - Add API key columns to User model - Add migration for new columns - Add getter methods to DataHandler with user->global fallback - Update preview/prehear/ai_prompt to use per-user keys - Add API key form fields to profile page - Handle API key form submission in profile update
- Security warning: keys are stored on the server, use at own risk - LLM URL warning: set correct base URL when using own key - TODO comment for future key encryption via user password
- Fix get_openai_recommender_for_user to check global recommender before API key gate (was returning None when recommender was set but no raw key strings configured) - Restore _personal_source_definitions to no-args signature to avoid breaking test monkey-patches; BYO Last.fm override applied inline in personal_recommendations after user resolution - Fix _fetch_lastfm_top_tracks and prehear to use per-user Last.fm and YouTube keys via getter methods - Fix personal discovery flow to support BYO-only Last.fm users with no global admin keys configured - Rebase onto upstream/main; update migration down_revision to 20260303_01
a672e5d to
dc60b8d
Compare
|
all fixed on my end :) |
Users can now configure their own Last.fm, YouTube, and LLM API keys in their Profile page. When set, user keys override the global keys for that user's sessions. If not set, falls back to admin-configured global keys automatically.