mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Merge remote-tracking branch 'origin/develop' into finch
This commit is contained in:
commit
326575d5b7
10 changed files with 225 additions and 16 deletions
|
@ -93,6 +93,27 @@ unit-testing:
|
||||||
- mix ecto.migrate
|
- mix ecto.migrate
|
||||||
- mix coveralls --preload-modules
|
- mix coveralls --preload-modules
|
||||||
|
|
||||||
|
unit-testing-erratic:
|
||||||
|
stage: test
|
||||||
|
retry: 2
|
||||||
|
only:
|
||||||
|
changes:
|
||||||
|
- "**/*.ex"
|
||||||
|
- "**/*.exs"
|
||||||
|
- "mix.lock"
|
||||||
|
cache: &testing_cache_policy
|
||||||
|
<<: *global_cache_policy
|
||||||
|
policy: pull
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: postgres:13
|
||||||
|
alias: postgres
|
||||||
|
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
||||||
|
script:
|
||||||
|
- mix ecto.create
|
||||||
|
- mix ecto.migrate
|
||||||
|
- mix test --only=erratic
|
||||||
|
|
||||||
# Removed to fix CI issue. In this early state it wasn't adding much value anyway.
|
# Removed to fix CI issue. In this early state it wasn't adding much value anyway.
|
||||||
# TODO Fix and reinstate federated testing
|
# TODO Fix and reinstate federated testing
|
||||||
# federated-testing:
|
# federated-testing:
|
||||||
|
|
|
@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Added
|
### Added
|
||||||
- `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object
|
- `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object
|
||||||
- Experimental support for Finch. Put `config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}` in your secrets file to use it. Reverse Proxy will still use Hackney.
|
- Experimental support for Finch. Put `config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}` in your secrets file to use it. Reverse Proxy will still use Hackney.
|
||||||
|
- AdminAPI: allow moderators to manage reports, users, invites, and custom emojis
|
||||||
|
- AdminAPI: restrict moderators to access sensitive data: change user credentials, get password reset token, read private statuses and chats, etc
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
||||||
|
@ -68,7 +70,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Attachment dimensions and blurhashes are federated when available.
|
- Attachment dimensions and blurhashes are federated when available.
|
||||||
- Mastodon API: support `poll` notification.
|
- Mastodon API: support `poll` notification.
|
||||||
- Pinned posts federation
|
- Pinned posts federation
|
||||||
- AdminAPI: allow moderators to manage reports, users, invites, and custom emojis
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Don't crash so hard when email settings are invalid.
|
- Don't crash so hard when email settings are invalid.
|
||||||
|
|
|
@ -149,6 +149,8 @@ config :pleroma, Pleroma.Web.Endpoint,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Configures Elixir's Logger
|
# Configures Elixir's Logger
|
||||||
|
config :logger, truncate: 65536
|
||||||
|
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
level: :debug,
|
level: :debug,
|
||||||
format: "\n$time $metadata[$level] $message\n",
|
format: "\n$time $metadata[$level] $message\n",
|
||||||
|
@ -255,7 +257,8 @@ config :pleroma, :instance,
|
||||||
],
|
],
|
||||||
show_reactions: true,
|
show_reactions: true,
|
||||||
password_reset_token_validity: 60 * 60 * 24,
|
password_reset_token_validity: 60 * 60 * 24,
|
||||||
profile_directory: true
|
profile_directory: true,
|
||||||
|
privileged_staff: false
|
||||||
|
|
||||||
config :pleroma, :welcome,
|
config :pleroma, :welcome,
|
||||||
direct_message: [
|
direct_message: [
|
||||||
|
@ -853,6 +856,13 @@ config :pleroma, ConcurrentLimiter, [
|
||||||
{Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy, [max_running: 5, max_waiting: 5]}
|
{Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy, [max_running: 5, max_waiting: 5]}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
config :pleroma, :telemetry,
|
||||||
|
slow_queries_logging: [
|
||||||
|
enabled: false,
|
||||||
|
min_duration: 500_000,
|
||||||
|
exclude_sources: [nil, "oban_jobs"]
|
||||||
|
]
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
|
@ -941,6 +941,12 @@ config :pleroma, :config_description, [
|
||||||
key: :profile_directory,
|
key: :profile_directory,
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description: "Enable profile directory."
|
description: "Enable profile directory."
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :privileged_staff,
|
||||||
|
type: :boolean,
|
||||||
|
description:
|
||||||
|
"Let moderators access sensitive data (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,10 +12,16 @@ defmodule Pleroma.Telemetry.Logger do
|
||||||
[:pleroma, :connection_pool, :reclaim, :stop],
|
[:pleroma, :connection_pool, :reclaim, :stop],
|
||||||
[:pleroma, :connection_pool, :provision_failure],
|
[:pleroma, :connection_pool, :provision_failure],
|
||||||
[:pleroma, :connection_pool, :client, :dead],
|
[:pleroma, :connection_pool, :client, :dead],
|
||||||
[:pleroma, :connection_pool, :client, :add]
|
[:pleroma, :connection_pool, :client, :add],
|
||||||
|
[:pleroma, :repo, :query]
|
||||||
]
|
]
|
||||||
def attach do
|
def attach do
|
||||||
:telemetry.attach_many("pleroma-logger", @events, &handle_event/4, [])
|
:telemetry.attach_many(
|
||||||
|
"pleroma-logger",
|
||||||
|
@events,
|
||||||
|
&Pleroma.Telemetry.Logger.handle_event/4,
|
||||||
|
[]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Passing anonymous functions instead of strings to logger is intentional,
|
# Passing anonymous functions instead of strings to logger is intentional,
|
||||||
|
@ -87,4 +93,64 @@ defmodule Pleroma.Telemetry.Logger do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok
|
def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok
|
||||||
|
|
||||||
|
def handle_event(
|
||||||
|
[:pleroma, :repo, :query] = _name,
|
||||||
|
%{query_time: query_time} = measurements,
|
||||||
|
%{source: source} = metadata,
|
||||||
|
config
|
||||||
|
) do
|
||||||
|
logging_config = Pleroma.Config.get([:telemetry, :slow_queries_logging], [])
|
||||||
|
|
||||||
|
if logging_config[:enabled] &&
|
||||||
|
logging_config[:min_duration] &&
|
||||||
|
query_time > logging_config[:min_duration] and
|
||||||
|
(is_nil(logging_config[:exclude_sources]) or
|
||||||
|
source not in logging_config[:exclude_sources]) do
|
||||||
|
log_slow_query(measurements, metadata, config)
|
||||||
|
else
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp log_slow_query(
|
||||||
|
%{query_time: query_time} = _measurements,
|
||||||
|
%{source: _source, query: query, params: query_params, repo: repo} = _metadata,
|
||||||
|
_config
|
||||||
|
) do
|
||||||
|
sql_explain =
|
||||||
|
with {:ok, %{rows: explain_result_rows}} <-
|
||||||
|
repo.query("EXPLAIN " <> query, query_params, log: false) do
|
||||||
|
Enum.map_join(explain_result_rows, "\n", & &1)
|
||||||
|
end
|
||||||
|
|
||||||
|
{:current_stacktrace, stacktrace} = Process.info(self(), :current_stacktrace)
|
||||||
|
|
||||||
|
pleroma_stacktrace =
|
||||||
|
Enum.filter(stacktrace, fn
|
||||||
|
{__MODULE__, _, _, _} ->
|
||||||
|
false
|
||||||
|
|
||||||
|
{mod, _, _, _} ->
|
||||||
|
mod
|
||||||
|
|> to_string()
|
||||||
|
|> String.starts_with?("Elixir.Pleroma.")
|
||||||
|
end)
|
||||||
|
|
||||||
|
Logger.warn(fn ->
|
||||||
|
"""
|
||||||
|
Slow query!
|
||||||
|
|
||||||
|
Total time: #{round(query_time / 1_000)} ms
|
||||||
|
|
||||||
|
#{query}
|
||||||
|
|
||||||
|
#{inspect(query_params, limit: :infinity)}
|
||||||
|
|
||||||
|
#{sql_explain}
|
||||||
|
|
||||||
|
#{Exception.format_stacktrace(pleroma_stacktrace)}
|
||||||
|
"""
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
features: features(),
|
features: features(),
|
||||||
federation: federation(),
|
federation: federation(),
|
||||||
fields_limits: fields_limits(),
|
fields_limits: fields_limits(),
|
||||||
post_formats: Config.get([:instance, :allowed_post_formats])
|
post_formats: Config.get([:instance, :allowed_post_formats]),
|
||||||
|
privileged_staff: Config.get([:instance, :privileged_staff])
|
||||||
},
|
},
|
||||||
stats: %{mau: Pleroma.User.active_user_count()},
|
stats: %{mau: Pleroma.User.active_user_count()},
|
||||||
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||||
|
|
|
@ -69,7 +69,8 @@ defmodule Pleroma.Web.Nodeinfo.Nodeinfo do
|
||||||
mailerEnabled: Config.get([Pleroma.Emails.Mailer, :enabled], false),
|
mailerEnabled: Config.get([Pleroma.Emails.Mailer, :enabled], false),
|
||||||
features: features,
|
features: features,
|
||||||
restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
|
restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
|
||||||
skipThreadContainment: Config.get([:instance, :skip_thread_containment], false)
|
skipThreadContainment: Config.get([:instance, :skip_thread_containment], false),
|
||||||
|
privilegedStaff: Config.get([:instance, :privileged_staff])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
31
lib/pleroma/web/plugs/ensure_staff_privileged_plug.ex
Normal file
31
lib/pleroma/web/plugs/ensure_staff_privileged_plug.ex
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug do
|
||||||
|
@moduledoc """
|
||||||
|
Ensures if staff are privileged enough to do certain tasks
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Pleroma.Web.TranslationHelpers
|
||||||
|
import Plug.Conn
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
def init(options) do
|
||||||
|
options
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(%{assigns: %{user: %User{is_admin: true}}} = conn, _), do: conn
|
||||||
|
|
||||||
|
def call(conn, _) do
|
||||||
|
if Config.get!([:instance, :privileged_staff]) do
|
||||||
|
conn
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> render_error(:forbidden, "User is not an admin.")
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -101,6 +101,10 @@ defmodule Pleroma.Web.Router do
|
||||||
plug(Pleroma.Web.Plugs.IdempotencyPlug)
|
plug(Pleroma.Web.Plugs.IdempotencyPlug)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipeline :require_privileged_staff do
|
||||||
|
plug(Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug)
|
||||||
|
end
|
||||||
|
|
||||||
pipeline :require_admin do
|
pipeline :require_admin do
|
||||||
plug(Pleroma.Web.Plugs.UserIsAdminPlug)
|
plug(Pleroma.Web.Plugs.UserIsAdminPlug)
|
||||||
end
|
end
|
||||||
|
@ -195,7 +199,6 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/relay", RelayController, :follow)
|
post("/relay", RelayController, :follow)
|
||||||
delete("/relay", RelayController, :unfollow)
|
delete("/relay", RelayController, :unfollow)
|
||||||
|
|
||||||
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
|
|
||||||
patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
|
patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
|
||||||
get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
|
get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
|
||||||
patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
|
patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
|
||||||
|
@ -228,6 +231,24 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/backups", AdminAPIController, :create_backup)
|
post("/backups", AdminAPIController, :create_backup)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# AdminAPI: admins and mods (staff) can perform these actions (if enabled by config)
|
||||||
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
|
pipe_through([:admin_api, :require_privileged_staff])
|
||||||
|
|
||||||
|
delete("/users", UserController, :delete)
|
||||||
|
|
||||||
|
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
|
||||||
|
patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
|
||||||
|
|
||||||
|
get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
|
||||||
|
get("/users/:nickname/chats", AdminAPIController, :list_user_chats)
|
||||||
|
|
||||||
|
get("/statuses", StatusController, :index)
|
||||||
|
|
||||||
|
get("/chats/:id", ChatController, :show)
|
||||||
|
get("/chats/:id/messages", ChatController, :messages)
|
||||||
|
end
|
||||||
|
|
||||||
# AdminAPI: admins and mods (staff) can perform these actions
|
# AdminAPI: admins and mods (staff) can perform these actions
|
||||||
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
pipe_through(:admin_api)
|
pipe_through(:admin_api)
|
||||||
|
@ -240,22 +261,16 @@ defmodule Pleroma.Web.Router do
|
||||||
patch("/users/deactivate", UserController, :deactivate)
|
patch("/users/deactivate", UserController, :deactivate)
|
||||||
patch("/users/approve", UserController, :approve)
|
patch("/users/approve", UserController, :approve)
|
||||||
|
|
||||||
delete("/users", UserController, :delete)
|
|
||||||
|
|
||||||
post("/users/invite_token", InviteController, :create)
|
post("/users/invite_token", InviteController, :create)
|
||||||
get("/users/invites", InviteController, :index)
|
get("/users/invites", InviteController, :index)
|
||||||
post("/users/revoke_invite", InviteController, :revoke)
|
post("/users/revoke_invite", InviteController, :revoke)
|
||||||
post("/users/email_invite", InviteController, :email)
|
post("/users/email_invite", InviteController, :email)
|
||||||
|
|
||||||
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
|
|
||||||
patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
|
patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
|
||||||
get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
|
get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
|
||||||
patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
|
|
||||||
|
|
||||||
get("/users", UserController, :index)
|
get("/users", UserController, :index)
|
||||||
get("/users/:nickname", UserController, :show)
|
get("/users/:nickname", UserController, :show)
|
||||||
get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
|
|
||||||
get("/users/:nickname/chats", AdminAPIController, :list_user_chats)
|
|
||||||
|
|
||||||
get("/instances/:instance/statuses", InstanceController, :list_statuses)
|
get("/instances/:instance/statuses", InstanceController, :list_statuses)
|
||||||
delete("/instances/:instance", InstanceController, :delete)
|
delete("/instances/:instance", InstanceController, :delete)
|
||||||
|
@ -269,15 +284,12 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/statuses/:id", StatusController, :show)
|
get("/statuses/:id", StatusController, :show)
|
||||||
put("/statuses/:id", StatusController, :update)
|
put("/statuses/:id", StatusController, :update)
|
||||||
delete("/statuses/:id", StatusController, :delete)
|
delete("/statuses/:id", StatusController, :delete)
|
||||||
get("/statuses", StatusController, :index)
|
|
||||||
|
|
||||||
get("/moderation_log", AdminAPIController, :list_log)
|
get("/moderation_log", AdminAPIController, :list_log)
|
||||||
|
|
||||||
post("/reload_emoji", AdminAPIController, :reload_emoji)
|
post("/reload_emoji", AdminAPIController, :reload_emoji)
|
||||||
get("/stats", AdminAPIController, :stats)
|
get("/stats", AdminAPIController, :stats)
|
||||||
|
|
||||||
get("/chats/:id", ChatController, :show)
|
|
||||||
get("/chats/:id/messages", ChatController, :messages)
|
|
||||||
delete("/chats/:id/messages/:message_id", ChatController, :delete_message)
|
delete("/chats/:id/messages/:message_id", ChatController, :delete_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.Plugs.EnsureStaffPrivilegedPlugTest do
|
||||||
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
test "accepts a user that is an admin" do
|
||||||
|
user = insert(:user, is_admin: true)
|
||||||
|
|
||||||
|
conn = assign(build_conn(), :user, user)
|
||||||
|
|
||||||
|
ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||||
|
|
||||||
|
assert conn == ret_conn
|
||||||
|
end
|
||||||
|
|
||||||
|
test "accepts a user that is a moderator when :privileged_staff is enabled" do
|
||||||
|
clear_config([:instance, :privileged_staff], true)
|
||||||
|
user = insert(:user, is_moderator: true)
|
||||||
|
|
||||||
|
conn = assign(build_conn(), :user, user)
|
||||||
|
|
||||||
|
ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||||
|
|
||||||
|
assert conn == ret_conn
|
||||||
|
end
|
||||||
|
|
||||||
|
test "denies a user that is a moderator when :privileged_staff is disabled" do
|
||||||
|
clear_config([:instance, :privileged_staff], false)
|
||||||
|
user = insert(:user, is_moderator: true)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||||
|
|
||||||
|
assert conn.status == 403
|
||||||
|
end
|
||||||
|
|
||||||
|
test "denies a user that isn't a staff member" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||||
|
|
||||||
|
assert conn.status == 403
|
||||||
|
end
|
||||||
|
|
||||||
|
test "denies when a user isn't set" do
|
||||||
|
conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
|
||||||
|
|
||||||
|
assert conn.status == 403
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue