Skip to content

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 6 commits into from
Nov 13, 2022

Conversation

normana10
Copy link
Contributor

Hi,

I'm trying to get Coder deployed within my organization but our OpenID Connect provider requires valid TLS client certificates before it will respond to the .well-known HTTP call that the oidc library makes

These changes configure the oidc library to use (optional and configurable) client TLS certificates

I've verified these changes work with my personal/homelab OpenID Connect provider when I configure my reverse proxy to require TLS client certs

(Let me know if I missed anything, I'm new to Go 😄)

Also let me know if there's some glaringly obvious Go-ish way to do this with like environment variables or command line args that I'm unaware of

Thanks!

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Your contribution is appreciated!

Is it possible for us to use the existing ClientCAFile property instead of adding these new ones? RIght now, it's consumed when TLS is enabled, but it seems like we should make it always apply instead and add the oauth2.HTTPClient to the context.

If you need help or have questions, feel free to ping me! Happy to add this (and we can do a release afterward so you can use it).

@@ -1248,3 +1253,21 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg
}
return connectionURL, ep.Stop, nil
}

func handleOauth2ClientCertificates(cfg *codersdk.DeploymentConfig, ctx context.Context) (context.Context, error) {
if cfg.TLS.ClientCertFile.Value != "" && cfg.TLS.ClientKeyFile.Value != "" {
Copy link
Member

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!

Copy link
Contributor Author

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" cert normana10.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 if ClientAuth 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 services

If 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

Copy link
Member

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!

@normana10 normana10 requested a review from a team as a code owner November 13, 2022 01:55
@normana10 normana10 requested review from jsjoeio and removed request for a team November 13, 2022 01:55
@@ -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 != "" {
Copy link
Member

Choose a reason for hiding this comment

The 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!

@kylecarbs kylecarbs merged commit 9578ce9 into coder:main Nov 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2022
@github-actions github-actions bot deleted the oauth-use-client-certificate branch May 17, 2024 00:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants