@@ -704,10 +704,45 @@ You need roughly three additional configuration steps:
704
704
* Add x.509 Certificate subject as a User
705
705
* Authenticate with an x.509 Certificate
706
706
707
+ To get the x.509 authentication working you need to prepare the ssl configuration accordingly:
708
+ * you need set the ssl option: ` verify_peer `
709
+ * you need to specify the ` cacertfile ` because Erlang BEAM don't provide any CA certificate store by default
710
+ * you maybe need to customize the hostname check to allow wildcard certificates
711
+ * you need to specify the ` username ` from the subject entry of the user certificate
712
+
713
+ If you use a user certificate from Atlas a working configuration looks like this. First we
714
+ use the [ castore] ( https://hex.pm/packages/castore ) package as the CA certificate store. After downloading
715
+ the user certificate we extract the username subject entry from the PEM file:
716
+
717
+ ``` shell
718
+ openssl x509 -in < pathToClientPEM> -inform PEM -subject -nameopt RFC2253
719
+
720
+ > CN=cert-user
721
+ ```
722
+
723
+ The configuration looks now:
707
724
``` elixir
708
- {:ok , pid} = Mongo .start_link (database: " test" , auth_mechanism: :x509 )
725
+ opts = [
726
+ url: " mongodb+srv://cluster0.xxx.mongodb.net/myFirstDatabase?authSource=%24external&retryWrites=true&w=majority" ,
727
+ ssl: true ,
728
+ username: " CN=cert-user" ,
729
+ password: " " ,
730
+ auth_mechanism: :x509 ,
731
+ ssl_opts: [
732
+ verify: :verify_peer ,
733
+ cacertfile: to_charlist (CAStore .file_path ()),
734
+ certfile: ' /path-to-cert/X509-cert-2227052404946303101.pem' ,
735
+ customize_hostname_check: [
736
+ match_fun:
737
+ :public_key .pkix_verify_hostname_match_fun (:https )
738
+ ]
739
+ ]]
740
+
741
+ Mongo .start_link (opts)
709
742
```
710
743
744
+ Currently, we need to specify * an empty password* to get the x.509 auth module working. This will be changed soon.
745
+
711
746
## AWS, TLS and Erlang SSL Ciphers
712
747
713
748
Some MongoDB cloud providers (notably AWS) require a particular TLS cipher that isn't enabled
0 commit comments