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

Need a non-caching version of the client #13

Open
petewall opened this issue Jan 1, 2024 · 10 comments
Open

Need a non-caching version of the client #13

petewall opened this issue Jan 1, 2024 · 10 comments

Comments

@petewall
Copy link
Contributor

petewall commented Jan 1, 2024

I'm using this to build a deployment in Kubernetes, so the process will stay alive for a long time, unlike a CLI program. It'd be nice to make a version of the client that doesn't use the cache file.

@petewall
Copy link
Contributor Author

petewall commented Jan 1, 2024

If you're interested, I could try and whip up a PR for this. It'd keep the original behavior intact.

@rspier
Copy link
Owner

rspier commented Jan 3, 2024

I'm not opposed...... but.....

Can you help me understand why the cache file is something you want to avoid on Kubernetes? The process might stay alive for a long time, or might be killed at any moment.

Ecobee refresh tokens only last for 30 days so if you aren't storing fresh refresh tokens at least that often, you'll be in a bad way. https://www.ecobee.com/home/developer/api/documentation/v1/auth/token-refresh.shtml#:~:text=on%20handling%20errors.-,Token%20Expiry,-The%20following%20table

Thinking about how I might implement this, the simplest thing would be to use a PVC to store the authcache file. Alternatively, we could store the refresh (and maybe access) token back in a Kubernetes Secret, or dynamically in something like Vault. For the latter, I'd want to make a "pluggable" authcache system so you can choose how it is stored.

What were you thinking?

@petewall
Copy link
Contributor Author

petewall commented Jan 3, 2024

Yeah, good points. One of the thing I'm trying to avoid in a Kubernetes deployment is secrets stored on the file system, or anywhere except for Kubernetes Secrets. You're totally right that pods will go down without warning, so it'd need a way to store the current refresh token (and maybe access token) or generate a new one on startup...

@petewall
Copy link
Contributor Author

petewall commented Jan 3, 2024

I mean, Ecobee isn't the first to use refresh tokens, this has to be a solved pattern.

In an ideal world, I can deploy my ecobee data exporter (which uses your library) as a Deployment, along with a Secret that contains the client id, and maybe some other secret that'll let the process request refresh and access tokens.

@petewall
Copy link
Contributor Author

petewall commented Jan 3, 2024

This library is great, BTW! Happy that it exists!

@petewall
Copy link
Contributor Author

petewall commented Jan 3, 2024

Maybe I'm not fully understanding Ecobee's authorization process fully. Does the 30 day expiration of the refresh token mean that every 30 days, I'll have to do the manual process of loading the website, installing my app, and pasting the authorization code?

@rspier
Copy link
Owner

rspier commented Jan 4, 2024

Maybe I'm not fully understanding Ecobee's authorization process fully. Does the 30 day expiration of the refresh token mean that every 30 days, I'll have to do the manual process of loading the website, installing my app, and pasting the authorization code?

After 30 days you can't use the initial refresh token to get a new access token.

As long as your job is running, you're fine, because every time you get a new access token, you get a new 30 day refresh token too. But once your job restarts, you need a still valid refresh token or you have to start over from scratch.

@rspier
Copy link
Owner

rspier commented Jan 4, 2024

@rspier
Copy link
Owner

rspier commented Jan 4, 2024

https://kubernetes.web.cern.ch/blog/2023/04/12/propagating-oauth2-tokens-made-easier/ looks like an interesting approach. It might need some tweaking. (This is basically outsourcing the refreshing to the operator, which stores it in a Secret for you.)

@petewall
Copy link
Contributor Author

petewall commented Jan 9, 2024

Great resources. I still want to think about this and the best way to deploy something with this library in K8s.
Honestly, this was a winter break hack project for me, but I do want to return to it...
Just letting you know I haven't dropped this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants