-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add ability to obtain client certificate in Request to support implementation of Authorisation Filters via certificate principals #632
Comments
Thanks for the request. FYI, we have implemented MTLS on a couple of http4k projects in the past - so you do already can do it at a push. Both involve implementing custom
|
Thanks for the suggestions! Currently we are trying to do it by implementing our own We also tried a less invasive way where we add a It seems that combining this Just wondering whats the best way/ workaround at the moment? |
For 1 (and using SunHttp as an example) something like this works. It's not particularly pretty as it introduces some dependencies between construction of the server and the app, but it will get you there. https://gist.github.com/daviddenton/fdc203254813f679b17dadbb5c196f1e The key here is that you don't need to rewrite the Jetty headers - just the Http4k headers - which will be done automatically in the case above - so you just need to "import" the RequestContextKey. There is also a way to reduce the key being passed at the expense of randomness by hardcoding the identifier instead (but the store will still need to be passed): For 2 - a similar thing - just compute the certificate fingerprint inside your custom jetty and then add an http4k header which is passed downstream to the filters. HTH |
Background
Currently, we are able to implement Mutual TLS Authentication (mTLS) via configuring the various backends (e.g. Jetty). However, once authenticated, we are not able to utilise http4k (E.g. implement our own custom Filters) to perform authorisation as the certificate (or its principal/ subject) is not passed to the Request object.
Feature Request
Add support to allow Filters to retrieve the certificate used for authentication (e.g. via the Request object, or other possible means). The certificate is available from the underlying web server abstraction, for example in Jetty, it is available via a call to the
HttpServletRequest#getAttribute
method, usingjavax.servlet.request.X509Certificate
as the key.Prior Art
Micronaut's
HttpRequest
has a method to retrieve the client certificate: HttpRequest#getCertificateFuture Work
With this enhancement, it will allow us to write more default Authentication Filters like CertificateAuthenticationFilter, that will allow users to configure authentication via X509Certificate principal.
The text was updated successfully, but these errors were encountered: