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

🐛 token authenticate #621

Merged
merged 4 commits into from
Jun 11, 2024
Merged

Conversation

roceb
Copy link
Contributor

@roceb roceb commented Mar 30, 2024

fix for issue / #619
Missing Bearer token return error instead of panicking.
Also updated Client.send() method to work with bearer tokens.

@roceb roceb force-pushed the bugfix/tokenAuthenticate branch from 1ed3563 to e8af612 Compare March 30, 2024 13:53
@roceb roceb changed the title [fix] token authenticate 🐛 token authenticate Mar 30, 2024
auth/builtin.go Outdated Show resolved Hide resolved
auth/builtin.go Outdated Show resolved Hide resolved
auth/builtin.go Outdated Show resolved Hide resolved
auth/builtin.go Outdated Show resolved Hide resolved
auth/builtin.go Outdated
if splitToken[0] != "Bearer" {
return "", errors.New("authentication header not of type bearer")
}
token := strings.TrimSpace(splitToken[1])
Copy link
Contributor

@jortel jortel Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in a SEGV when requestToken="Bearer". no token.

parseToken() should return NotValid which will result in the request http=403 (forbidden) instead of 500.

auth/builtin.go Outdated

// Parse Token out of a string
func ParseToken(requestToken string) (string, error) {
splitToken := strings.Split(requestToken, " ")
Copy link
Contributor

@jortel jortel Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should:

requestToken = strings.TrimSpace(requestToken)

so that " Bearer " will be valid.

Also the "Bearer" header should be optional or, the binding.Client will be broken. Or, the binding.Client.send() needs to add the "Bearer".
I don't know if it's optional in JWT (or not).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bearer is for the type of schema and JWT is the encoding. JWT encodes to the Bearer schema. So unless there are plans to support different schemas, then Bearer should be included.

As far as:
requestToken = strings.TrimSpace(requestToken)
Is there a use case for " Bearer "? This seams like a bad formatted request and shouldn't be allowed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bearer is for the type of schema and JWT is the encoding. JWT encodes to the Bearer schema. So unless there are plans to support different schemas, then Bearer should be included.

Yes, I understand the difference.

Is there a use case for " Bearer "? This seams like a bad formatted request and shouldn't be allowed.

Just suggesting that API could be tolerant of curl users trying to do the right thing.
That said, I suppose the standard is not that hard to follow.

Copy link
Contributor

@jortel jortel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think changes to the AUTH layer is a good first issue.

@roceb
Copy link
Contributor Author

roceb commented Apr 3, 2024

We all have to start somewhere.

@roceb roceb force-pushed the bugfix/tokenAuthenticate branch from 651c0ba to 62865af Compare April 3, 2024 04:11
Ross added 3 commits April 3, 2024 00:13
Signed-off-by: Ross <ross@roceb.xyz>
Signed-off-by: Ross <ross@roceb.xyz>
- Used code style for return and formatting
- Replaced string.split with string.field to avoid panic

Signed-off-by: Ross <ross@roceb.xyz>
@roceb roceb force-pushed the bugfix/tokenAuthenticate branch from 62865af to 46a9ee4 Compare April 3, 2024 04:13
@jortel
Copy link
Contributor

jortel commented Apr 3, 2024

Thanks for the PR and requested changes @roceb.

We still need to change the Client.send() method like:

- request.Header.Set(api.Authorization, r.token.Token)
+ request.Header.Set(api.Authorization, "Bearer "+r.token.Token)

Else, the binding will no longer work with our API.

Unfortunately, I don't think our CI does not run with auth enabled and won't catch this.

Signed-off-by: Ross <ross@roceb.xyz>
@roceb
Copy link
Contributor Author

roceb commented Apr 3, 2024

Thank you for your time and patience @jortel . I have updated Client.send() method. Let me know if there is anything else?

@jortel jortel added this to the v0.5.0 milestone Jun 5, 2024
Copy link
Contributor

@jortel jortel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jortel jortel merged commit c28822e into konveyor:main Jun 11, 2024
3 checks passed
@jortel jortel mentioned this pull request Jun 11, 2024
jortel added a commit that referenced this pull request Jun 12, 2024
Fix auth unit tests broken by:
#621.

Signed-off-by: Jeff Ortel <jortel@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants