Skip to content

Commit a2007b8

Browse files
committed
fix(release): postgres socket options
1 parent e4122c4 commit a2007b8

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

config/releases.exs

+21-10
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,33 @@ end
6969

7070
# ---- [APP CONFIG] :db ----
7171

72+
# Location of root certificates to verify database SSL connection.
73+
# For example: /opt/homebrew/etc/openssl@3/cert.pem
74+
database_ca_cert_filepath =
75+
load_secret.({"DATABASE_CA_CERT_FILEPATH", "/etc/ssl/certs/ca-certificates.crt"})
76+
77+
postgres_enable_ssl? = load_bool.({"db_ssl", "false"})
78+
postgres_socket_options = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []
79+
postgres_ssl_options = []
80+
81+
if postgres_enable_ssl? do
82+
postgres_ssl_options = [
83+
server_name_indication: to_charlist(load_secret.("db_hostname")),
84+
verify: :verify_peer,
85+
cacertfile: database_ca_cert_filepath,
86+
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]
87+
]
88+
end
89+
7290
config :db, DB.Repo,
7391
hostname: load_secret.("db_hostname"),
7492
username: load_secret.("db_username"),
7593
password: load_secret.("db_password"),
7694
database: load_secret.("db_name"),
7795
pool_size: load_int.({"db_pool_size", 10}),
78-
socket_options: if load_bool.({"db_ssl", "false"}), do: [:inet6], else: [],
79-
ssl: load_bool.({"db_ssl", "false"}),
80-
ssl_opts: [
81-
server_name_indication: to_charlist(load_secret.("db_hostname")),
82-
verify: :verify_peer,
83-
customize_hostname_check: [
84-
# Our hosting provider uses a wildcard certificate. By default, Erlang does not support wildcard certificates.
85-
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
86-
]
87-
]
96+
socket_options: postgres_socket_options,
97+
ssl: postgres_enable_ssl?,
98+
ssl_opts: postgres_ssl_options
8899

89100
config :ex_aws,
90101
access_key_id: [load_secret.("s3_access_key_id"), :instance_role],

0 commit comments

Comments
 (0)