Skip to content

Commit 2f073c7

Browse files
committed
Use explicit ssl peer verification when connecting to LDAP
1 parent 282024e commit 2f073c7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

app/lib/meadow/accounts/ldap.ex

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@ defmodule Meadow.Accounts.Ldap do
1111
@connect_timeout 1500
1212
@retries 3
1313
@ldap_matching_rule_in_chain "1.2.840.113556.1.4.1941"
14+
@sslopts [cacertfile: :certifi.cacertfile(), verify: :verify_peer]
1415

1516
def connection(force_new \\ false) do
1617
if force_new, do: Meadow.Cache |> Cachex.del(:ldap_address)
1718

18-
settings =
19-
with config <- Application.get_env(:exldap, :settings) do
20-
Keyword.put(config, :server, connection_address(config))
21-
end
22-
23-
case {Exldap.connect(settings, @connect_timeout), force_new} do
19+
case {connection_settings() |> Exldap.connect(@connect_timeout), force_new} do
2420
{{:ok, result}, _} -> result
2521
{_, false} -> connection(true)
2622
{other, true} -> other
2723
end
2824
end
2925

26+
def connection_settings do
27+
with config <- Application.get_env(:exldap, :settings) |> address_to_ip() do
28+
if Keyword.get(config, :ssl, false),
29+
do: Keyword.put(config, :sslopts, @sslopts),
30+
else: config
31+
end
32+
end
33+
3034
@doc "Find a user entry by its common name (NetID)"
3135
def find_user(cn) do
3236
find_user_func = fn ->
@@ -172,7 +176,7 @@ defmodule Meadow.Accounts.Ldap do
172176

173177
@doc "Add a member to a group"
174178
def add_member(group_dn, member_dn) do
175-
with operation <- :eldap.mod_add('member', [to_charlist(member_dn)]) do
179+
with operation <- :eldap.mod_add(~c"member", [to_charlist(member_dn)]) do
176180
case modify_entry(group_dn, operation) do
177181
{:ok, _} -> :ok
178182
{:exists, _} -> :exists
@@ -183,7 +187,7 @@ defmodule Meadow.Accounts.Ldap do
183187

184188
@doc "Remove a member from a group"
185189
def remove_member(group_dn, member_dn) do
186-
with operation <- :eldap.mod_delete('member', [to_charlist(member_dn)]) do
190+
with operation <- :eldap.mod_delete(~c"member", [to_charlist(member_dn)]) do
187191
case modify_entry(group_dn, operation) do
188192
{:ok, _} -> :ok
189193
other -> other
@@ -207,6 +211,8 @@ defmodule Meadow.Accounts.Ldap do
207211
end
208212
end
209213

214+
defp address_to_ip(config), do: Keyword.put(config, :server, connection_address(config))
215+
210216
defp connection_address(config) do
211217
find_connection = fn tuple ->
212218
case tuple |> :gen_tcp.connect(config[:port], [:inet]) do

app/lib/mix/tasks/pipeline.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Mix.Tasks.Meadow.Pipeline.Setup do
99
@shortdoc @moduledoc
1010
def run(_) do
1111
if Meadow.Config.environment?(:prod) or System.get_env("AWS_DEV_ENVIRONMENT") do
12-
Logger.warn("Not in localstack environment – queue creation skipped")
12+
Logger.warning("Not in localstack environment – queue creation skipped")
1313
else
1414
[:ex_aws, :hackney] |> Enum.each(&Application.ensure_all_started/1)
1515

0 commit comments

Comments
 (0)