new migration mode
This commit is contained in:
parent
e94ed21061
commit
337b6b9736
6 changed files with 179 additions and 58 deletions
|
|
@ -14,18 +14,17 @@
|
|||
{
|
||||
matrixoidc = {
|
||||
enable = true;
|
||||
jwtSecretFile = config.age.secrets."oidcJwtSecret.age".path;
|
||||
# A snapshot from before the cutover, made by ~/Documents/fednex-password-hashes.sh
|
||||
passwordHashesFile = "/var/lib/matrix-password-hashes/hashes";
|
||||
args = [
|
||||
"--socket"
|
||||
socket
|
||||
"--homeserver"
|
||||
config.services.matrix-continuwuity.settings.global.well_known.client
|
||||
"--issuer"
|
||||
"https://${domain}"
|
||||
"--authorizeEndpoint"
|
||||
"https://federated.nexus/login"
|
||||
"--migrateUri"
|
||||
"https://federated.nexus/migrate/"
|
||||
"--serviceDomain"
|
||||
"federated.nexus"
|
||||
config.quad.matrix.domain
|
||||
];
|
||||
group = "caddy";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ let
|
|||
bootstrapDir = "/var/lib/kanidm-bootstrap";
|
||||
mailSenderToken = "${bootstrapDir}/mail-sender-token";
|
||||
migrateToken = "${bootstrapDir}/migrate-token";
|
||||
registrationToken = "${bootstrapDir}/registration-token";
|
||||
|
||||
secretsDir = "/var/lib/kanidm-oauth2-secrets";
|
||||
oauth2Clients = builtins.attrNames config.services.kanidm.provision.systems.oauth2;
|
||||
|
|
@ -90,6 +91,8 @@ in
|
|||
./hide-radius.patch
|
||||
# Applies dark mode before the page is drawn, rather than flashing light mode first
|
||||
./theme-flash.patch
|
||||
# Emails new accounts a welcome message instead of "This is your credential reset link"
|
||||
./welcome-email.patch
|
||||
];
|
||||
});
|
||||
|
||||
|
|
@ -164,6 +167,24 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
"03-registration" = {
|
||||
id = "5837871f-1810-47a5-ad43-60ecbf313462";
|
||||
assertions = [
|
||||
{
|
||||
# Used by nexusbot to create approved registrations
|
||||
state = "present";
|
||||
id = "662082c2-9ec4-443d-98b5-537c4d128914";
|
||||
class = [
|
||||
"account"
|
||||
"service_account"
|
||||
];
|
||||
name = "registration";
|
||||
displayname = "Registration approval";
|
||||
entry_managed_by = "idm_admins";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Existing built-in entries: class is omitted, as asserting it would
|
||||
# replace the entry's classes
|
||||
"10-builtin" = {
|
||||
|
|
@ -192,7 +213,7 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
# Its /migrate creates Kanidm accounts for legacy Matrix users
|
||||
# Creates Kanidm accounts for legacy Matrix users
|
||||
matrixoidc = {
|
||||
kanidmTokenFile = migrateToken;
|
||||
args = [
|
||||
|
|
@ -201,6 +222,15 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
# Creates Kanidm accounts for approved registrations
|
||||
nexusbot = {
|
||||
kanidmTokenFile = registrationToken;
|
||||
args = [
|
||||
"--kanidmUrl"
|
||||
"https://${domain}"
|
||||
];
|
||||
};
|
||||
|
||||
caddy.virtualHosts.${domain}.extraConfig = ''
|
||||
reverse_proxy https://${address} {
|
||||
transport http {
|
||||
|
|
@ -212,11 +242,15 @@ in
|
|||
};
|
||||
|
||||
systemd.services = {
|
||||
# Its token is created by kanidm-bootstrap
|
||||
# Their tokens are created by kanidm-bootstrap
|
||||
matrixoidc = {
|
||||
wants = [ "kanidm-bootstrap.service" ];
|
||||
after = [ "kanidm-bootstrap.service" ];
|
||||
};
|
||||
nexusbot = {
|
||||
wants = [ "kanidm-bootstrap.service" ];
|
||||
after = [ "kanidm-bootstrap.service" ];
|
||||
};
|
||||
|
||||
kanidm-tls = {
|
||||
description = "Generate Kanidm's loopback TLS certificate";
|
||||
|
|
@ -331,7 +365,7 @@ in
|
|||
# Asserting these memberships in a migration didn't persist, so they're
|
||||
# re-applied here on every start. Adding an existing member is a no-op.
|
||||
kanidm group add-members idm_message_senders mail-sender -D idm_admin >/dev/null
|
||||
kanidm group add-members idm_people_admins migrate -D idm_admin >/dev/null
|
||||
kanidm group add-members idm_people_admins migrate registration -D idm_admin >/dev/null
|
||||
|
||||
# Usernames must match Matrix localparts, so people can't rename themeselves.
|
||||
# This also locks display and legal names, as Kanidm has no separate permission for those
|
||||
|
|
@ -356,6 +390,7 @@ in
|
|||
|
||||
token mail-sender ${mailSenderToken}
|
||||
token migrate ${migrateToken}
|
||||
token registration ${registrationToken}
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
(% endif -%)
|
||||
|
||||
+ <div class="input-group mb-3 justify-content-md-center text-center">
|
||||
+ <a href="https://federated.nexus/login?redirect_uri=https://auth.federated.nexus/migrate">Don't have a Kanidm account yet? Migrate your legacy Federated Nexus account</a>
|
||||
+ <a href="https://federated.nexus/migrate/">Don't have a Kanidm account yet? Migrate your legacy Federated Nexus account</a>
|
||||
+ </div>
|
||||
+
|
||||
</form>
|
||||
|
|
|
|||
65
clients/quadraticserver/kanidm/welcome-email.patch
Normal file
65
clients/quadraticserver/kanidm/welcome-email.patch
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
diff -ru a/proto/src/v1/message.rs b/proto/src/v1/message.rs
|
||||
--- a/proto/src/v1/message.rs 2026-11-15 20:02:57.593682769 -0500
|
||||
+++ b/proto/src/v1/message.rs 2026-11-15 20:03:05.231705521 -0500
|
||||
@@ -12,6 +12,9 @@
|
||||
intent_id: String,
|
||||
#[serde(with = "time::serde::timestamp")]
|
||||
expiry_time: OffsetDateTime,
|
||||
+ // The account has no credentials yet, so this sets them up for the first time
|
||||
+ #[serde(default)]
|
||||
+ first_setup: bool,
|
||||
},
|
||||
AccountSignupRequestV1 {
|
||||
username: String,
|
||||
diff -ru a/server/lib/src/idm/credupdatesession.rs b/server/lib/src/idm/credupdatesession.rs
|
||||
--- a/server/lib/src/idm/credupdatesession.rs 2026-11-15 20:02:57.602151429 -0500
|
||||
+++ b/server/lib/src/idm/credupdatesession.rs 2026-11-15 20:03:05.233821288 -0500
|
||||
@@ -1107,6 +1107,9 @@
|
||||
display_name,
|
||||
intent_id,
|
||||
expiry_time,
|
||||
+ first_setup: account.primary.is_none()
|
||||
+ && account.passkeys.is_empty()
|
||||
+ && account.attested_passkeys.is_empty(),
|
||||
};
|
||||
|
||||
let ident = Identity::message_queue();
|
||||
diff -ru a/tools/mail_sender/src/main.rs b/tools/mail_sender/src/main.rs
|
||||
--- a/tools/mail_sender/src/main.rs 2026-11-15 20:02:57.611181240 -0500
|
||||
+++ b/tools/mail_sender/src/main.rs 2026-11-15 20:03:05.236297186 -0500
|
||||
@@ -94,6 +94,7 @@
|
||||
display_name,
|
||||
intent_id,
|
||||
expiry_time,
|
||||
+ first_setup,
|
||||
} => {
|
||||
let mut reset_url = ctx.instance_url.clone();
|
||||
reset_url.set_path("/ui/reset");
|
||||
@@ -108,6 +109,27 @@
|
||||
.format(&Rfc2822)
|
||||
.unwrap_or("ERROR - invalid expiration time".into());
|
||||
|
||||
+ if *first_setup {
|
||||
+ return (
|
||||
+ format!("Welcome to {0}", ctx.instance_display_name),
|
||||
+ format!(
|
||||
+ r#"Welcome to {instance}, {display_name}
|
||||
+
|
||||
+You can set up your authentication here:
|
||||
+
|
||||
+{reset_url}
|
||||
+
|
||||
+This link will expire at {pretty_expiry_time}
|
||||
+
|
||||
+
|
||||
+msg_id: {message_id}
|
||||
+ "#,
|
||||
+ instance = ctx.instance_display_name,
|
||||
+ message_id = ctx.message_id,
|
||||
+ ),
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
(
|
||||
format!("{0}: Credential Reset Link", ctx.instance_display_name),
|
||||
format!(
|
||||
|
|
@ -14,56 +14,19 @@
|
|||
{
|
||||
nexusbot = {
|
||||
enable = true;
|
||||
botPasswordFile = config.age.secrets."botPassword.age".path;
|
||||
smtpPasswordFile = config.age.secrets."smtpPassword.age".path;
|
||||
# An access token from a password login, made before continuwuity switched to Kanidm logins
|
||||
botTokenFile = config.age.secrets."botToken.age".path;
|
||||
args = [
|
||||
"--socket"
|
||||
socket
|
||||
"--homeserver"
|
||||
config.services.matrix-continuwuity.settings.global.well_known.client
|
||||
"--username"
|
||||
"nexusbot"
|
||||
"--adminRoom"
|
||||
"#admins:federated.nexus"
|
||||
"--successUri"
|
||||
"https://federated.nexus/success"
|
||||
"--failureUri"
|
||||
"https://federated.nexus/failure"
|
||||
"--inviteTo"
|
||||
"#space:federated.nexus"
|
||||
"--adminName"
|
||||
"conduit"
|
||||
"--email"
|
||||
("inf" + "o@f" + "edera" + "ted.n" + "exus")
|
||||
"--mailDomain"
|
||||
"email-smtp.us-east-1.amazonaws.com"
|
||||
"--mailName"
|
||||
"Federated Nexus"
|
||||
"--mailUsername"
|
||||
"AKIAREHCBHZLJ3FNCCSM"
|
||||
"--subject"
|
||||
"Your registration for Federated Nexus has been accepted!"
|
||||
"--plainText"
|
||||
"Your registration for Federated Nexus has been accepted! Your credentials are:
|
||||
Username: @{username}
|
||||
Password: @{password}
|
||||
|
||||
You can change your password in your favorite Matrix client, or here: https://matrix.federated.nexus/_continuwuity/account/password/change
|
||||
|
||||
If you have any questions, check out our documentation: https://federated.nexus/services/matrix/.
|
||||
|
||||
If you have any issues, reply to this email."
|
||||
"--markdown"
|
||||
"# Your registration for Federated Nexus has been accepted!
|
||||
## Your credentials are:
|
||||
- ### Username: @{username}
|
||||
- ### Password: @{password}
|
||||
|
||||
You can change your password in your favorite Matrix client, or [here](https://matrix.federated.nexus/_continuwuity/account/password/change).
|
||||
|
||||
If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/).
|
||||
|
||||
If you have any issues, reply to this email."
|
||||
];
|
||||
group = "caddy";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,19 +1,73 @@
|
|||
{ lib, pkgs, ... }: {
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
client = "matrix";
|
||||
in
|
||||
{
|
||||
systemd.services.continuwuity = {
|
||||
unitConfig.RequiresMountsFor = [ "/var/lib/private/continuwuity/media" ];
|
||||
# It fetches Kanidm's OIDC metadata once at startup, and logins fail until a restart if that fails
|
||||
requires = [ "kanidm-oauth2-secrets.service" ];
|
||||
wants = [ "kanidm.service" ];
|
||||
after = [
|
||||
"kanidm-oauth2-secrets.service"
|
||||
"kanidm.service"
|
||||
"caddy.service"
|
||||
];
|
||||
serviceConfig = {
|
||||
MemoryMax = "5.5G";
|
||||
MemorySwapMax = "4.5G";
|
||||
TimeoutStartSec = "10m";
|
||||
Restart = lib.mkForce "always";
|
||||
ExecStartPost = "/bin/sh -c 'until ${lib.getExe pkgs.curl} -s -f https://matrix.federated.nexus/.well-known/matrix/client; do sleep 1; done'";
|
||||
LoadCredential = [
|
||||
"oidc-secret:${config.services.kanidm.provision.systems.oauth2.${client}.basicSecretFile}"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.kanidm.provision.systems.oauth2.${client} = {
|
||||
displayName = "Matrix";
|
||||
originUrl = "${config.services.matrix-continuwuity.settings.global.well_known.client}/_continuwuity/oidc/complete";
|
||||
originLanding = "https://app.${config.quad.matrix.domain}";
|
||||
imageFile = "${
|
||||
inputs.sable.packages.${pkgs.stdenv.hostPlatform.system}.default
|
||||
}/public/svg/logo.svg";
|
||||
basicSecretFile = "/var/lib/kanidm-oauth2-secrets/${client}";
|
||||
# The username claim is the Matrix localpart
|
||||
preferShortUsername = true;
|
||||
scopeMaps.idm_all_persons = [
|
||||
"openid"
|
||||
"email"
|
||||
"profile"
|
||||
];
|
||||
};
|
||||
|
||||
quad.matrix = rec {
|
||||
enable = true;
|
||||
domain = "federated.nexus";
|
||||
settings = {
|
||||
auto_join_rooms = [ "#space:${domain}" ];
|
||||
|
||||
# Logins go through Kanidm only. Existing accounts are linked by username
|
||||
# on first login, and new ones are created then
|
||||
oauth.oidc = {
|
||||
discovery_url = "${config.services.kanidm.server.settings.origin}/oauth2/openid/${client}";
|
||||
client_id = client;
|
||||
client_secret_file = "/run/credentials/continuwuity.service/oidc-secret";
|
||||
provider_name = "Federated Nexus";
|
||||
prompt_for_localpart = false;
|
||||
additional_scopes = [
|
||||
"email"
|
||||
"profile"
|
||||
];
|
||||
};
|
||||
|
||||
admins_list = [
|
||||
"@nexusbot:federated.nexus"
|
||||
"@quadradical:federated.nexus"
|
||||
|
|
|
|||
Loading…
Reference in a new issue