-
Notifications
You must be signed in to change notification settings - Fork 35
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 hack to generate jwt token. #534
Conversation
Signed-off-by: Jeff Ortel <jortel@redhat.com>
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.
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
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.
Looks great!
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
@@ -71,9 +74,15 @@ type Builtin struct { | |||
// | |||
// Authenticate the token | |||
func (r *Builtin) Authenticate(request *Request) (jwToken *jwt.Token, err error) { | |||
token := request.Token | |||
token := strings.Replace(request.Token, "Bearer", "", 1) | |||
token = strings.Fields(token)[0] |
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.
hint: support proper header value: Authorization: <type> <token>
.
Signed-off-by: Jeff Ortel <jortel@redhat.com>
Signed-off-by: Jeff Ortel <jortel@redhat.com>
@@ -93,32 +102,52 @@ func (r *Builtin) Authenticate(request *Request) (jwToken *jwt.Token, err error) | |||
} | |||
claims, cast := jwToken.Claims.(jwt.MapClaims) | |||
if !cast { | |||
err = liberr.Wrap(&NotAuthenticated{Token: token}) | |||
err = liberr.Wrap( | |||
&NotValid{ |
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.
hint: This (and below) is a token validation error, not authentication.
} | ||
|
||
func (e *NotAuthenticated) Is(err error) (matched bool) { | ||
_, matched = err.(*NotAuthenticated) | ||
notAuth := &NotAuthenticated{} | ||
matched = errors.As(err, ¬Auth) |
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.
hint: Using As()
is more robust in case of wrapped errors.
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.
LGTM
@@ -22,26 +24,34 @@ type Validator struct { | |||
// - The token references a task. | |||
// - The task is valid and running. | |||
// - The task pod valid and pending|running. | |||
func (r *Validator) Valid(token *jwt.Token, db *gorm.DB) (valid bool) { | |||
var err error | |||
func (r *Validator) Valid(token *jwt.Token, db *gorm.DB) (err error) { |
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.
Really like this refactor.
Add hack script to generate jwt tokens for _builtin_ auth. Likley used by actors such as the operator for migration related to upgrade. Related: - auth.Validator signature changed to return error. This is more flexible and _failures_ can be propagated. - auth.Builtin.Authenticate() returns NotAuthenticated when should have returned NotValid for clearity. - auth.NotValid includes `Reason`. --------- Signed-off-by: Jeff Ortel <jortel@redhat.com>
Add hack script to generate jwt tokens for builtin auth. Likley used by actors such as the operator for migration related to upgrade.
Related:
Reason
.