Skip to content

Commit 3adf2a1

Browse files
committed
fix(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 075a357 commit 3adf2a1

3 files changed

Lines changed: 9 additions & 46 deletions

File tree

backend/lib/edgehog/config.ex

Lines changed: 5 additions & 33 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,11 +96,7 @@ 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!()
99+
120100

121101
@doc """
122102
Returns true if edgehog should use an ssl connection with the database.
@@ -179,11 +159,7 @@ defmodule Edgehog.Config do
179159
else: false
180160
end
181161

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!()
162+
187163

188164
@doc """
189165
Returns the list of geolocation modules to use.
@@ -215,11 +191,7 @@ defmodule Edgehog.Config do
215191
"""
216192
@spec validate_admin_authentication!() :: :ok | no_return()
217193
def validate_admin_authentication! do
218-
if admin_authentication_disabled?() do
219-
:ok
220-
else
221-
admin_jwk!()
222-
:ok
223-
end
194+
admin_jwk!()
195+
:ok
224196
end
225197
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

0 commit comments

Comments
 (0)