~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Groups move from one host to another, whole, keeping their DID

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/migration
crates/atproto/src/jose.rs+5−0
@@ -31,6 +31,11 @@ pub fn b64(bytes: impl AsRef<[u8]>) -> String {
URL_SAFE_NO_PAD.encode(bytes)
}
/// The bytes `text` holds, base64url without padding.
pub fn unb64(text: &str) -> Option<Vec<u8>> {
URL_SAFE_NO_PAD.decode(text).ok()
}
/// The JSON object `part` holds, base64url: a JWT's header or claims.
pub fn json_of(part: &str) -> Option<Value> {
let bytes = URL_SAFE_NO_PAD.decode(part).ok()?;
crates/atproto/tests/jose.rs+2−0
@@ -107,5 +107,7 @@ fn hashes_and_draws_as_oauth_wants() {
"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"
);
assert_eq!(random(32).len(), 43);
assert_eq!(jose::unb64(&jose::b64(b"bytes")).unwrap(), b"bytes");
assert_eq!(jose::unb64("!!"), None);
assert_ne!(random(16), random(16));
}
crates/group-host/src/authority.rs+1−1
@@ -175,7 +175,7 @@ impl Host {
/// A write to `space`, of a group here, by `repo`: kept in the writer
/// set unless it knows a later one, and told to the space's syncers.
pub(crate) fn record_writer(
pub fn record_writer(
&self,
space: &str,
authority: &str,
crates/group-host/src/lib.rs+21−0
@@ -27,6 +27,7 @@ pub mod identity;
pub mod index;
pub mod index_api;
pub mod lifecycle;
pub mod migration;
pub mod moderation;
pub mod oauth;
pub mod oauth_clients;
@@ -394,6 +395,26 @@ pub fn router(host: Arc<Host>) -> Router {
"/xrpc/fyi.opensocial.removeRecoveryKey",
post(recovery::remove_recovery_key),
)
.route(
"/xrpc/fyi.opensocial.migratePrepare",
post(migration::migrate_prepare),
)
.route(
"/xrpc/fyi.opensocial.migrateExport",
get(migration::migrate_export),
)
.route(
"/xrpc/fyi.opensocial.migrateReceive",
post(migration::migrate_receive),
)
.route(
"/xrpc/fyi.opensocial.migrateComplete",
post(migration::migrate_complete),
)
.route(
"/xrpc/fyi.opensocial.migrateActivate",
post(migration::migrate_activate),
)
.route("/oauth/authorize", get(oauth::authorize))
.route(
"/console/client-metadata.json",
crates/group-host/src/migration.rsnew+682−0
682 lines changed: not loaded until asked for.
crates/group-host/src/repo.rs+7−2
@@ -85,6 +85,9 @@ pub struct Asked<'a> {
pub put: bool,
/// Asked of the writes as resolved, before any is made.
pub allow: Option<Allow<'a>>,
/// Made while the account is switched off, as one received from
/// another host is until the directory names this one.
pub off: bool,
}
fn invalid_swap(message: impl Into<String>) -> XrpcError {
@@ -268,7 +271,7 @@ impl Host {
}
/// `account`'s commit of `tree`, at the next revision.
fn sign(&self, account: &Account, tree: &Tree) -> Head {
pub(crate) fn sign(&self, account: &Account, tree: &Tree) -> Head {
let commit = Commit::sign(
&account.did,
tree.root(),
@@ -306,7 +309,9 @@ impl Host {
format!("no repo {did} here"),
)
})?;
self.active(&account.did)?;
if !asked.off {
self.active(&account.did)?;
}
let head = self
.store
.head(&account.did)
crates/group-host/src/space.rs+3−1
@@ -94,7 +94,9 @@ impl Host {
format!("no repo {did} here"),
)
})?;
self.active(&account.did)?;
if !asked.off {
self.active(&account.did)?;
}
let uri = space.to_string();
let head = self
.store
crates/group-host/src/store.rs+8−0
@@ -327,6 +327,13 @@ pub const MIGRATIONS: &[&str] = &[
added_at INTEGER NOT NULL,
PRIMARY KEY (grp, key)
);
",
"
CREATE TABLE migration_export (
did TEXT PRIMARY KEY REFERENCES account (did),
token_hash TEXT NOT NULL,
expires_at INTEGER NOT NULL
);
",
];
@@ -445,6 +452,7 @@ const DEACTIVATION: &str = "SELECT at, by, stewards FROM deactivation WHERE did
const ACTIVATE: &str = "DELETE FROM deactivation WHERE did = ?1";
/// What goes with an account, in an order its references allow.
const FORGET_ACCOUNT: &[&str] = &[
"DELETE FROM migration_export WHERE did = ?1",
"DELETE FROM recovery_key WHERE grp = ?1",
"DELETE FROM mod_event WHERE grp = ?1",
"DELETE FROM mod_subject WHERE grp = ?1",
crates/group-host/src/token_writes.rs+1−0
@@ -343,6 +343,7 @@ async fn put_or_delete(
swap_record,
put: true,
allow: Some(&allow),
off: false,
};
// A put of what is there, or a delete of what is not, makes no commit.
let committed = host.write_asked(group, std::slice::from_ref(&write), &asked)?;
crates/group-host/tests/migration.rsnew+667−0
667 lines changed: not loaded until asked for.
docs/design/moving.mdnew+56−0
@@ -0,0 +1,56 @@
# Moving a group
A group moves from one group host to another whole, and keeps its DID:
everyone who follows it, and everything that points at it, still does
(`migration.rs`).
Its identity moves by a PLC operation the host it leaves signs with its
rotation key, and everything it holds moves with it: its public repo, its
files, and in each of its spaces its own repo and what the space's
authority keeps (whether anyone may read it, who writes there and what
they last wrote, and who may beyond its access record). Members' repos in
the group's spaces are theirs, at their own PDSes, and stay there: the
new host keeps who writes, so it reads them on without waiting for them
to write again, and their PDSes find the new authority by the group's
DID.
## The steps
1. **`migratePrepare`**, at the host it leaves, for one who configures
the group: a service token the group signs, for the new host; the
group's handle, address and spaces; and a token, good for an hour,
to pull the rest with. Preparing again replaces the token.
2. **`migrateReceive`**, at the new host. It takes the group in only:
- when the service token is the group's, by its current key in the
directory, for this host;
- reaching the host it leaves only at the address the group's DID
document names, and only at a public address;
- with its public repo signed by the group and whole, each space's
repo what its commit's set hash says, and each file what its CID
says;
- and for one who configures the group by its own records, as they
arrive.
Anything less and nothing of it stays. It is kept switched off, with
keys of its own here, under a handle here (the same label, under this
host's domain; a domain of the group's own kept), and the answer is
what the PLC operation should name.
3. **`migrateComplete`**, at the host it leaves: the operation signed and
sent, naming the new host, its keys and its handle; its stewards'
recovery keys kept ahead of the new host's; and the group switched off
there. Once handed over, it is that host's no more to hand.
4. **`migrateActivate`**, at the new host: once the directory names this
host and the group's new key, the group switched on, and its spaces'
index read again.
The `opensocial` command walks through the four (step 9).
## From the prototype
- A space's state moves as this host keeps it, as JSON, not as the space
alpha's meta archive: a move between two group hosts does not need it.
A move to a plain PDS (the prototype's `leaving`) is not here.
- The new host makes the group's repos again from the records it pulls,
under the group's new key, rather than keeping the old commits.
- Spaces the group writes in that another governs (an invite in a
member's inbox) do not move: they are that space's authority's.
docs/design/README.md+3−1
@@ -121,7 +121,9 @@ says otherwise.
8. **Moderation, recovery and moving.** Reports, labels, subjects and
history, and the console's moderation page (`moderation.rs`; done, see
[moderation](moderation.md)); recovery keys (`recovery.rs`; done, see
[recovery](recovery.md)); then importing an account; migrating a group to another host and moving the host itself:
[recovery](recovery.md)); moving a group to another host
(`migration.rs`; done, see [moving](moving.md)); then importing an
account, and moving the host itself:
`methods/{moderation,recovery,importAccount,migration}.ts`,
`hostLabels.ts`, `scripts/move-host.ts`.
9. **MCP and the command.** The MCP tools over what steps 4 to 8 brought,
lexicons/fyi/opensocial/migrateExport.json+1−1