-
Notifications
You must be signed in to change notification settings - Fork 14
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 JWT flow #426
Add JWT flow #426
Conversation
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.
Some comments
810c3fa
to
ec99e32
Compare
ec99e32
to
1acaa3e
Compare
pkg/authenticator/jwt/requests.go
Outdated
req.Header.Set("Content-Type", "text/plain") | ||
req.Header.Set("Content-Length", string(len(formattedJwt))) | ||
req.Header.Set("User-Agent", "k8s") |
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.
Do we want to add support for accept-encoding header?
Conjur is able to return access token already encoded base64 instead of plain json (1, 2)
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.
Currently the components that use authn-k8s-client do the encode themselves . I think this is good idea but not in scope. I wanted to be aligned with the auhtn-k8s flow
235938e
to
82cfcc7
Compare
CHANGELOG.md
Outdated
@@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
|
|||
### Added | |||
- Add support for tracing with OpenTelemetry. This adds a new function to the authenticator, `AuthenticateWithContext`. The existing funtion, `Authenticate()` is deprecated and will be removed in a future upddate. [cyberark/conjur-authn-k8s-client#423](https://github.com/cyberark/conjur-authn-k8s-client/pull/423) | |||
- Authn JWT flow support [cyberark/conjur-authn-k8s-client#426](https://github.com/cyberark/conjur-authn-k8s-client/pull/426) |
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.
@szamir1 @shulifink
May you review my code
e9d0cd1
to
8adadfe
Compare
authenticatingIdentity = "" | ||
} | ||
|
||
req, err := AuthenticateRequest( |
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.
i think we should align the context handling with this code
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 what we talked about and i fixed
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.
Oh i see i done it in all error handling in the function
8adadfe
to
076654d
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.
Small comments, great job
86f070f
to
6a81934
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.
Looking good, left a few comments
6a81934
to
5cf4125
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.
LGTM! 👍
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 good!!!
Some editorial comments and a possible missing strconv.Itoa()
.
pkg/authenticator/jwt/config.go
Outdated
config.Common = common.Config{} | ||
config.Common.LoadConfig(settings) | ||
|
||
for key, value := range settings { |
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.
Instead of looping through the range of settings, couldn't we see if the "JWT_TOKEN_PATH" entry exists and then use it? Something like this?:
if path, exists := settings["JWT_TOKEN_PATH"]; exists {
config.JWTTokenFilePath = path
}
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.
Good point thanks
pkg/authenticator/jwt/requests.go
Outdated
} | ||
|
||
req.Header.Set("Content-Type", "text/plain") | ||
req.Header.Set("Content-Length", string(len(formattedJwt))) |
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.
When an int is typecast using string()
, the int value is interpreted as Unicode. I believe that what we need here is:
req.Header.Set("Content-Length", strconv.Itoa(len(formattedJwt)))
pkg/authenticator/jwt/requests.go
Outdated
func createUrl(authnURL string, account string, username string) string { | ||
if len(username) > 0 { | ||
return fmt.Sprintf("%s/%s/%s/authenticate", authnURL, account, url.QueryEscape(username)) | ||
} else { |
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.
The if
block ends with a return, so the } else {
isn't needed. That is, this should be:
if len(username) > 0 {
return fmt.Sprintf("%s/%s/%s/authenticate", authnURL, account, url.QueryEscape(username))
}
return fmt.Sprintf("%s/%s/authenticate", authnURL, account)
@@ -44,6 +45,8 @@ func ConfigFromEnv(readFileFunc common.ReadFileFunc) (Configuration, error) { | |||
func getConfiguration(url string) (Configuration, error) { | |||
if strings.Contains(url, k8sAuthenticator.AuthnType) { | |||
return &k8sAuthenticator.Config{}, nil | |||
} else if strings.Contains(url, jwtAuthenticator.AuthnType) { |
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.
Instead of using an if/else
block here, you could optionally use switch
without a statement (i.e. evaluating expressions in the case statements). I think this makes it a little more obvious that there are 3 possible results for which we're looking. For example:
switch {
case strings.Contains(url, k8sAuthenticator.AuthnType):
return &k8sAuthenticator.Config{}, nil
case strings.Contains(url, jwtAuthenticator.AuthnType):
return &jwtAuthenticator.Config{}, nil
default:
return nil, fmt.Errorf(log.CAKC063, url)
}
pkg/authenticator/jwt/config.go
Outdated
|
||
func configureLogLevel(level string) { | ||
validVal := "true" | ||
if level == validVal { |
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.
You could also use a switch statement here. I think this makes it a little more obvious that there are three possible outcomes (2 good, 1 bad):
switch level {
case validVal:
log.EnableDebugMode()
case "":
// Log level not configured
break
default:
// Log level is configured but it's invalid
log.Warn(log.CAKC034, level, validVal)
}
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.
Good point. Moved it to ConfigFactory to be in one place
5cf4125
to
25a3282
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.
LGTM
I fixed your comments so i will merge. If there anything else let me know and i will open separate PR :)
Desired Outcome
Added JWT flow to the authenticator
Connected Issue/Story
ONYX-14722
Changelog
CHANGELOG update
Test coverage
changes, or
Documentation
README
s) were updated in this PRBehavior
Security