forked from AkkomaGang/akkoma
Merge remote-tracking branch 'norm/config-permissions' into develop
This commit is contained in:
commit
b4399574ca
4 changed files with 29 additions and 2 deletions
|
@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- Add `no_new_privs` hardening to OpenRC and systemd service files
|
- Add `no_new_privs` hardening to OpenRC and systemd service files
|
||||||
- Ensured that XML parsers cannot load external entities (thanks @Mae@is.badat.dev!)
|
- Ensured that XML parsers cannot load external entities (thanks @Mae@is.badat.dev!)
|
||||||
|
- Reduced permissions of config files and directories, distros requiring greater permissions like group-read need to pre-create the directories
|
||||||
|
|
||||||
## Removed
|
## Removed
|
||||||
|
|
||||||
|
|
|
@ -247,16 +247,22 @@ def run(["gen" | rest]) do
|
||||||
config_dir = Path.dirname(config_path)
|
config_dir = Path.dirname(config_path)
|
||||||
psql_dir = Path.dirname(psql_path)
|
psql_dir = Path.dirname(psql_path)
|
||||||
|
|
||||||
|
# Note: Distros requiring group read (0o750) on those directories should
|
||||||
|
# pre-create the directories.
|
||||||
to_create =
|
to_create =
|
||||||
[config_dir, psql_dir, static_dir, uploads_dir]
|
[config_dir, psql_dir, static_dir, uploads_dir]
|
||||||
|> Enum.reject(&File.exists?/1)
|
|> Enum.reject(&File.exists?/1)
|
||||||
|
|
||||||
for dir <- to_create do
|
for dir <- to_create do
|
||||||
File.mkdir_p!(dir)
|
File.mkdir_p!(dir)
|
||||||
|
File.chmod!(dir, 0o700)
|
||||||
end
|
end
|
||||||
|
|
||||||
shell_info("Writing config to #{config_path}.")
|
shell_info("Writing config to #{config_path}.")
|
||||||
|
|
||||||
|
# Sadly no fchmod(2) equivalent in Elixir…
|
||||||
|
File.touch!(config_path)
|
||||||
|
File.chmod!(config_path, 0o640)
|
||||||
File.write(config_path, result_config)
|
File.write(config_path, result_config)
|
||||||
shell_info("Writing the postgres script to #{psql_path}.")
|
shell_info("Writing the postgres script to #{psql_path}.")
|
||||||
File.write(psql_path, result_psql)
|
File.write(psql_path, result_psql)
|
||||||
|
@ -275,8 +281,7 @@ def run(["gen" | rest]) do
|
||||||
else
|
else
|
||||||
shell_error(
|
shell_error(
|
||||||
"The task would have overwritten the following files:\n" <>
|
"The task would have overwritten the following files:\n" <>
|
||||||
(Enum.map(will_overwrite, &"- #{&1}\n") |> Enum.join("")) <>
|
Enum.map_join(will_overwrite, &"- #{&1}\n") <> "Rerun with `--force` to overwrite them."
|
||||||
"Rerun with `--force` to overwrite them."
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,20 @@ def load(config, opts) do
|
||||||
|
|
||||||
with_runtime_config =
|
with_runtime_config =
|
||||||
if File.exists?(config_path) do
|
if File.exists?(config_path) do
|
||||||
|
# <https://git.pleroma.social/pleroma/pleroma/-/issues/3135>
|
||||||
|
%File.Stat{mode: mode} = File.lstat!(config_path)
|
||||||
|
|
||||||
|
if Bitwise.band(mode, 0o007) > 0 do
|
||||||
|
raise "Configuration at #{config_path} has world-permissions, execute the following: chmod o= #{config_path}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if Bitwise.band(mode, 0o020) > 0 do
|
||||||
|
raise "Configuration at #{config_path} has group-wise write permissions, execute the following: chmod g-w #{config_path}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Note: Elixir doesn't provides a getuid(2)
|
||||||
|
# so cannot forbid group-read only when config is owned by us
|
||||||
|
|
||||||
runtime_config = Config.Reader.read!(config_path)
|
runtime_config = Config.Reader.read!(config_path)
|
||||||
|
|
||||||
with_defaults
|
with_defaults
|
||||||
|
|
|
@ -13,6 +13,8 @@ test "loads release defaults config and warns about non-existent runtime config"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "merged runtime config" do
|
test "merged runtime config" do
|
||||||
|
assert :ok == File.chmod!("test/fixtures/config/temp.secret.exs", 0o640)
|
||||||
|
|
||||||
merged =
|
merged =
|
||||||
ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")
|
ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")
|
||||||
|
|
||||||
|
@ -21,6 +23,8 @@ test "merged runtime config" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "merged exported config" do
|
test "merged exported config" do
|
||||||
|
assert :ok == File.chmod!("test/fixtures/config/temp.exported_from_db.secret.exs", 0o640)
|
||||||
|
|
||||||
ExUnit.CaptureIO.capture_io(fn ->
|
ExUnit.CaptureIO.capture_io(fn ->
|
||||||
merged =
|
merged =
|
||||||
ReleaseRuntimeProvider.load([],
|
ReleaseRuntimeProvider.load([],
|
||||||
|
@ -33,6 +37,9 @@ test "merged exported config" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "runtime config is merged with exported config" do
|
test "runtime config is merged with exported config" do
|
||||||
|
assert :ok == File.chmod!("test/fixtures/config/temp.secret.exs", 0o640)
|
||||||
|
assert :ok == File.chmod!("test/fixtures/config/temp.exported_from_db.secret.exs", 0o640)
|
||||||
|
|
||||||
merged =
|
merged =
|
||||||
ReleaseRuntimeProvider.load([],
|
ReleaseRuntimeProvider.load([],
|
||||||
config_path: "test/fixtures/config/temp.secret.exs",
|
config_path: "test/fixtures/config/temp.secret.exs",
|
||||||
|
|
Loading…
Reference in a new issue