Skip to content

Commit ae62847

Browse files
committed
chore(secrets): init
move openbao to its own library. needed in preparation of the TO2 rework, where astarte_fdo will need access to openbao's key Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
2 parents 9f82258 + 4c89b99 commit ae62847

File tree

29 files changed

+444
-237
lines changed

29 files changed

+444
-237
lines changed

.github/codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ coverage:
2323
- astarte_rpc
2424
- astarte_fdo
2525
- astarte_fdo_core
26+
- astarte_secrets
2627

2728
ignore:
2829
- "apps/*/test"
@@ -93,3 +94,7 @@ flags:
9394
carryforward: true
9495
paths:
9596
- libs/astarte_fdo_core
97+
astarte_secrets:
98+
carryforward: true
99+
paths:
100+
- libs/astarte_secrets

.github/workflows/astarte-libs-workflow.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ jobs:
5757
with:
5858
lib: "astarte_rpc"
5959
secrets: inherit
60+
astarte_secrets:
61+
uses: ./.github/workflows/astarte-libs-build-workflow.yaml
62+
with:
63+
lib: "astarte_secrets"
64+
secrets: inherit

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ COPY libs/astarte_events/mix.exs libraries/astarte_events/mix.exs
3030
COPY libs/astarte_events/mix.lock libraries/astarte_events/mix.lock
3131
COPY libs/astarte_rpc/mix.exs libraries/astarte_rpc/mix.exs
3232
COPY libs/astarte_rpc/mix.lock libraries/astarte_rpc/mix.lock
33+
COPY libs/astarte_fdo_core/mix.exs libraries/astarte_fdo_core/mix.exs
34+
COPY libs/astarte_fdo_core/mix.lock libraries/astarte_fdo_core/mix.lock
35+
COPY libs/astarte_fdo/mix.exs libraries/astarte_fdo/mix.exs
36+
COPY libs/astarte_fdo/mix.lock libraries/astarte_fdo/mix.lock
37+
COPY libs/astarte_generators/mix.exs libraries/astarte_generators/mix.exs
38+
COPY libs/astarte_generators/mix.lock libraries/astarte_generators/mix.lock
39+
COPY libs/astarte_secrets/mix.exs libraries/astarte_secrets/mix.exs
40+
COPY libs/astarte_secrets/mix.lock libraries/astarte_secrets/mix.lock
3341
RUN mix do deps.get, deps.compile --skip-local-deps
3442

3543
COPY libs ./libraries

apps/astarte_pairing/config/test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ config :astarte_fdo, :base_url_port, 4003
106106
config :astarte_fdo, :base_url_protocol, :http
107107
config :astarte_pairing, :enable_credential_reuse, true
108108

109-
config :astarte_pairing, bao_authentication_mechanism: :token
110-
config :astarte_pairing, bao_token: "astarte_token"
111-
config :astarte_pairing, bao_url: "http://localhost:8200"
109+
config :astarte_secrets, bao_authentication_mechanism: :token
110+
config :astarte_secrets, bao_token: "astarte_token"
111+
config :astarte_secrets, bao_url: "http://localhost:8200"
112112

113113
config :bcrypt_elixir,
114114
log_rounds: 4

apps/astarte_pairing/lib/astarte_pairing/config.ex

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ defmodule Astarte.Pairing.Config do
2424
use Skogsra
2525

2626
alias Astarte.Pairing.CFSSLCredentials
27-
alias Astarte.Pairing.Config
2827
alias Astarte.Pairing.Config.BaseURLProtocol
2928
alias Astarte.Pairing.Config.CQExNodes
30-
alias Astarte.Pairing.Config.OpenBaoAuthenticationMechanism
29+
alias Astarte.Secrets.Config, as: SecretsConfig
3130

3231
@envdoc "The external broker URL which should be used by devices."
3332
app_env :broker_url, :astarte_pairing, :broker_url,
@@ -147,90 +146,6 @@ defmodule Astarte.Pairing.Config do
147146
end
148147
end
149148

