Skip to content

[Feature Request] Update API key generation to use argon2id  #284

@matoszz

Description

@matoszz

Similar to the way we persist a hash of the user's inputted password here, we should update the API token and Personal Access Tokens schema and token creation to leverage the same hashing.

You can use utils.CreateDerivedKey, the same way the user password is done today:

hash, err := passwd.CreateDerivedKey(password)

Instead of a hook here, you would update the default function on both the api and personal access token schemas, e.g. here on api tokens

token := keygen.PrefixedSecret("tola") // api token prefix

Additionally, the auth middleware needs to be updated to use derived key instead of the token in the request:

func checkToken(ctx context.Context, conf *Options, token, orgFromHeader string) (*auth.AuthenticatedUser, string, error) {

Example from user password login:

valid, err := passwd.VerifyDerivedKey(*user.Password, req.Password)
if err != nil || !valid {
metrics.RecordLogin(false)
return h.BadRequest(ctx, rout.ErrInvalidCredentials, openapi)
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions