Add configs for creating the admin room and granting first user.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -75,6 +75,7 @@ COPY <<EOF complement.toml
|
|||||||
allow_public_room_directory_over_federation = true
|
allow_public_room_directory_over_federation = true
|
||||||
allow_public_room_directory_without_auth = true
|
allow_public_room_directory_without_auth = true
|
||||||
allow_registration = true
|
allow_registration = true
|
||||||
|
create_admin_room = false
|
||||||
database_path = "/database"
|
database_path = "/database"
|
||||||
dns_attempts = 20
|
dns_attempts = 20
|
||||||
dns_timeout = 60
|
dns_timeout = 60
|
||||||
|
|||||||
@@ -513,19 +513,18 @@ pub(crate) async fn register_route(
|
|||||||
// If this is the first real user, grant them admin privileges except for guest
|
// If this is the first real user, grant them admin privileges except for guest
|
||||||
// users
|
// users
|
||||||
// Note: the server user is generated first
|
// Note: the server user is generated first
|
||||||
if !is_guest {
|
if !is_guest
|
||||||
if let Ok(admin_room) = services.admin.get_admin_room().await {
|
&& services.config.grant_admin_to_first_user
|
||||||
if services
|
&& let Ok(admin_room) = services.admin.get_admin_room().await
|
||||||
.rooms
|
&& services
|
||||||
.state_cache
|
.rooms
|
||||||
.room_joined_count(&admin_room)
|
.state_cache
|
||||||
.await
|
.room_joined_count(&admin_room)
|
||||||
.is_ok_and(is_equal_to!(1))
|
.await
|
||||||
{
|
.is_ok_and(is_equal_to!(1))
|
||||||
services.admin.make_user_admin(&user_id).await?;
|
{
|
||||||
warn!("Granting {user_id} admin privileges as the first user");
|
services.admin.make_user_admin(&user_id).await?;
|
||||||
}
|
warn!("Granting {user_id} admin privileges as the first user");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if body.appservice_info.is_none()
|
if body.appservice_info.is_none()
|
||||||
|
|||||||
@@ -1683,6 +1683,23 @@ pub struct Config {
|
|||||||
#[serde(default = "default_admin_room_tag")]
|
#[serde(default = "default_admin_room_tag")]
|
||||||
pub admin_room_tag: String,
|
pub admin_room_tag: String,
|
||||||
|
|
||||||
|
/// Whether to grant the first user to register admin privileges by joining
|
||||||
|
/// them to the admin room. Note that technically the next user to register
|
||||||
|
/// when the admin room is empty (or only contains the server-user) is
|
||||||
|
/// granted, and only when the admin room is enabled.
|
||||||
|
///
|
||||||
|
/// default: true
|
||||||
|
#[serde(default = "true_fn")]
|
||||||
|
pub grant_admin_to_first_user: bool,
|
||||||
|
|
||||||
|
/// Whether the admin room is created on first startup. Users should not set
|
||||||
|
/// this to false. Developers can set this to false during integration tests
|
||||||
|
/// to reduce activity and output.
|
||||||
|
///
|
||||||
|
/// default: true
|
||||||
|
#[serde(default = "true_fn")]
|
||||||
|
pub create_admin_room: bool,
|
||||||
|
|
||||||
/// Sentry.io crash/panic reporting, performance monitoring/metrics, etc.
|
/// Sentry.io crash/panic reporting, performance monitoring/metrics, etc.
|
||||||
/// This is NOT enabled by default. tuwunel's default Sentry reporting
|
/// This is NOT enabled by default. tuwunel's default Sentry reporting
|
||||||
/// endpoint domain is `o4509498990067712.ingest.us.sentry.io`.
|
/// endpoint domain is `o4509498990067712.ingest.us.sentry.io`.
|
||||||
|
|||||||
@@ -20,6 +20,22 @@ use tuwunel_core::{Result, pdu::PduBuilder};
|
|||||||
|
|
||||||
use crate::Services;
|
use crate::Services;
|
||||||
|
|
||||||
|
/// Create the server user.
|
||||||
|
///
|
||||||
|
/// This should be the first user on the server and created prior to the
|
||||||
|
/// admin room.
|
||||||
|
pub async fn create_server_user(services: &Services) -> Result {
|
||||||
|
let server_user = services.globals.server_user.as_ref();
|
||||||
|
|
||||||
|
// Create a user for the server
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.create(server_user, None, None)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Create the admin room.
|
/// Create the admin room.
|
||||||
///
|
///
|
||||||
/// Users in this room are considered admins by tuwunel, and the room can be
|
/// Users in this room are considered admins by tuwunel, and the room can be
|
||||||
@@ -38,10 +54,9 @@ pub async fn create_admin_room(services: &Services) -> Result {
|
|||||||
|
|
||||||
// Create a user for the server
|
// Create a user for the server
|
||||||
let server_user = services.globals.server_user.as_ref();
|
let server_user = services.globals.server_user.as_ref();
|
||||||
services
|
if !services.users.exists(server_user).await {
|
||||||
.users
|
create_server_user(services).await?;
|
||||||
.create(server_user, None, None)
|
}
|
||||||
.await?;
|
|
||||||
|
|
||||||
let create_content = {
|
let create_content = {
|
||||||
use RoomVersionId::*;
|
use RoomVersionId::*;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod console;
|
pub mod console;
|
||||||
mod create;
|
pub mod create;
|
||||||
mod execute;
|
mod execute;
|
||||||
mod grant;
|
mod grant;
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,11 @@ async fn fresh(services: &Services) -> Result {
|
|||||||
db["global"].insert(b"fix_readreceiptid_readreceipt_duplicates", []);
|
db["global"].insert(b"fix_readreceiptid_readreceipt_duplicates", []);
|
||||||
|
|
||||||
// Create the admin room and server user on first run
|
// Create the admin room and server user on first run
|
||||||
crate::admin::create_admin_room(services)
|
if services.config.create_admin_room {
|
||||||
.boxed()
|
crate::admin::create_admin_room(services)
|
||||||
.await?;
|
.boxed()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
warn!("Created new RocksDB database with version {DATABASE_VERSION}");
|
warn!("Created new RocksDB database with version {DATABASE_VERSION}");
|
||||||
|
|
||||||
|
|||||||
@@ -1450,6 +1450,19 @@
|
|||||||
#
|
#
|
||||||
#admin_room_tag = "m.server_notice"
|
#admin_room_tag = "m.server_notice"
|
||||||
|
|
||||||
|
# Whether to grant the first user to register admin privileges by joining
|
||||||
|
# them to the admin room. Note that technically the next user to register
|
||||||
|
# when the admin room is empty (or only contains the server-user) is
|
||||||
|
# granted, and only when the admin room is enabled.
|
||||||
|
#
|
||||||
|
#grant_admin_to_first_user = true
|
||||||
|
|
||||||
|
# Whether the admin room is created on first startup. Users should not set
|
||||||
|
# this to false. Developers can set this to false during integration tests
|
||||||
|
# to reduce activity and output.
|
||||||
|
#
|
||||||
|
#create_admin_room = true
|
||||||
|
|
||||||
# Sentry.io crash/panic reporting, performance monitoring/metrics, etc.
|
# Sentry.io crash/panic reporting, performance monitoring/metrics, etc.
|
||||||
# This is NOT enabled by default. tuwunel's default Sentry reporting
|
# This is NOT enabled by default. tuwunel's default Sentry reporting
|
||||||
# endpoint domain is `o4509498990067712.ingest.us.sentry.io`.
|
# endpoint domain is `o4509498990067712.ingest.us.sentry.io`.
|
||||||
|
|||||||
Reference in New Issue
Block a user