150-
@envdoc "The URL to access OpenBao."
151-
app_env :bao_url, :astarte_pairing, :bao_url,
152-
os_env: "ASTARTE_OPENBAO_URL",
153-
type: :binary,
154-
default: "http://localhost:8200"
155-
156-
@envdoc "Internal variable used to store bao authentication"
157-
app_env :bao_authentication, :astarte_pairing, :bao_authentication,
158-
binding_skip: [:system],
159-
type: :any
160-
161-
@envdoc "The mechanism to use for authenticating with OpenBao"
162-
app_env :bao_authentication_mechanism, :astarte_pairing, :bao_authentication_mechanism,
163-
os_env: "ASTARTE_OPENBAO_AUTHENTICATION_MECHANISM",
164-
type: OpenBaoAuthenticationMechanism
165-
166-
@envdoc "Token to authenticate with OpenBao"
167-
app_env :bao_token, :astarte_pairing, :bao_token,
168-
os_env: "ASTARTE_OPENBAO_TOKEN",
169-
type: :binary
170-
171-
@envdoc "Enable SSL for the OpenBao connection. If not specified, SSL is disabled."
172-
app_env :bao_ssl_enabled, :astarte_housekeeping, :bao_ssl_enabled,
173-
os_env: "ASTARTE_OPENBAO_SSL_ENABLED",
174-
type: :boolean,
175-
default: false
176-
177-
@envdoc """
178-
Specifies the certificates of the root Certificate Authorities to be trusted for the OpenBao connection. When not specified, the bundled cURL certificate bundle will be used.
179-
"""
180-
app_env :bao_ssl_ca_file, :astarte_housekeeping, :bao_ssl_ca_file,
181-
os_env: "ASTARTE_OPENBAO_SSL_CA_FILE",
182-
type: :binary,
183-
default: CAStore.file_path()
184-
185-
@envdoc "Disable Server Name Indication. Defaults to false."
186-
app_env :bao_ssl_disable_sni,
187-
:astarte_housekeeping,
188-
:bao_ssl_disable_sni,
189-
os_env: "ASTARTE_OPENBAO_SSL_DISABLE_SNI",
190-
type: :boolean,
191-
default: false
192-
193-
@envdoc "Specify the hostname to be used in TLS Server Name Indication extension. If not specified, the amqp consumer host will be used. This value is used only if Server Name Indication is enabled."
194-
app_env :bao_ssl_custom_sni, :astarte_housekeeping, :bao_ssl_custom_sni,
195-
os_env: "ASTARTE_OPENBAO_SSL_CUSTOM_SNI",
196-
type: :binary
197-
198-
def bao_ssl_options! do
199-
if Config.bao_ssl_enabled!() do
200-
build_bao_ssl_options()
201-
else
202-
[]
203-
end
204-
end
205-
206-
defp build_bao_ssl_options do
207-
[
208-
cacertfile: bao_ssl_ca_file!(),
209-
verify: :verify_peer,
210-
depth: 10
211-
]
212-
|> populate_bao_sni()
213-
end
214-
215-
defp populate_bao_sni(ssl_options) do
216-
if Config.bao_ssl_disable_sni!() do
217-
Keyword.put(ssl_options, :server_name_indication, :disable)
218-
else
219-
server_name =
220-
case Config.bao_ssl_custom_sni!() do
221-
nil ->
222-
Config.bao_url!()
223-
|> URI.parse()
224-
|> Map.fetch!(:host)
225-
226-
custom_sni ->
227-
custom_sni
228-
end
229-
230-
Keyword.put(ssl_options, :server_name_indication, to_charlist(server_name))
231-
end
232-
end
233-
234149
def init! do
235150
if {:ok, nil} == ca_cert() do
236151
case CFSSLCredentials.ca_cert() do
@@ -250,8 +165,7 @@ defmodule Astarte.Pairing.Config do
250165
raise "FDO feature is enabled but not all its parameters are configured"
251166
end
252167

253-
parse_bao_authentication!()
254-
|> put_bao_authentication()
168+
SecretsConfig.init()
255169
end
256170
end
257171

@@ -309,17 +223,4 @@ defmodule Astarte.Pairing.Config do
309223
false
310224
end
311225
end
312-
313-
defp parse_bao_authentication! do
314-
case Config.bao_authentication_mechanism!() do
315-
nil ->
316-
raise "OpenBao authentication method not set"
317-
318-
:token ->
319-
case Config.bao_token!() do
320-
nil -> raise "OpenBao token not set"
321-
token -> {:token, token}
322-
end
323-
end
324-
end
325226
end

apps/astarte_pairing/mix.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ defmodule Astarte.Pairing.Mixfile do
9797
{:cfxxl, github: "ispirata/cfxxl"},
9898
{:astarte_data_access, path: astarte_lib("astarte_data_access")},
9999
{:astarte_generators, path: astarte_lib("astarte_generators"), only: [:dev, :test]},
100+
{:astarte_secrets, path: astarte_lib("astarte_secrets")},
100101
{:bcrypt_elixir, "~> 2.2"},
101102
{:xandra, "~> 0.19"},
102103
{:ecto, "~> 3.12"},
103104
{:exandra, "~> 0.13"},
104-
{:typed_ecto_schema, "~> 0.4"},
105105
{:mimic, "~> 1.11", only: :test},
106106
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
107107
{:con_cache, "~> 1.1"},
@@ -110,8 +110,7 @@ defmodule Astarte.Pairing.Mixfile do
110110
{:astarte_fdo_core, path: astarte_lib("astarte_fdo_core")},
111111
{:astarte_rpc, path: astarte_lib("astarte_rpc")},
112112
# HTTP client needed by some tests, override to avoid conflicts with cfxxl
113-
{:httpoison, "~> 2.2", override: true},
114-
{:x509, "~> 0.8"}
113+
{:httpoison, "~> 2.2", override: true}
115114
]
116115
end
117116

apps/astarte_pairing/test/test_helper.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# limitations under the License.
1717
#
1818

19-
Mimic.copy(:hackney)
2019
Mimic.copy(Astarte.DataAccess.Config)
2120
Mimic.copy(Astarte.DataAccess.Health.Health)
2221
Mimic.copy(Astarte.Events.TriggersHandler)
@@ -31,9 +30,6 @@ Mimic.copy(Astarte.FDO.Rendezvous)
3130
Mimic.copy(Astarte.FDO.Rendezvous.Client)
3231
Mimic.copy(Astarte.FDO.ServiceInfo)
3332
Mimic.copy(Astarte.Pairing.Config)
34-
Mimic.copy(Astarte.Pairing.FDO.OpenBao)
35-
Mimic.copy(Astarte.Pairing.FDO.OpenBao.Client)
36-
Mimic.copy(Astarte.Pairing.FDO.OpenBao.Core)
3733
Mimic.copy(Astarte.Pairing.Queries)
3834
Mimic.copy(DateTime)
3935
Mimic.copy(HTTPoison)

committed.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ allowed_scopes = [
3535
"fdo",
3636
"fdo_core",
3737
"generators",
38+
"secrets",
3839
# tools
3940
"e2e",
4041
"import",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
3+
import_deps: [:ecto, :skogsra]
4+
]

libs/astarte_secrets/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Astarte Secrets
2+
3+
Secret management for Astarte Services using OpenBao

0 commit comments

Comments
 (0)