-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add token based authorization #90
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Santhosh Fernandes <[email protected]>
37b0999
to
1eefbeb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to discuss overall approach for the secret store implementation and JWT auth. Once we agree on that we will also need to add tests to this PR.
|
||
valid, statusCode := utils.ValidateToken(ctx, kfcfg.HostConfig, reqToken) | ||
if !valid { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we set a status code above this indicating Unauthorized?
"net/http" | ||
"os" | ||
|
||
jwt "github.com/dgrijalva/jwt-go" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repo is no longer maintained, we should use the maintained one here:
https://github.com/golang-jwt/jwt
|
||
var jwtSecretKey string | ||
if conf.SecretsType == "ENV" { | ||
jwtSecretKey = os.Getenv(conf.SecretsKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should be clear and call this "SecreteKeyName" or something like that as it is not the actual key, but just the name of the secret key to retrieve
} | ||
|
||
token, err := jwt.Parse(reqToken, func(token *jwt.Token) (interface{}, error) { | ||
return []byte(jwtSecretKey), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about algorithm validation (SigningMethodHMAC)?
return | ||
} | ||
|
||
valid, statusCode := utils.ValidateToken(ctx, kfcfg.HostConfig, reqToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about moving jwt validation to chi and use protected routes? I think this would be better than implementing here. https://github.com/go-chi/jwtauth
|
||
// secrets | ||
SecretsKey string | ||
SecretsType string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For supporting different secret stores it seems like the secrets package would provide more backend support. Otherwise we will have to keep implementing backends for different cloud platforms ourself.
https://pkg.go.dev/gocloud.dev/secrets
1eefbeb
to
3b10f32
Compare
Signed-off-by: Santhosh Fernandes <[email protected]>
3b10f32
to
0b35c4b
Compare
Signed-off-by: Santhosh Fernandes [email protected]
It enables token-based authorization. Env variables or vaults can be used to store secrets.