-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Personal API Keys Discussion #4849
Comments
This makes sense to me so far. Are you thinking of deprecating personal API keys, or is #3 in addition to personal API keys? I feel we can do away with personal API keys as things stand. I'm a bit wary of introducing a new key without a migration path / reconciliation step for existing keys. My assumptions here (which I don't know are correct or not yet):
|
Project Secret in addition to Project API Key sounds interesting.
|
@Twixes' questions (brainstorming as I go):
|
@neilkakkar's assumptions:
|
Copying "the problem" from here:
Organization/team level, and scoped (like in github, screenshot below) keys sound like the way to go somehow. Regarding |
Ok, even worse (and not mentioned above), is that for people with multiple orgs, Personal API keys will transcend those too. Was implied earlier, but not explicitly mentioned in the issue. |
@mariusandra seems like this aligns with solution |
Feature flags could actually benefit from a solution like the one I mentioned on #4713, where we do away with Personal API Keys without a new key. Plugins that hit the API on the other hand (at least how I'm envisioning it), using a secret project key would be quite neat. |
Following up here on any further thoughts |
Sorry, for joining this conversation but I am still very much concerned and unclear what the current status of using the The above conversation is suggesting to me using feature flag will return the flags of the project I have selected in the |
Hey @weyert! This here is a deeper discussion about how to restructure auth around Personal API Keys. Any problems that existed with using feature flags in server-side libraries were fixed, as I mentioned on Slack. See #4764 and PostHog/posthog-node@5a14e6c for |
More context / same issue: https://posthog.slack.com/archives/C01F31E9PRD/p1627475465099300 |
I would like to re-open this discussion. I am having a requirement at work were I would like to define For example, you have data processing jobs which run every few hours which fetches data from third parties. Occasionally the third party might have spike in traffic and ask to temporary postpone our jobs until the high traffic has passed or maybe the third party is having issues. For this reason, I would like to use feature flags to temporary stop jobs for doing outgoing requests as its easier then needing to redeploy the service to change environment variables etc. The only current problem I am having is that I can't define server-side feature flags that are only accessible for server-side code and don't get exposed on the client-side e.g. web-applications or mobile applications. For this reason, I would like to propose the following as a first iteration to allow this functionality:
I think this is a reasonable solution to my problem at hand. I noticed there has been a discussion earlier about scoped personal access tokens but I don't think that would be able to solve the problem and typically it's problematic to use user-specific access tokens e.g. what happens when the user gets disabled or deleted etc? I am happy to work on the necessary PRs to introduce this functionality In the future I can imagine we could build upon this by for example support depending feature flags, e.g. only enable front-end feature flags when backend feature flag A and B are enabled etc. |
Hey @weyert! So let's go step-by-step here. I think a project secret makes sense, so let's start with that. Once that's done we can look into the best way of having "hidden" flags. So for a project secret:
I wonder if @Twixes has any thoughts here given you're probably the person with the most context on our authentication mechanisms. |
Ah okay, but it should still show up together with the other project api key, correct?
Hmm, maybe for now we could limit the change behind a feature flag and only limit it to the feature flag related endpoints?
Great
Looking forward to hear from @Twixes :) |
We could do this iteratively, yes. However, I do worry about this endpoint-specific code sitting there and for a long time (ever?) we don't actually implement it everywhere else but we've now rolled out this change to people like yourself who want to depend on it. In general I'm fine with starting with one endpoint though |
Awesome, I will have a crack at it :) |
How difficult would it be to scope API keys to end-points? |
We don't currently have plans to implement scoping for personal API keys, but regardless of that, we very strongly advocate against exposing any personal API key on the client side. A personal API key is tied to a specific user and their identity even if strictly scoped, so it should be almost as private as a password. @aurovrata |
Hey, |
@NikoFoX that's exactly what we recommend doing, except the read API key is tied to someone's account, not to the project in general. To really have a "project read API key", you can create a new fake user who will only have access to the project. Your suggestion makes sense though - multiple configurable project API keys sounds like a reasonable ask. |
I was about to dive head-first into this but authentication is such a foundational aspect of everything that I think this needs some discussion first.
Problem
#4713 first raised the issue of feature flags in our server-side libraries being subject to project changes in the UI which was a quite a significant issue. That was fixed in #4764.
However, the same problem also affects:
In addition, while the integrity issue is fixed with feature flags, it is still far from optimal that we ask people to use a Personal API Key with org-level access in PostHog libs. I wouldn't be comfortable with a key attached to my name in a team project.
So there are a few problems here:
Potential Solutions
0. In Any Case...
Regardless of what solution we go with below, we probably need to update all relevant view sets to respect the
team_id
set when specifying a project on an API call. This was done forapi/feature_flag
on #4764.1. Forcing Project Specification with Personal API Keys
This ensures people are explicit about what project they want to interact with programmatically. It's probably the simplest solution. Solves problem 1, but not really problem 2. I still would need a personal key on a plugin and feature flags, and that's not great.
2. Scoped Personal API Keys
Almost the same as above, with a little bit more work to shift the project definition to the key creation step rather than the key usage step.
3. Secret Project Key
This can also be done alongside one of the above, but paired with
#0
, it fixes both problems.The secret project key would be a shared key among all members of the project, much like the token (project API key), except it would be secret (and prefixed as such) and would allow access to the same things a personal API key does (perhaps with a few exceptions), except limited to a single project.
This would be big for plugins, and also a good thing for feature flags.
Take plugins for example. Currently, to use the PostHog API, they have to ask the user for a Personal API Key. We have some frontend logic to generate and autofill this in some cases, but that's really not optimal, as that plugin is now impersonating someone (same with feature flags).
If plugins want to provide devs with the ability to access the API, they need something better than generating full org access identifiable Personal API Keys in the background. A secret project token would make an implementation for PostHog/plugin-server#401 clean and secure, for instance.
4. Something else?
...
What next?
If you couldn't tell, I'm advocating for
#3
. Yes it's yet another key, but it solves an important problem. Wanted to get some thoughts before messing a lot with auth though.This issue would also be split into at least 2 PRs:
cc @Twixes
The text was updated successfully, but these errors were encountered: