1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.ReleaseRuntimeProvider do
7 Imports runtime config and `{env}.exported_from_db.secret.exs` for releases.
9 @behaviour Config.Provider
12 def init(opts), do: opts
15 def load(config, opts) do
16 with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
19 opts[:config_path] || System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
22 if File.exists?(config_path) do
23 # <https://git.pleroma.social/pleroma/pleroma/-/issues/3135>
24 %File.Stat{mode: mode} = File.lstat!(config_path)
26 if Bitwise.band(mode, 0o007) > 0 do
27 raise "Configuration at #{config_path} has world-permissions, execute the following: chmod o= #{config_path}"
30 if Bitwise.band(mode, 0o020) > 0 do
31 raise "Configuration at #{config_path} has group-wise write permissions, execute the following: chmod g-w #{config_path}"
34 # Note: Elixir doesn't provides a getuid(2)
35 # so cannot forbid group-read only when config is owned by us
37 runtime_config = Config.Reader.read!(config_path)
40 |> Config.Reader.merge(pleroma: [config_path: config_path])
41 |> Config.Reader.merge(runtime_config)
46 "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
54 exported_config_path =
55 opts[:exported_config_path] ||
58 |> Path.join("#{Pleroma.Config.get(:env)}.exported_from_db.secret.exs")
61 if File.exists?(exported_config_path) do
62 exported_config = Config.Reader.read!(exported_config_path)
63 Config.Reader.merge(with_runtime_config, exported_config)