-
Notifications
You must be signed in to change notification settings - Fork 905
OAuth now uses client TLS certs (if configured) #5042
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0490733
OAuth now uses client TLS certs (if configured)
normana10 54ee429
Update docs
normana10 ae0c5dd
Cleaning
normana10 5df2ca8
Fix lint errors and generate static files
normana10 d71be77
Fix lint error and regenerate more static files
normana10 83fcf35
Suppress lint error
normana10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,11 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co | |
return xerrors.Errorf("OIDC issuer URL must be set!") | ||
} | ||
|
||
ctx, err := handleOauth2ClientCertificates(ctx, cfg) | ||
if err != nil { | ||
return xerrors.Errorf("configure oidc client certificates: %w", err) | ||
} | ||
|
||
oidcProvider, err := oidc.NewProvider(ctx, cfg.OIDC.IssuerURL.Value) | ||
if err != nil { | ||
return xerrors.Errorf("configure oidc provider: %w", err) | ||
|
@@ -1248,3 +1253,21 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg | |
} | ||
return connectionURL, ep.Stop, nil | ||
} | ||
|
||
func handleOauth2ClientCertificates(ctx context.Context, cfg *codersdk.DeploymentConfig) (context.Context, error) { | ||
if cfg.TLS.ClientCertFile.Value != "" && cfg.TLS.ClientKeyFile.Value != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (not blocking merge): You could invert the control-flow here to reduce indentation! |
||
certificates, err := loadCertificates([]string{cfg.TLS.ClientCertFile.Value}, []string{cfg.TLS.ClientKeyFile.Value}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return context.WithValue(ctx, oauth2.HTTPClient, &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ //nolint:gosec | ||
Certificates: certificates, | ||
}, | ||
}, | ||
}), nil | ||
} | ||
return ctx, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Code generated by 'make coder/scripts/apitypings/main.go'. DO NOT EDIT. | ||
// Code generated by 'make site/src/api/typesGenerated.ts'. DO NOT EDIT. | ||
|
||
// From codersdk/enums.go | ||
export type Enum = "bar" | "baz" | "foo" | "qux" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 already have
ClientCAFile
as a configuration option, so you should be able to remove the configuration changes here!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 going to expand on my use-case a bit more because I think it's slightly different
So with my changes in the config file we have:
CertFiles
KeyFiles
ClientCAFile
ClientCertFile
(new)ClientKeyFile
(new)In my org, I have been given a wildcard cert
*.coder.normana10.example.com
and a "system/identity" certnormana10.example.com
I need to use the wildcard cert for all "serving" and the "identity" cert for all external calls that Coder makes
(I'm not going to say this is "correct", but it's just how my org does things)
So if I wanted Coder to terminate TLS my config would look like:
CertFiles
=/path/to/wildcard.cert
KeyFiles
=/path/to/wildcard.key
ClientCAFile
=/path/to/ca.cert
(Only used to verify client certs ifClientAuth
is set to verify)ClientCertFile
(new) =/path/to/identity.cert
ClientKeyFile
(new) =/path/to/identity.key
So
ClientCAFile
(as far as I've seen) looks like it's just used to verify clients connecting to Coder. Where I'm looking to set the client certs Coder uses when connecting to external servicesIf that makes sense?
For full transparency, my actual config doesn't have Coder terminating TLS, so realistically I'd just have my two new configs set
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.
All makes sense! I appreciate the context... the changes look good to me!