<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="259671" data-post-id="259671">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="nhpip" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nhpip/120/23811_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  nhpip
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>So I managed to get it working. First off, looking at the Erlang (R25) code this is wrong:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">verify_fun: &amp;:ssl_verify_hostname.verify_fun/3,
</code></pre>
<p>This works:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">verify_fun: {&amp;:ssl_verify_hostname.verify_fun/3, []},
</code></pre>
<p>I still have hostname validation errors, but in my case i don’t really care about that. So I added <code>customize_hostname_check</code> to make the (working) configuration look like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">[
    verify: :verify_peer,
    cacertfile: System.get_env("DB_SSL_CACERTFILE"),
    customize_hostname_check: [match_fun: fn(_, _) -&gt; true end],
    verify_fun: {&amp;:ssl_verify_hostname.verify_fun/3, []}
]
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259671" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-259671" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259671"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="259733" data-post-id="259733">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="voltone" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/voltone/120/24672_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  voltone
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="nhpip" data-post="12" data-topic="49312">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nhpip/48/23811_2.png" class="avatar"> nhpip:</div>
<blockquote>
<p>I still have hostname validation errors, but in my case i don’t really care about that.</p>
</blockquote>
</aside>
<p>Without hostname verification, the only requirement for certificate verification to succeed is that the server presents a certificate that was issued by a trusted CA. Any certificate will do. So if your CA trust store is a common list of public CAs, any certificate issued by e.g. Let’s Encrypt for a random hostname will do. So in terms of stopping an active attacker from impersonating your DB or performing a MitM attack, this is not really any better than <code>verify: :verify_none</code>.</p>
<p>You may have to explicitly set the hostname that <code>:ssl_verify_hostname</code> should expect to find in the certificate: depending on the DB driver and wire protocol, the TLS handshake may be started on an already established TCP socket, in which case the <code>:ssl</code> module doesn’t know the hostname that was used to establish that connection. Try setting <code>verify_fun: {&amp;:ssl_verify_hostname.verify_fun/3, [check_hostname: 'db.host.name']}</code>…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259733" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-259733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259733"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="259736" data-post-id="259736">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gesta" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gesta/120/27490_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gesta
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Using Elixir 1.13.4 (<a href="https://github.com/erlef/docker-elixir/blob/253f56764ed34d41e4279cb741d84dcb4b284a55/1.13/otp-25-alpine/Dockerfile#L4" rel="noopener nofollow ugc">image</a>) which in turn relies on Erlang 25.0.4 (<a href="https://github.com/erlang/docker-erlang-otp/blob/d392a298bf87cec97b713d51f55e1b23faa6224d/25/alpine/Dockerfile" rel="noopener nofollow ugc">image</a>).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259736" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-259736" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259736"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="259930" data-post-id="259930">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="nhpip" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nhpip/120/23811_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  nhpip
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ended up with:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    customize_hostname_check: [match_fun:  fn(_ip, {_, dns_name}) -&gt; dns_name == to_charlist(db_hostname) end],
    verify_fun: {&amp;:ssl_verify_hostname.verify_fun/3, [check_hostname: to_charlist(db_hostname)]}
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259930" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-259930" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259930"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="284324" data-post-id="284324">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="voltone" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/voltone/120/24672_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  voltone
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Perhaps relevant for future readers of this thread, I have released a package to help enable TLS and server certificate verification with AWS RDS: <a href="https://forum.elixirforum.com/t/aws-rds-castore-certificate-validation-for-aws-rds-dbs/55111/1" class="inline-onebox" rel="nofollow">Aws_rds_castore - Certificate validation for AWS RDS DBs</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="284324" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-284324" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="284324"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="369308" data-post-id="369308">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gmile" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gmile/120/33982_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gmile
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Does anyone have a complete example for connecting to a PostgreSQL database inside GCP, and using a more recent Erlang version (27+)? I’m trying to connect to the DB using a certificate, no luck.</p>
<p>For context, the DB and my app are inside a VPC, the DB only has an IP address and no internal DNS record.</p>
<p>The way I am making attempts to connect look like this:</p>
<pre data-code-wrap="sh"><code class="lang-sh">iex --eval 'Mix.install([:postgrex])'
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">{:ok, pid} =
  Postgrex.start_link(
    hostname: "1.2.3.4",
    port: 5432,
    username: "my-user",
    password: "my-password",
    database: "my-db",
    ssl: [cacertfile: "/tmp/my-server-ca.pem"
  )
</code></pre>
<p>The server CA was obtained like this:</p>
<pre data-code-wrap="sh"><code class="lang-sh">gcloud sql instances describe my-db-instance --project=my-project --format='value(serverCaCert.cert)' &gt; my-server-ca.pem
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="369308" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/ecto-ssl-verification-with-google-sql-connection-requires-a-valid-client-certificate/49312/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-369308" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="369308"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>