Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug/Enhancement] Cache the random HMAC_KEY #3540

Closed
iBicha opened this issue Jan 6, 2023 · 8 comments
Closed

[Bug/Enhancement] Cache the random HMAC_KEY #3540

iBicha opened this issue Jan 6, 2023 · 8 comments
Labels
question Further information is requested

Comments

@iBicha
Copy link
Contributor

iBicha commented Jan 6, 2023

Is your enhancement request related to a problem? Please describe.
I noticed that in a lot of instances, tokens stop working ("Invalid signature")
I investigated a bit, and I noticed that if HMAC_KEY will be random after reach restart, if it was not configured.
This means that all tokens will be immediately invalid after each restart.
This is strange, since it is recommended from people who host Invidious to restart often.

Describe the solution you'd like
I would like to have the HMAC_KEY (the randomly generated one - HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)) to be cached between restarts, so that tokens do not randomly stop working.
If we do not want to do that for some reason, then this config should be mandatory (e.g. invidious would not start without it - but that's an overkill probably)

Describe alternatives you've considered
I do not see any other way to prevent tokens from going invalid.

Additional context

This is not for the web frontend, this is for another app (Playlet) so we're using the token not the cookie. For that reason, it's important to keep the token alive. This has been a blocker and painful to find the account logged out every time.

@iBicha iBicha added the enhancement Improvement of an existing feature label Jan 6, 2023
@unixfox
Copy link
Member

unixfox commented Jan 6, 2023

Just set the HMAC_KEY in the config file and you won't have any issue anymore: https://github.com/iv-org/invidious/blob/master/config/config.example.yml#L465

@unixfox unixfox closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2023
@iBicha
Copy link
Contributor Author

iBicha commented Jan 6, 2023

@unixfox the problem is not an instance I control, it's instances under https://docs.invidious.io/instances/
This is not documented clearly enough for them. It's important piece that most people might miss.

@unixfox
Copy link
Member

unixfox commented Jan 6, 2023

Then send a message to each instance maintainer to set this value, I'll add that in the docs though.

All the maintainers have opened an issue here so feel free to ping them here: https://github.com/iv-org/documentation/issues

EDIT: I did ping all the maintainers in the github issues. wait and see

@unixfox unixfox added question Further information is requested and removed enhancement Improvement of an existing feature labels Jan 6, 2023
@iBicha
Copy link
Contributor Author

iBicha commented May 30, 2023

@unixfox Kinda stumbling on this issue again (iBicha/playlet#77)

I really think this is a simple change that we can introduce to Invidious that persists the randomly generated key in the case it was not manually configured. Saving it to a file in a known location and checking it later is fine.
Otherwise Invidious should fail to start to bring the issue to the attention of the maintainer.

And there isn't a good way to know if an instance if properly configured or not, until it starts randomly failing to maintain sessions, or to authorize tokens.
This feels like a low-hanging fruit to me

@unixfox
Copy link
Member

unixfox commented May 30, 2023

No there is no easy way to cache the hmac key.

Instead we can introduce a way to display in the API if the hmac key is set and then you can use it in your app.

This also will help us deny or accept the new public instances if the hmac key is missing or not.

If you are interested and the solution is good for you. You can either submit a PR with this new change or create an issue for tracking the feature request.

@iBicha
Copy link
Contributor Author

iBicha commented May 30, 2023

No there is easy way to cache the hmac key.

Are you saying there's an easy way, or no easy way to cache the key?

@unixfox
Copy link
Member

unixfox commented May 30, 2023

I've edited my last comment.

@iBicha
Copy link
Contributor Author

iBicha commented May 30, 2023

#3828

jakubgs added a commit to jakubgs/nixos-config that referenced this issue Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants