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

Change the PK field #40

Closed
eagle-r opened this issue Jun 7, 2019 · 8 comments
Closed

Change the PK field #40

eagle-r opened this issue Jun 7, 2019 · 8 comments
Labels
breaking This involves breaking API changes bug Something isn't working
Milestone

Comments

@eagle-r
Copy link

eagle-r commented Jun 7, 2019

Is your feature request related to a problem? Please describe.
The PK on the APIKey model is the string containing the prefix and hash. This makes it challenging to work with when referencing it in URLs in many REST-based frameworks. eg. 2TothlA4.pbkdf2_sha256$36000$dfPh6LIy7NB3$FTA61Pvuq3gres5ZsclXimNCRz70jvDRl/ygYOjEiLc=. This contains a slash and other special chars that would typically be URL encoded.

Describe the solution you'd like
Either convert the model to use a standard integer PK or provide some other means to reference it in such a way

Describe alternatives you've considered
I'm not sure, but could this be handled through the solution being considered for #34?

@florimondmanca
Copy link
Owner

Hey, thanks for this.

I’m trying to understand the use case here. Are you trying to build an API to manage API keys? This package wasn’t originally intended for this kind of use case — more for private cross-service identification — so this explains why the PK is not friendly to being passed in URLs.

If migrating to a good old integer PK can make this easier for you, I’m open to the idea, though we need to make sure this doesn’t introduce any security risks.

@eagle-r
Copy link
Author

eagle-r commented Jun 7, 2019 via email

@florimondmanca
Copy link
Owner

Yes, makes sense!

Reading your comment, I actually think being able to manage API keys through REST endpoints secures behind authentication could be in the scope of this package. I suppose you built serializers and views for API keys to create the endpoint? Are they generic enough to be included built-in?

Anyway, as for the PK, I think you’ve got a fair point. We can create a data migration that moves the current PK (prefix + hash) to another field (actually probably two separate fields), and use a standard integer PK.

I’m a bit short on time at the moment (and also need to take a look at the abstract API key feature), so if you feel like giving this a shot, let me know!

@curtismorte
Copy link

curtismorte commented Jun 7, 2019

@eagle-r,
It's a bad idea to pass an API Key in a URL. You're essentially exposing your API Key.

With your reference to #34, that's a solution. However, I think it's actually a poor fix for the actual problem.

@florimondmanca, we need to normalize the table to have a generic based integer PK. With the completion of #34, those who need to change the PK to some other form of ID, say a UUID, will have the flexibility to do so.

@curtismorte
Copy link

@eagle-r and @florimondmanca,
In my opinion, while this is technically not a bug and is more of a feature enhancement, the issue should be considered with the same level of priority as a bug.

Using a Model View Set requires a PK. The current PK we have is not a valid form of PK.

@florimondmanca florimondmanca added bug Something isn't working and removed feature-request labels Jun 7, 2019
@florimondmanca
Copy link
Owner

Thanks for your input @curtismorte, and agreed on the fact that this fits the bug label better.

@eagle-r
Copy link
Author

eagle-r commented Jun 7, 2019

If I have time this weekend I'll have a go at submitting a PR.

@curtismorte I agree that exposing the key in the URL is a security risk.

@florimondmanca I assume that when you mentioned splitting the existing key into two fields you were talking about the prefix and hash being two separate fields? I actually feel this is even better than just replacing the PK by itself because it means that I can pass the prefix in the ModelVewSet if I need to without ever exposing the hash.

Thanks for all the input.

@florimondmanca
Copy link
Owner

Yes @eagle-r, I was referring to the prefix and hash. :-)

I think having the prefix used as a PK could make sense, but since it is tightly coupled to the generation/validation mechanism I would rather not have clients use it all over the place, at least for the sake of separation of concerns.

And storing the prefix separately while keeping the PK as is would induce data duplication.

So I think that to enable building CRUD on top of API keys, a simple integer PK (or anything else via customization) is enough. We don’t need to be fancy. :)

I agree that exposing the key in the URL is a security risk.

I don’t think you were exposing the API key, because it’s actual value can’t be retrieved from the prefix and hash.

The fact that we need to ask this question (can I use this PK in URLs?) is another sign that things need to change. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This involves breaking API changes bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants