|
69 | 69 |
|
70 | 70 | # ---- [APP CONFIG] :db ----
|
71 | 71 |
|
| 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 | + |
72 | 90 | config :db, DB.Repo,
|
73 | 91 | hostname: load_secret.("db_hostname"),
|
74 | 92 | username: load_secret.("db_username"),
|
75 | 93 | password: load_secret.("db_password"),
|
76 | 94 | database: load_secret.("db_name"),
|
77 | 95 | 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 |
88 | 99 |
|
89 | 100 | config :ex_aws,
|
90 | 101 | access_key_id: [load_secret.("s3_access_key_id"), :instance_role],
|
|
0 commit comments