forked from vhaudiquet/rhema-together
feat: add account avatars and a deployable image
Accounts get a profile page with an uploaded picture, shown in the sidebar, the room bar, and every human message. Pictures live in the SQLite database and are served through an authenticated route. Hardening from the security audit: preview hosts expire after 24 hours and carry no-referrer; removing a member or archiving a room ends their event feed, presence socket, and terminal within seconds; previews and the terminal pin the SSH host key; invites are claimed atomically; missing accounts spend the same argon2 time as wrong passwords; registration is closed by default; WebSockets check the origin; and the master key is created with mode 0600. The Dockerfile builds one image with the static client and the server. The Helm chart runs a single replica with a SQLite volume, a wildcard preview ingress, and the proxy settings the event feed and uploads need. It refuses more than one replica because state is in process.
This commit is contained in:
1 parent
7e7a1d2bb6
commit
3b82719d56
38 files changed
+1307
-106
No files matched your search
+32
-13
@@ -46,13 +46,26 @@ impl client::Handler for HostKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens a connection for the preview proxy.
|
||||
/// Opens a connection for the preview proxy, returning the host-key
|
||||
/// fingerprint when this was the first contact.
|
||||
pub(crate) async fn connect_handle(
|
||||
target: &TargetRow,
|
||||
private_key: &str,
|
||||
) -> Result<Handle<HostKey>, String> {
|
||||
let (handle, _fingerprint) = connect(target, private_key).await?;
|
||||
Ok(handle)
|
||||
) -> Result<(Handle<HostKey>, Option<String>), String> {
|
||||
connect(target, private_key).await
|
||||
}
|
||||
|
||||
/// Pins a learned host key after a successful login. A later connection
|
||||
/// then refuses a different key.
|
||||
pub(crate) fn remember_host_key(state: &Shared, target: &TargetRow, learned: Option<String>) {
|
||||
if target.host_fingerprint.is_none()
|
||||
&& let Some(fingerprint) = learned
|
||||
{
|
||||
let _ = state.db.conn().execute(
|
||||
"UPDATE sandbox_targets SET host_fingerprint = ?1 WHERE id = ?2",
|
||||
rusqlite::params![fingerprint, target.id],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn connect(
|
||||
@@ -95,7 +108,14 @@ async fn connect(
|
||||
|
||||
/// Attaches a browser socket to an interactive shell in the room's
|
||||
/// sandbox.
|
||||
pub async fn terminal(socket: WebSocket, state: Shared, workspace: String, target: TargetRow) {
|
||||
pub async fn terminal(
|
||||
socket: WebSocket,
|
||||
state: Shared,
|
||||
room: String,
|
||||
account: String,
|
||||
workspace: String,
|
||||
target: TargetRow,
|
||||
) {
|
||||
let (mut sink, mut source) = socket.split();
|
||||
let key = match state.secrets.open_str(&target.private_key_ciphertext) {
|
||||
Ok(key) => key,
|
||||
@@ -125,14 +145,7 @@ pub async fn terminal(socket: WebSocket, state: Shared, workspace: String, targe
|
||||
};
|
||||
// Learn the host key once the login succeeded, not before: a
|
||||
// server that refuses us should not become known.
|
||||
if target.host_fingerprint.is_none()
|
||||
&& let Some(fingerprint) = learned
|
||||
{
|
||||
let _ = state.db.conn().execute(
|
||||
"UPDATE sandbox_targets SET host_fingerprint = ?1 WHERE id = ?2",
|
||||
rusqlite::params![fingerprint, target.id],
|
||||
);
|
||||
}
|
||||
remember_host_key(&state, &target, learned);
|
||||
let mut channel = match connection.channel_open_session().await {
|
||||
Ok(channel) => channel,
|
||||
Err(err) => {
|
||||
@@ -160,8 +173,14 @@ pub async fn terminal(socket: WebSocket, state: Shared, workspace: String, targe
|
||||
json!({ "type": "ready" }).to_string().into(),
|
||||
))
|
||||
.await;
|
||||
let mut access = tokio::time::interval(std::time::Duration::from_secs(2));
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = access.tick() => {
|
||||
if crate::api::rooms::member_of(&state, &room, &account).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
message = channel.wait() => {
|
||||
match message {
|
||||
Some(ChannelMsg::Data { data }) => {
|
||||
|
||||
Reference in new issue
Block a user