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

chore: support mtls settings #2443

Merged
merged 1 commit into from
Dec 21, 2023
Merged

chore: support mtls settings #2443

merged 1 commit into from
Dec 21, 2023

Conversation

rajcspsg
Copy link
Contributor

closes #2211

@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (f2f5378) 64.30% compared to head (9350eec) 64.27%.

Files Patch % Lines
zio-http/src/main/scala/zio/http/SSLConfig.scala 18.18% 9 Missing ⚠️
...scala/zio/http/netty/server/ServerSSLDecoder.scala 50.00% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2443      +/-   ##
==========================================
- Coverage   64.30%   64.27%   -0.04%     
==========================================
  Files         139      139              
  Lines        8198     8207       +9     
  Branches     1530     1497      -33     
==========================================
+ Hits         5272     5275       +3     
- Misses       2926     2932       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rajcspsg
Copy link
Contributor Author

@adamgfraser still I need to write test. could you have quick glance whether the approach is correct.

@jdegoes
Copy link
Member

jdegoes commented Sep 24, 2023

@danestig Can you review and ensure this meets your needs?

@danestig
Copy link

Hello! Thanks for taking a stab at this @rajcspsg.

I have 2 concerns:

  1. How do I provide both client keytstore/key/certificate and a truststore/ca-certificate? Looking at the ClientSSLConfig they look mutually exclusive to me.
  2. Since I could not figure out 1 I have not tried this yet. Will mTLS be used to connect to both the proxy and the server, or only one of them? Client proxy mTLS support #2211 Is specifically about authenticating with mTLS with the proxy, I expected that to be configured in the proxy setting.

@rajcspsg
Copy link
Contributor Author

@danestig Sorry I missed your comment. I did mistake I updating the ClientSSLConfig config instead of ServerSSLConfig.
I going to configure only the proxy server verifies the client certificates, does that work for you?

@danestig
Copy link

@rajcspsg Yes, I believe that would solve my issue. Thank you.

final case class FromTrustStoreResource(trustStorePath: String, trustStorePassword: String) extends ClientSSLConfig
final case class FromTrustStoreFile(trustStorePath: String, trustStorePassword: String) extends ClientSSLConfig
sealed trait ClientAuth
case object RequireClientAuth extends ClientAuth
Copy link
Member

Choose a reason for hiding this comment

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

@rajcspsg Can you put these in the companion object of ClientAuth?

Copy link
Member

Choose a reason for hiding this comment

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

Also, once you put them there, they can have shorter names, e.g.:

object ClientAuth {
  case object Required extends ClientAuth
  case object None extends ClientAuth
  case object Optional extends ClientAuth
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdegoes sure. I've to set this config on ServerSslContext not on ClientSSLContext

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'll update my PR shortly

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

Just one minor suggestion, then looks good to merge. Thankk you!

@rajcspsg
Copy link
Contributor Author

@jdegoes @danestig @adamgfraser I updated the PR to add clientAuth config on SSLServerContext.
Please review again and let me know if you have any questions.

@rajcspsg rajcspsg force-pushed the issue-2211 branch 2 times, most recently from 043cd94 to c2fbba7 Compare December 21, 2023 09:17
new SSLConfig(HttpBehaviour.Redirect, data, Provider.JDK, None)

def apply(data: Data, clientAuth: ClientAuth): SSLConfig =
new SSLConfig(HttpBehaviour.Redirect, data, Provider.JDK, Some(clientAuth))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdegoes @adamgfraser I tried to combine both the apply (and other duplicate functions below)
into single function like

def apply(data: Data, clientAuth: Option[ClientAuth] = None): SSLConfig =
    new SSLConfig(HttpBehaviour.Redirect, data, Provider.JDK, clientAuth)

But I'm getting below error -

/home/raj/Coding/scala/zio-http/zio-http/src/main/scala/zio/http/SSLConfig.scala:39:8: in object SSLConfig, multiple overloaded alternatives of method fromFile define default arguments.

I did workaround to make it compile. Not sure why the first option didn't work

@jdegoes jdegoes merged commit a74ffc0 into zio:main Dec 21, 2023
14 checks passed
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.

Client proxy mTLS support
4 participants