Skip to content

Commit fb5585c

Browse files
committed
chore(backend)!: remove authentication bypass configuration
- Remove 'DISABLE_TENANT_AUTHENTICATION' and 'DISABLE_ADMIN_AUTHENTICATION' support - Hardens authentication by removing runtime checks that could bypass auth pipelines - Removes associated configuration definitions in Edgehog.Config Signed-off-by: Davide Briani <davide.briani@secomind.com>
1 parent 0fcbd4b commit fb5585c

5 files changed

Lines changed: 9 additions & 107 deletions

File tree

backend/lib/edgehog/config.ex

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2022-2023 SECO Mind Srl
4+
# Copyright 2022-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -30,14 +30,6 @@ defmodule Edgehog.Config do
3030
alias Edgehog.Geolocation
3131
alias Edgehog.Geolocation.Providers.GoogleGeocoding
3232

33-
@envdoc """
34-
Disables admin authentication. CHANGING IT TO TRUE IS GENERALLY A REALLY BAD IDEA IN A PRODUCTION ENVIRONMENT, IF YOU DON'T KNOW WHAT YOU ARE DOING.
35-
"""
36-
app_env :disable_admin_authentication, :edgehog, :disable_admin_authentication,
37-
os_env: "DISABLE_ADMIN_AUTHENTICATION",
38-
type: :boolean,
39-
default: false
40-
4133
@envdoc "The Admin API JWT public key."
4234
app_env :admin_jwk, :edgehog, :admin_jwk,
4335
os_env: "ADMIN_JWT_PUBLIC_KEY_PATH",
@@ -67,14 +59,6 @@ defmodule Edgehog.Config do
6759
type: :boolean,
6860
default: false
6961

70-
@envdoc """
71-
Disables tenant authentication. CHANGING IT TO TRUE IS GENERALLY A REALLY BAD IDEA IN A PRODUCTION ENVIRONMENT, IF YOU DON'T KNOW WHAT YOU ARE DOING.
72-
"""
73-
app_env :disable_tenant_authentication, :edgehog, :disable_tenant_authentication,
74-
os_env: "DISABLE_TENANT_AUTHENTICATION",
75-
type: :boolean,
76-
default: false
77-
7862
@envdoc "The API key for the ipbase.com geolocation provider."
7963
app_env :ipbase_api_key, :edgehog, :ipbase_api_key,
8064
os_env: "IPBASE_API_KEY",
@@ -112,12 +96,6 @@ defmodule Edgehog.Config do
11296
type: GeocodingProviders,
11397
default: [GoogleGeocoding]
11498

115-
@doc """
116-
Returns true if admin authentication is disabled.
117-
"""
118-
@spec admin_authentication_disabled?() :: boolean()
119-
def admin_authentication_disabled?, do: disable_admin_authentication!()
120-
12199
@doc """
122100
Returns true if edgehog should use an ssl connection with the database.
123101
"""
@@ -179,12 +157,6 @@ defmodule Edgehog.Config do
179157
else: false
180158
end
181159

