chadtmiller.com/group-host
atmosphere group host
0
0
A group's site stays at its address when it takes a domain of its own
crates/group-host/src/sites.rs+13−9
| @@ -1,8 +1,10 @@ | ||
//! A group's website: the static files its `fyi.opensocial.site` record, | ||
//! in its public repo, names, served as they are at its handle, | ||
//! `https://<handle>/`. The host keeps `/.well-known/` there for itself. | ||
//! in its public repo, names, served as they are at its address, | ||
//! `https://<address>/`: the name under the host's domain it was made at, | ||
//! which stays its site's when it takes a handle on a domain of its own. | ||
//! The host keeps `/.well-known/` there for itself. | ||
//! | ||
//! A group's handle is a name under the host's own domain, so a browser | ||
//! A group's address is a name under the host's own domain, so a browser | ||
//! takes its pages for the same site as the console. Every answer here is | ||
//! sandboxed (`Content-Security-Policy: sandbox`), which gives each page an | ||
//! origin of its own that no other shares: it can neither read nor set a | ||
| @@ -207,8 +209,8 @@ fn moved(to: &str, status: StatusCode) -> Response { | ||
} | ||
| ||
impl Host { | ||
/// The group whose handle a request to `name` names, unless `name` is | ||
/// the host's own. | ||
/// The group whose address a request to `name` names, and its handle, | ||
/// unless `name` is the host's own. | ||
fn site_of(&self, name: &str) -> Option<(String, String)> { | ||
let name = name | ||
.split(':') | ||
| @@ -224,8 +226,9 @@ impl Host { | ||
if name.is_empty() || name == own.split(':').next().unwrap_or_default() { | ||
return None; | ||
} | ||
let account = self.store.account(&name).ok().flatten()?; | ||
(account.handle == name).then_some((account.did, account.handle)) | ||
let did = self.store.addressed(&name).ok().flatten()?; | ||
let account = self.store.account(&did).ok().flatten()?; | ||
Some((account.did, account.handle)) | ||
} | ||
| ||
/// The file of `did`'s site at `path`: its type and bytes, and its ETag. | ||
| @@ -442,7 +445,8 @@ pub async fn put_site( | ||
..Asked::default() | ||
}; | ||
host.write_asked(&group, std::slice::from_ref(&write), &asked)?; | ||
let handle = group_of(&host, &group)?; | ||
let address = host.store.address(&group).map_err(XrpcError::internal)?; | ||
let address = address.expect("a group has an address"); | ||
let scheme = host | ||
.config | ||
.public_url | ||
| @@ -452,7 +456,7 @@ pub async fn put_site( | ||
Ok(Json(json!({ | ||
"uri": format!("at://{group}/{SITE}/self"), | ||
"cid": record_cid(SITE, &site)?.to_string(), | ||
"url": format!("{scheme}://{handle}/"), | ||
"url": format!("{scheme}://{address}/"), | ||
"uploaded": uploaded, | ||
}))) | ||
} | ||
crates/group-host/tests/sites.rs+23−1
| @@ -1,5 +1,5 @@ | ||
//! A group's website: published whole by those who configure the group, | ||
//! and served as it is, sandboxed, at the group's handle. | ||
//! and served as it is, sandboxed, at the group's address. | ||
| ||
mod common; | ||
| ||
| @@ -269,6 +269,28 @@ async fn a_site_is_taken_down() { | ||
assert_eq!(again.0, 200, "{}", again.1); | ||
} | ||
| ||
#[tokio::test] | ||
async fn a_site_stays_at_the_address_when_the_handle_moves_to_a_domain_of_its_own() { | ||
let h = start(&[], false).await; | ||
let (did, [alice, ..]) = group(&h).await; | ||
let body = json!({"group": did, "files": [{"path": "index.html", "text": "hi"}]}); | ||
let made = call(&h, &alice, "putSite", body.clone()).await; | ||
assert_eq!(made.0, 200, "{}", made.1); | ||
// The handle updateGroupHandle would give it. | ||
h.host.store.set_handle(&did, "riders.test", &[]).unwrap(); | ||
| ||
let front = page(&h, "/").await; | ||
assert_eq!((front.status, front.body.as_str()), (200, "hi")); | ||
assert_eq!(front.header("content-security-policy"), SANDBOX); | ||
// The domain is the group's name, not where its site is. | ||
let there = ask(&h, "GET", "riders.test", "/", &[]).await; | ||
assert_ne!(there.body, "hi"); | ||
assert_eq!(there.header("content-security-policy"), ""); | ||
// And putSite says the site is at the address. | ||
let again = call(&h, &alice, "putSite", body).await; | ||
assert_eq!(again.1["url"], format!("https://{RIDERS}/")); | ||
} | ||
| ||
#[tokio::test] | ||
async fn an_app_writes_the_site_as_the_group_only_if_its_member_configures_it() { | ||
let h = start(&[], false).await; | ||
crates/group-host-mcp/src/lib.rs+1−1
| @@ -380,7 +380,7 @@ const TOOLS: &[(&str, &[&str], &str, Made)] = &[ | ||
( | ||
"site_publish", | ||
&[], | ||
"Publishes the group's website, whole, at its handle (`https://<handle>/`): every file \ | ||
"Publishes the group's website, whole, at its address (`https://<address>/`): every file \ | ||
of it, each as text or as bytes, in place of the site there; a file the group holds \ | ||
already is used again. Its pages run sandboxed, each in an origin of its own, with no \ | ||
cookies or storage; a page reads live data from the host's public methods.", | ||
docs/design/groups.md+4−3
| @@ -60,9 +60,10 @@ Details: | ||
| ||
A group needs a name before it has a domain of its own. The host gives it | ||
a handle of one label under `HANDLE_DOMAIN`, the domain of this host's | ||
handles, and keeps that handle as the group's address. The address never | ||
changes. When the group takes a handle on its own domain, the address | ||
stays reserved for it, until the group is deleted. | ||
handles, and keeps that handle as the group's address, where its site is | ||
served ([sites](sites.md)). The address never changes. When the group | ||
takes a handle on its own domain, the address stays reserved for it, and | ||
its site stays there, until the group is deleted. | ||
| ||
`checkAddress` says, without signing in, whether an address is free: not | ||
an account's handle here and not kept as a group's address. | ||
docs/design/README.md+2−2
| @@ -31,7 +31,7 @@ accounts on their own PDSes, anywhere on the network. | ||
| --- | --- | | ||
| The group's identity | its DID document, in the PLC directory, changed with the host's rotation key and any recovery keys ([recovery](recovery.md)) | | ||
| Its public records and files | its repo here | | ||
| Its website | a record in its repo here, served at its handle ([sites](sites.md)) | | ||
| Its website | a record in its repo here, served at its address ([sites](sites.md)) | | ||
| Its profile, rules and labeler | its `meta` space, in the group's repo there | | ||
| Its roles, permissions, memberships and spaces | its `members` space, in the group's repo there | | ||
| What members write in its spaces | each member's own repo in the space, on their own PDS | | ||
| @@ -62,7 +62,7 @@ accounts on their own PDSes, anywhere on the network. | ||
token may do. | ||
- [Moderation](moderation.md): labels, the queue, and reports. | ||
- [Sites](sites.md): a group's website, published whole and served | ||
sandboxed at its handle. | ||
sandboxed at its address. | ||
- [MCP](mcp.md): connecting an AI app to a group, and its tools. | ||
- [Recovery](recovery.md): keys that let a group's stewards hold its | ||
identity. | ||
docs/design/sites.md+10−7
| @@ -1,8 +1,8 @@ | ||
# Sites | ||
| ||
A group can have a website: a front page that says who it is, or as many | ||
pages as it likes. The host serves it at the group's handle, | ||
`https://<handle>/`, as static files, the way they were published. It has | ||
pages as it likes. The host serves it at the group's address, | ||
`https://<address>/`, as static files, the way they were published. It has | ||
no templates, no build step and no rendering on the server. A page that | ||
wants live data, such as the group's events or members, asks the host's | ||
public methods from the browser. | ||
| @@ -59,10 +59,13 @@ segment, backslash or control character. | ||
| ||
## Serving | ||
| ||
A request whose `Host` is a group's handle here is answered from its site, | ||
except under `/.well-known/`, which the host keeps for itself there: the | ||
handle's `atproto-did` is how anyone checks that the handle names the | ||
group. A request to the host's own name, `PUBLIC_URL`, is never a site's. | ||
A request whose `Host` is a group's address here is answered from its site, | ||
except under `/.well-known/`, which the host keeps for itself there: while | ||
the address is the group's handle, its `atproto-did` is how anyone checks | ||
that the handle names the group. The address is where the group was made | ||
([groups](groups.md#its-address)), and stays its site's when the group takes | ||
a handle on a domain of its own; that domain is the group's name, not its | ||
site's. A request to the host's own name, `PUBLIC_URL`, is never a site's. | ||
| ||
Only `GET` and `HEAD` are answered; anything else is 405. A path is read | ||
with its `%XX` escapes decoded, then answered in this order: | ||
| @@ -85,7 +88,7 @@ max-age=60`. A browser that holds that ETag already is answered 304. | ||
| ||
## The sandbox | ||
| ||
A group's handle is a name under the host's domain, so a browser takes | ||
A group's address is a name under the host's domain, so a browser takes | ||
every group's pages for the same site as the console, at the host's own | ||
name. Left alone, a page's scripts could set a cookie for the whole | ||
domain, which the console would then receive. They could also send a | ||
docs/reference/api.md+1−1
| @@ -127,7 +127,7 @@ A group's website ([sites](../design/sites.md)). | ||
| --- | --- | | ||
| `POST fyi.opensocial.putSite` | publishes a group's site whole from the files given, each as text or bytes, in place of the one there; takes a body as large as `BLOB_UPLOAD_LIMIT` | | ||
| `POST fyi.opensocial.deleteSite` | takes a group's site down | | ||
| `GET`, `HEAD` `https://<handle>/<path>` | a file of the site of the group whose handle the request's `Host` names, sandboxed; the host keeps `/.well-known/` there for itself | | ||
| `GET`, `HEAD` `https://<address>/<path>` | a file of the site of the group whose address the request's `Host` names, sandboxed; the host keeps `/.well-known/` there for itself | | ||
| ||
As the spaces' authority and the PDS of the group's own repo in each, the | ||
host answers the space alpha's methods: | ||
docs/reference/cli.md+1−1
| @@ -88,7 +88,7 @@ an MCP client acts in one group. | ||
| ||
| Command | What it does | | ||
| --- | --- | | ||
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>]` | publishes the files under `<dir>`, but those whose names start with a dot, as the group's website at its handle, in place of the one there: each as text if it is UTF-8, else as bytes | | ||
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>]` | publishes the files under `<dir>`, but those whose names start with a dot, as the group's website at its address, in place of the one there: each as text if it is UTF-8, else as bytes | | ||
| `site delete <group>` | takes the group's website down | | ||
| ||
### member | ||
lexicons/fyi/opensocial/defs.json+1−1
| @@ -552,7 +552,7 @@ | ||
"url": { | ||
"type": "string", | ||
"format": "uri", | ||
"description": "The group's own site, if not at its handle." | ||
"description": "The group's own site, if not at its address." | ||
}, | ||
"memberCount": { | ||
"type": "integer", | ||
lexicons/fyi/opensocial/putSite.json+1−1
| @@ -52,7 +52,7 @@ | ||
"properties": { | ||
"uri": { "type": "string", "format": "at-uri", "description": "The site record." }, | ||
"cid": { "type": "string", "format": "cid", "description": "The site record's CID." }, | ||
"url": { "type": "string", "format": "uri", "description": "Where the site is served: the group's handle, over https." }, | ||
"url": { "type": "string", "format": "uri", "description": "Where the site is served: the group's address, over https." }, | ||
"uploaded": { "type": "integer", "minimum": 0, "description": "How many of the files given were new to the group; the rest it held already." } | ||
} | ||
} | ||