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

fix/refactor: Move auth.token_key and other parameters to AuthConfig structure #925

Merged
merged 5 commits into from
Sep 12, 2023

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Sep 11, 2023

The intent is to have a central place to fetch the configuration and validate it.

This way, starting the server will fail if the needed crypto configuration is not
set up appropriately.

This also moves the crypto package to internal which is more appropriate.

Closes: #923

@JAORMX JAORMX force-pushed the token-key branch 2 times, most recently from fecf453 to dbc5e13 Compare September 11, 2023 11:39
@JAORMX JAORMX requested a review from jhrozek September 11, 2023 11:40
jhrozek
jhrozek previously approved these changes Sep 11, 2023
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

The refactor is good. I would like the option to be used instead of the viper call consistently. The comment about config file pointing to another file or environment variable is more for later I think.

internal/crypto/crypto.go Outdated Show resolved Hide resolved
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

I'll have more comments later, but the code in handlers_auth.go I think needs to change if we're doing this. (That is the only part of the code which is that way, so I'd be happy to see it fixed.)

internal/reconcilers/reconcilers.go Outdated Show resolved Hide resolved
internal/config/auth.go Show resolved Hide resolved
Comment on lines 62 to 91
// EngineFromAuthConfig creates a new crypto engine from an auth config
func EngineFromAuthConfig(authConfig *config.AuthConfig) (*Engine, error) {
if authConfig == nil {
return nil, errors.New("auth config is nil")
}

if authConfig.TokenKey == "" {
return nil, errors.New("token key is empty")
}

return &Engine{
encryptionKey: authConfig.TokenKey,
}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of reversing this dependency, and having config.go have an .Engine() method?

It looks like the other usage is configuration params in GeneratePasswordHash, and I'd sort of prefer a non-magic struct as an argument there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

uhm... can't really add an Engine method without introducing an import cycle

internal/crypto/crypto.go Show resolved Hide resolved
internal/crypto/crypto.go Outdated Show resolved Hide resolved
internal/engine/executor.go Show resolved Hide resolved
…ig` structure

The intent is to have a central place to fetch the configuration and validate it.

This way, starting the server will fail if the needed crypto configuration is not
set up appropriately.

This also moves the `crypto` package to `internal` which is more appropriate.

Finally, the concept of `auth.token_key` changed from being a string to being a file.
The idea is that we'll have all secrets as files which will be referenced as kubernetes secrets.

Closes: #923
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

My only comment with the auth key being a string was resolved, so I'm happy with this PR version.

@JAORMX JAORMX merged commit 35ab0fd into main Sep 12, 2023
12 checks passed
@JAORMX JAORMX deleted the token-key branch September 12, 2023 13:03
JAORMX added a commit that referenced this pull request Sep 12, 2023
Add token_key_passphrase to file location overrides following #925
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.

auth.token_key is empty and not actually using a passphrase to encrypt oauth2 tokens
3 participants