-
Notifications
You must be signed in to change notification settings - Fork 15
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
Refactor authn-k8s-client to be authentication flow generic #425
Conversation
8ad3b37
to
3dc627a
Compare
73d3808
to
469d7d2
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
1bba60a
to
4644da9
Compare
pkg/log/log_messages.go
Outdated
@@ -75,3 +75,5 @@ const CAKC059 string = "CAKC059 Path exists but does not contain regular file: % | |||
const CAKC060 string = "CAKC060 Setting %s given invalid value %s" | |||
const CAKC061 string = "CAKC061 Failed to validate setting for Authenticator configuration" | |||
const CAKC062 string = "CAKC062 Required Authenticator setting %s not provided" | |||
const CAKC063 string = "CAKC063 Can't find configuration for URL : %s" | |||
const CAKC064 string = "CAKC064 Can't find Authenticator for this configuration" |
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.
@tzheleznyak - What is the use-case for this?
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 are going to add support to authn-jwt to authn-k8s-client.
And this is the error message when the authn-client can't decide which authentication flow should run (authn-k8s or authn-jwt)
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.
How about "No authenticator configured. "
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.
or even better: "No authentication configured. "
Thanks for taking on this challenge! I think the interfaces that you've defined are a good start at making this client more pluggable. I'd like to make some suggestions that might simplify things a little bit. This will take a bit of rearranging, so we can chat about this tomorrow, and maybe pull some other folks in to get some consensus (Kumbi and Johah might be good to include). First, some high-level comments:
} |
@diverdane About 1: During development i came across dependency loop when i tried putting interfaces and factories in the same package. It what made me split factories to one separate and the interfaces to the common package. The common package is all code relevant to the main authenticator package that don't uses other packages inside authenticator and used by multiple packages inside authenticator. The name creators can be discussed and i can remove this directory and move the factories one step back. About 2:
These are not responsibilits of the authenticator that should only support two things:
|
4644da9
to
c5ec2e1
Compare
aa10a51
to
37b32ed
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.
Some thoughts
pkg/log/log_messages.go
Outdated
@@ -75,3 +75,5 @@ const CAKC059 string = "CAKC059 Path exists but does not contain regular file: % | |||
const CAKC060 string = "CAKC060 Setting %s given invalid value %s" | |||
const CAKC061 string = "CAKC061 Failed to validate setting for Authenticator configuration" | |||
const CAKC062 string = "CAKC062 Required Authenticator setting %s not provided" | |||
const CAKC063 string = "CAKC063 Can't find configuration for URL: %s" |
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.
In other repos we have been standardising on Unable
. So these would all become Unable to ...
func (config *Config) GetAuthenticationType() string { | ||
return AuthnType | ||
} | ||
|
||
func (config *Config) GetEnvVariables() []string { | ||
return envVariables | ||
} | ||
|
||
func (config *Config) GetRequiredVariables() []string { | ||
return requiredEnvVariables | ||
} | ||
|
||
func (config *Config) GetDefaultValues() map[string]string { | ||
return defaultValues | ||
} |
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.
These methods are a bit strange because they don't make use of the struct at all, and so could be static.
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.
But the usage inside Validate() and GatherSettings()
Is config.GetDefaultValues() so it will go to the config of the correct flow
// New creates a new authenticator instance from a token file | ||
func New(config authnConfig.Config) (*Authenticator, error) { | ||
accessToken, err := file.NewAccessToken(config.TokenFilePath) | ||
func New(config Config) (*Authenticator, 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.
I think it would be good for us to update this to NewAuthenticator
to make it explicit what this method is creating.
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.
Done
func (auth *Authenticator) Init(config *common.ConfigurationInterface) (common.AuthenticatorInterface, error) { | ||
var cfg = (*config).(*Config) | ||
authn, err := New(*cfg) | ||
if err != nil { | ||
return nil, fmt.Errorf(log.CAKC019) | ||
} | ||
|
||
return authn, nil | ||
} | ||
|
||
func (auth *Authenticator) InitWithAccessToken(config *common.ConfigurationInterface, token access_token.AccessToken) (common.AuthenticatorInterface, 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.
I'm not sure about the name of the method. I think we need something other than Init
that better captures what this method is doing.
This should also probably be a free standing function (not a method) since it doesn't use the auth struct at all.
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.
Lets discuss in the meeting
6745595
to
2b9a857
Compare
2b9a857
to
05b78aa
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.
This looks FANTASTIC!!! Thanks again for your patience on this! I really like how you broke out things into config
and common
.
I just have a few very minor editorial nits, otherwise this looks good-to-go.
CONTRIBUTING.md
Outdated
@@ -151,7 +151,7 @@ follow the instructions in this section. | |||
### Update the version, changelog, and notices | |||
1. Create a new branch for the version bump. | |||
1. Based on the unreleased content, determine the new version number and update | |||
the [version.go](pkg/authenticator/version.go) file. | |||
the [version.go](pkg/authenticator/common/version.go) file. |
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 like this moved? Should be pkg/authenticator/version.go
?
"github.com/cyberark/conjur-authn-k8s-client/pkg/access_token" | ||
"github.com/cyberark/conjur-authn-k8s-client/pkg/access_token/file" | ||
"github.com/cyberark/conjur-authn-k8s-client/pkg/authenticator/config" | ||
k8sAuthenitcator "github.com/cyberark/conjur-authn-k8s-client/pkg/authenticator/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.
Oops. Typo, should be k8sAuthenticator
.
"github.com/cyberark/conjur-authn-k8s-client/pkg/log" | ||
) | ||
|
||
func NewAuthenticator(conf config.Configuration) (Authenticator, 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.
I don't want to hold up the merge on this, but Go style guides (e.g. https://go.dev/doc/effective_go#commentary) recommend that any exported names should have a preceding doc comment that begins with that name, e.g.
// NewAuthenticator creates an instance of the Authenticator interface based on configured authenticator type.
(My IDE is running golint
automatically, so when I write a file I see warnings pop up. BTW golint
is deprecated, but there are replacements, e.g. golangci-lint
.)
05b78aa
to
320a410
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.
LGTM
Internal issue: ONYX-14722. |
Desired Outcome
As part of the authn-jwt side car in K8S this is first stage where we do refactor, that will allow adding more authentication methods.
Defining interface for Config And Authenticator and factories creating instances of them.
Folder structure change
Connected Issue/Story
ONYX-14719
CyberArk internal issue link: insert issue ID
Definition of Done
At least 1 todo must be completed in the sections below for the PR to be
merged.
Changelog
CHANGELOG update
Test coverage
changes, or
Documentation
README
s) were updated in this PRBehavior
Security