182-
@doc """
183-
Returns true if tenant authentication is disabled.
184-
"""
185-
@spec tenant_authentication_disabled?() :: boolean()
186-
def tenant_authentication_disabled?, do: disable_tenant_authentication!()
187-
188160
@doc """
189161
Returns the list of geolocation modules to use.
190162
"""
@@ -215,11 +187,7 @@ defmodule Edgehog.Config do
215187
"""
216188
@spec validate_admin_authentication!() :: :ok | no_return()
217189
def validate_admin_authentication! do
218-
if admin_authentication_disabled?() do
219-
:ok
220-
else
221-
admin_jwk!()
222-
:ok
223-
end
190+
admin_jwk!()
191+
:ok
224192
end
225193
end

backend/lib/edgehog_web/admin_api/auth/auth.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2023 SECO Mind Srl
4+
# Copyright 2023-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -20,16 +20,14 @@
2020

2121
defmodule EdgehogWeb.AdminAPI.Auth do
2222
@moduledoc false
23-
alias Edgehog.Config
2423
alias EdgehogWeb.AdminAPI.Auth.Pipeline
2524

2625
def init(opts) do
2726
Pipeline.init(opts)
2827
end
2928

3029
def call(conn, opts) do
31-
if Config.admin_authentication_disabled?() ||
32-
conn.path_info == ["admin-api", "v1", "open_api"] do
30+
if conn.path_info == ["admin-api", "v1", "open_api"] do
3331
conn
3432
else
3533
Pipeline.call(conn, opts)

backend/lib/edgehog_web/auth.ex

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2022-2023 SECO Mind Srl
4+
# Copyright 2022-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -20,20 +20,13 @@
2020

2121
defmodule EdgehogWeb.Auth do
2222
@moduledoc false
23-
alias Edgehog.Config
2423
alias EdgehogWeb.Auth.Pipeline
2524

2625
def init(opts) do
2726
Pipeline.init(opts)
2827
end
2928

3029
def call(conn, opts) do
31-
if Config.tenant_authentication_disabled?() do
32-
# TODO: when we add Authz this path will probably have to
33-
# put some type of all-access Authz in the GraphQL context
34-
conn
35-
else
36-
Pipeline.call(conn, opts)
37-
end
30+
Pipeline.call(conn, opts)
3831
end
3932
end

backend/test/edgehog_web/admin_api/auth_test.exs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2023 SECO Mind Srl
4+
# Copyright 2023-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ defmodule EdgehogWeb.AdminAPI.AuthTest do
2525
import Edgehog.AstarteFixtures
2626
import Edgehog.TenantsFixtures
2727

28-
alias Edgehog.Config
2928
alias Edgehog.Tenants.ReconcilerMock
3029

3130
@valid_pem_public_key :secp256r1
@@ -62,45 +61,6 @@ defmodule EdgehogWeb.AdminAPI.AuthTest do
6261
{:ok, path: ~p"/admin-api/v1/tenants"}
6362
end
6463

65-
describe "disabled Admin authentication" do
66-
@describetag :unconfigured
67-
68-
setup do
69-
stub(ReconcilerMock, :reconcile_tenant, fn _tenant -> :ok end)
70-
Config.put_disable_admin_authentication(true)
71-
72-
on_exit(fn ->
73-
# Cleanup at the end
74-
Config.reload_disable_admin_authentication()
75-
end)
76-
77-
:ok
78-
end
79-
80-
test "returns 201 for request without JWT", %{
81-
conn: conn,
82-
path: path
83-
} do
84-
conn = post(conn, path, @valid_tenant_config)
85-
86-
assert response(conn, :created)
87-
end
88-
89-
test "returns 201 for request with random JWT", %{
90-
conn: conn,
91-
path: path
92-
} do
93-
other_private_key = X509.PrivateKey.new_ec(:secp256r1)
94-
95-
conn =
96-
conn
97-
|> authenticate_connection(other_private_key)
98-
|> post(path, @valid_tenant_config)
99-
100-
assert response(conn, :created)
101-
end
102-
end
103-
10464
describe "unconfigured Admin authentication" do
10565
@describetag :unconfigured
10666

backend/test/edgehog_web/auth_test.exs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2022-2024 SECO Mind Srl
4+
# Copyright 2022-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ defmodule EdgehogWeb.AuthTest do
2222
# This can't be async: true since it modifies the Application env
2323
use EdgehogWeb.ConnCase, async: false
2424

25-
alias Edgehog.Config
2625
alias Edgehog.Containers.ReconcilerMock
2726

2827
@query """
@@ -47,22 +46,6 @@ defmodule EdgehogWeb.AuthTest do
4746
assert %{"errors" => %{"detail" => "Unauthorized"}} = json_response(conn, 401)
4847
end
4948

50-
test "unauthenticated request with disabled authentication returns 200", %{
51-
conn: conn,
52-
api_path: api_path
53-
} do
54-
Config.put_disable_tenant_authentication(true)
55-
56-
on_exit(fn ->
57-
# Cleanup at the end
58-
Config.reload_disable_tenant_authentication()
59-
end)
60-
61-
conn = get(conn, api_path, query: @query)
62-
63-
assert json_response(conn, 200)
64-
end
65-
6649
test "request on unexisting tenant returns 403", %{conn: conn} do
6750
conn = get(conn, "/tenants/notexisting/api", query: @query)
6851

0 commit comments

Comments
 (0)