4 Commits
21 changed files with 1183 additions and 83 deletions

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
# OpenSSF Scorecard: grades the repository's security practices and
# publishes the result (https://scorecard.dev).
#
# Runs only in libracoder/kiri: copies of this repository skip it.
name: Scorecard
on:
push:
branches: [main]
schedule:
- cron: "41 5 * * 1"
branch_protection_rule:
workflow_dispatch:
permissions: {}
jobs:
analysis:
name: Scorecard
if: github.repository == 'libracoder/kiri'
runs-on: ubuntu-latest
permissions:
contents: read
# Upload the results to code scanning.
security-events: write
# Publish the results to the public Scorecard API.
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ossf/scorecard-action@fa7117db83c52d787ae5a89f350999701505d78e # v2.5.0
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: scorecard-results
path: results.sarif
retention-days: 5
- uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
with:
sarif_file: results.sarif
+75
View File
@@ -0,0 +1,75 @@
# Security checks for every pull request and for main.
#
# Each job runs only in libracoder/kiri: copies of this repository skip them.
name: Security
on:
pull_request:
push:
branches: [main]
schedule:
# Weekly, so new RustSec advisories show up between changes.
- cron: "17 6 * * 1"
workflow_dispatch:
permissions: {}
concurrency:
group: security-${{ github.ref }}
cancel-in-progress: true
jobs:
cargo-deny:
name: cargo-deny (${{ matrix.checks }})
if: github.repository == 'libracoder/kiri'
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
checks:
- advisories
- bans licenses sources
# A new advisory against an existing dependency shouldn't block
# unrelated pull requests; the weekly run reports it.
continue-on-error: ${{ matrix.checks == 'advisories' && github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1
with:
command: check ${{ matrix.checks }}
shellcheck:
name: ShellCheck
if: github.repository == 'libracoder/kiri'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check shell scripts
run: |
git ls-files -z '*.sh' \
'contrib/linux/deb/postinst' 'contrib/linux/deb/postrm' 'contrib/linux/deb/prerm' \
'packaging/linux/deb/postinst' 'packaging/linux/deb/postrm' 'packaging/linux/deb/prerm' \
'packaging/linux/docker-wrapper' 'contrib/wsl/kiri-linux/kiri-start' \
| xargs -0 shellcheck --severity=error
zizmor:
name: zizmor (workflow audit)
if: github.repository == 'libracoder/kiri'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
with:
advanced-security: false
+8
View File
@@ -62,7 +62,9 @@ pub fn serve(mut conn: File, paths: &Paths) -> io::Result<()> {
// On a Linux host, SIGTERM or SIGINT stops the agent as Shutdown does.
let term = if host_process { Some(term_signals()?) } else { None };
let mut bridges = Bridges::default();
// In the VM, lookups the gateway's resolver fails go through the host.
let mut dns = super::dns::Dns::default();
dns.relay = !host_process;
let forward = super::relay::listen()?;
// host.docker.internal's relay to the Mac (VM only). A Linux host maps
// that name to the bridge gateway and redirects nothing here, so the
@@ -130,6 +132,10 @@ pub fn serve(mut conn: File, paths: &Paths) -> io::Result<()> {
let wait = TTY_HUP_WAIT.as_millis() as i32;
timeout = if timeout < 0 { wait } else { timeout.min(wait) };
}
let wait = dns.timeout_ms();
if wait >= 0 {
timeout = if timeout < 0 { wait } else { timeout.min(wait) };
}
// SAFETY: `fds` is a valid array of pollfd of the given length.
let n = unsafe { libc::poll(fds.as_mut_ptr(), fds.len() as libc::nfds_t, timeout) };
if n < 0 {
@@ -157,6 +163,8 @@ pub fn serve(mut conn: File, paths: &Paths) -> io::Result<()> {
}
}
dns.on_timer();
// Output and input first, so a process's last words go out before its exit.
for pfd in &fds[3..] {
if pfd.revents == 0 {
+24 -7
View File
@@ -257,7 +257,7 @@ pub fn spawn(spec: &RunSpec<'_>, paths: &Paths, net: NetCtx<'_>) -> io::Result<P
prepared.host = HostApplied { rlimits: host.rlimits.clone(), groups: host.groups.clone(), nodes };
// Small, short-lived files: kept in memory (/run is tmpfs), not on the data disk.
let etc_dir = PathBuf::from("/run/kiri").join(spec.id);
let embedded_dns = embedded_dns(spec, net.upstream_dns);
let embedded_dns = embedded_dns(spec, net.upstream_dns, net.dns.relay);
prepared.etc_files = write_etc_files(spec, &etc_dir, net.upstream_dns, embedded_dns).map_err(cleanup)?;
prepared.mounts = parse_mounts(spec.mounts).map_err(cleanup)?;
let bridged = !spec.net.bridge.is_empty() && spec.flags & (run_flags::NET_HOST | run_flags::NET_NONE) == 0 && prepared.net_join.is_none();
@@ -736,16 +736,18 @@ fn write_etc_files(spec: &RunSpec<'_>, base: &std::path::Path, upstream: &[[u8;
/// `--dns-search` and `--dns-option` apply either way.
/// Whether the container's DNS goes to the agent's resolver (127.0.0.11):
/// on a user network, as Docker's embedded DNS; and on the default bridge
/// when the host's resolver is one of its own addresses (net::local_resolver),
/// unless the container names its own servers (`--dns`).
fn embedded_dns(spec: &RunSpec<'_>, upstream: &[[u8; 4]]) -> bool {
/// when the host's resolver is one of its own addresses (net::local_resolver)
/// or, in the VM (`relay`), so that lookups the Mac's gateway resolver fails
/// can go through the host (dns.rs), unless the container names its own
/// servers (`--dns`).
fn embedded_dns(spec: &RunSpec<'_>, upstream: &[[u8; 4]], relay: bool) -> bool {
if spec.flags & run_flags::DNS_GATEWAY != 0 {
return true;
}
let bridged = !spec.net.bridge.is_empty()
&& spec.flags & (run_flags::NET_HOST | run_flags::NET_NONE) == 0
&& net_opts::values(spec.net.opts, net_opts::NETNS).next().is_none();
bridged && net_opts::values(spec.net.opts, net_opts::NAMESERVER).next().is_none() && net::local_resolver(upstream)
bridged && net_opts::values(spec.net.opts, net_opts::NAMESERVER).next().is_none() && (relay || net::local_resolver(upstream))
}
fn resolv_conf(spec: &RunSpec<'_>, upstream: &[[u8; 4]], embedded_dns: bool) -> String {
@@ -1380,8 +1382,23 @@ mod tests {
encode_run(&mut buf, "c1", &[], &["sh"], &[], "/", "", "c1", 0, net, &[], &Limits::default(), 0, &[] as &[&str]);
let Ok(Msg::Run(spec)) = decode(&buf) else { panic!() };
// TEST-NET-3: no machine running the tests has it.
assert!(!super::embedded_dns(&spec, &[[203, 0, 113, 53]]), "a resolver elsewhere is asked directly");
assert!(!super::embedded_dns(&spec, &[]), "no resolver: the public fallback, not the agent");
assert!(!super::embedded_dns(&spec, &[[203, 0, 113, 53]], false), "a resolver elsewhere is asked directly");
assert!(!super::embedded_dns(&spec, &[], false), "no resolver: the public fallback, not the agent");
}
#[test]
fn in_the_vm_the_default_bridge_goes_through_the_agent() {
let spec_with = |flags: u32, opts: &[&str], f: &dyn Fn(&kiri_proto::RunSpec<'_>)| {
let mut buf = Vec::new();
let net = Net { bridge: "kiri0", ip: [172, 17, 0, 2], prefix: 16, gateway: [172, 17, 0, 1], extra_hosts: &[], dns_names: &[], opts };
encode_run(&mut buf, "c1", &[], &["sh"], &[], "/", "", "c1", flags, net, &[], &Limits::default(), 0, &[] as &[&str]);
let Ok(Msg::Run(spec)) = decode(&buf) else { panic!() };
f(&spec);
};
let gateway = [[192, 168, 64, 1]];
spec_with(0, &[], &|s| assert!(super::embedded_dns(s, &gateway, true), "so a refused gateway can fall back to the host"));
spec_with(0, &["nameserver=8.8.8.8"], &|s| assert!(!super::embedded_dns(s, &gateway, true), "--dns servers are asked directly"));
spec_with(run_flags::NET_HOST, &[], &|s| assert!(!super::embedded_dns(s, &gateway, true), "host networking keeps the VM's resolv.conf"));
}
#[test]
+263 -18
View File
@@ -6,6 +6,15 @@
//! forwarded to the VM's upstream resolver (or the container's own `--dns`
//! servers) and the answer relayed back. The 127.0.0.11 socket is opened in
//! the container's namespace by this agent, so no process runs in there.
//!
//! In the VM the upstream is the Mac's resolver for the NAT network, at its
//! gateway (192.168.64.1). macOS doesn't always answer there: after a
//! network change, sleep or a VPN, lookups are refused or go unanswered
//! while the Mac itself resolves fine. So a lookup the gateway refuses, or
//! leaves unanswered for `FALLBACK_AFTER`, is asked again through the Kiri
//! daemon on the Mac, over vsock, which asks the Mac's own resolvers
//! (crates/kiri/src/daemon/dns.rs). A container's own `--dns` servers are
//! never second-guessed.
use std::collections::HashMap;
use std::io::{self, Read};
@@ -24,6 +33,12 @@ const FORWARD_TIMEOUT: Duration = Duration::from_secs(5);
/// At most this many forwarded queries in flight (each has its own socket);
/// more are dropped, and the client asks again.
const MAX_PENDING: usize = 256;
/// A lookup the VM's resolver hasn't answered within this goes through the
/// host (VM only). Gateway answers take milliseconds; a slow recursive one
/// that loses the race is simply replaced by the host's.
const FALLBACK_AFTER: Duration = Duration::from_secs(1);
/// Largest reply the host relay may send (a DNS over TCP frame's limit).
const MAX_RELAYED: usize = 2 + 65_535;
/// Docker's embedded DNS address, inside each container.
pub const EMBEDDED: [u8; 4] = [127, 0, 0, 11];
@@ -42,7 +57,8 @@ struct Pending {
/// Its own socket, connected to the resolver: a fresh source port for
/// every query, as Docker's embedded DNS does, so one lost or blocked
/// flow doesn't take the resolver away from every later query, and an
/// answer has to guess the port as well as the ID.
/// answer has to guess the port as well as the ID. Once the query goes
/// through the host, the vsock stream to it instead.
sock: OwnedFd,
/// The ID it went out with.
our: u16,
@@ -52,6 +68,13 @@ struct Pending {
id: u16,
question: Vec<u8>,
sent: Instant,
/// The query as sent (with `our` ID), to send again through the host.
query: Vec<u8>,
/// It may still go through the host: in the VM, asked of the VM's own
/// resolver (not `--dns` servers), and not tried there yet.
may_relay: bool,
/// Sent through the host: the reply's bytes so far, `u16 len | reply`.
relayed: Option<Vec<u8>>,
}
/// One name's IPv6 addresses, each with its container's IPv4 address.
@@ -68,6 +91,9 @@ pub struct Dns {
/// Container address → its `--dns` servers, used instead of the VM's.
clients: HashMap<[u8; 4], Vec<[u8; 4]>>,
pending: Vec<Pending>,
/// Lookups the VM's resolver fails go through the host (in the VM; a
/// Linux host's agent asks the host's resolvers itself).
pub relay: bool,
}
fn udp_socket() -> io::Result<OwnedFd> {
@@ -220,21 +246,27 @@ impl Dns {
pub fn on_readable(&mut self, fd: RawFd, upstream: &[[u8; 4]]) {
let mut buf = [0u8; 1500];
if let Some(at) = self.pending.iter().position(|p| p.sock.as_raw_fd() == fd) {
if self.pending[at].relayed.is_some() {
self.read_relayed(at);
return;
}
// A forwarded answer: hand it back to whoever asked.
loop {
// SAFETY: receiving into a buffer we own.
let n = unsafe { libc::recv(fd, buf.as_mut_ptr().cast(), buf.len(), 0) };
if n < 0 && io::Error::last_os_error().raw_os_error() == Some(libc::ECONNREFUSED) {
// Nothing listens at the resolver: ask the host now
// rather than wait for the client to give up.
self.relay(at);
break;
}
if n < 12 {
break;
}
let msg = &mut buf[..n as usize];
let p = &self.pending[at];
if u16::from_be_bytes([msg[0], msg[1]]) == p.our && response_matches(msg, p) {
let p = self.pending.swap_remove(at);
msg[0..2].copy_from_slice(&p.id.to_be_bytes());
if let Some(s) = self.servers.iter().find(|s| s.sock.as_raw_fd() == p.server) {
send_to(s.sock.as_raw_fd(), msg, &p.client);
}
self.answered(at, msg);
break;
}
}
@@ -309,31 +341,169 @@ impl Dns {
let now = Instant::now();
self.pending.retain(|p| now.duration_since(p.sent) < FORWARD_TIMEOUT);
let key = self.servers[server].container.map_or(client.sin_addr.s_addr.to_ne_bytes(), |(_, owner)| owner);
let own = self.clients.get(&key).and_then(|v| v.first());
let Some(dest) = own.or(upstream.first()).copied() else { return };
let own = self.clients.get(&key).and_then(|v| v.first()).copied();
if self.pending.len() >= MAX_PENDING {
return;
}
let Some((_, _, end)) = parse_question(q) else {
return;
};
let Ok(sock) = udp_socket() else { return };
let to = sockaddr(dest, 53);
// Connected, so it only receives datagrams from this resolver.
// SAFETY: connecting to a valid sockaddr_in.
if unsafe { libc::connect(sock.as_raw_fd(), (&to as *const libc::sockaddr_in).cast(), std::mem::size_of::<libc::sockaddr_in>() as u32) } != 0 {
return;
}
let Some(our) = random_id() else { return };
let mut msg = q.to_vec();
let id = u16::from_be_bytes([msg[0], msg[1]]);
msg[0..2].copy_from_slice(&our.to_be_bytes());
// SAFETY: sending a buffer we own on a connected socket.
if unsafe { libc::send(sock.as_raw_fd(), msg.as_ptr().cast(), msg.len(), 0) } < 0 {
let may_relay = self.relay && own.is_none();
let dest = own.or(upstream.first().copied());
// No resolver yet, or it can't be reached: the host, if allowed.
let (sock, relayed) = match dest.and_then(|d| ask(d, &msg)) {
Some(s) => (s, false),
None if may_relay => match relay_stream(&msg) {
Some(s) => (s, true),
None => return,
},
None => return,
};
let p = Pending {
sock,
our,
server: self.servers[server].sock.as_raw_fd(),
client,
id,
question: q[12..end].to_vec(),
sent: now,
query: msg,
may_relay: may_relay && !relayed,
relayed: relayed.then(Vec::new),
};
self.pending.push(p);
}
/// Hands a matching answer to whoever asked, and forgets the query.
fn answered(&mut self, at: usize, msg: &mut [u8]) {
let p = self.pending.swap_remove(at);
msg[0..2].copy_from_slice(&p.id.to_be_bytes());
if let Some(s) = self.servers.iter().find(|s| s.sock.as_raw_fd() == p.server) {
send_to(s.sock.as_raw_fd(), msg, &p.client);
}
}
/// Sends pending query `at` again, through the host, once.
fn relay(&mut self, at: usize) {
let p = &mut self.pending[at];
if !p.may_relay {
return;
}
self.pending.push(Pending { sock, our, server: self.servers[server].sock.as_raw_fd(), client, id, question: q[12..end].to_vec(), sent: now });
p.may_relay = false;
if let Some(stream) = relay_stream(&p.query) {
p.sock = stream;
p.relayed = Some(Vec::new());
p.sent = Instant::now();
}
}
/// Reads the host's reply to query `at` as it arrives.
fn read_relayed(&mut self, at: usize) {
let fd = self.pending[at].sock.as_raw_fd();
let mut buf = [0u8; 4096];
let mut eof = false;
loop {
// SAFETY: reading into a buffer we own.
let n = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), buf.len()) };
if n > 0 {
let got = self.pending[at].relayed.get_or_insert_with(Vec::new);
got.extend_from_slice(&buf[..n as usize]);
if got.len() > MAX_RELAYED {
eof = true;
break;
}
continue;
}
if n < 0 && io::Error::last_os_error().kind() == io::ErrorKind::WouldBlock {
break;
}
eof = true;
break;
}
let got = self.pending[at].relayed.take().unwrap_or_default();
match framed_reply(&got) {
Some(reply) => {
let mut msg = reply.to_vec();
let p = &self.pending[at];
if msg.len() >= 12 && u16::from_be_bytes([msg[0], msg[1]]) == p.our && response_matches(&msg, p) {
self.answered(at, &mut msg);
} else {
self.pending.swap_remove(at);
}
}
// Gone before a whole reply: the client asks again.
None if eof => {
self.pending.swap_remove(at);
}
None => self.pending[at].relayed = Some(got),
}
}
/// Sends lookups the VM's resolver has left unanswered too long
/// through the host. Called on every turn of the agent's loop.
pub fn on_timer(&mut self) {
let now = Instant::now();
for at in 0..self.pending.len() {
let p = &self.pending[at];
if p.may_relay && now.duration_since(p.sent) >= FALLBACK_AFTER {
self.relay(at);
}
}
}
/// Milliseconds until `on_timer` has something to do; -1 for never.
pub fn timeout_ms(&self) -> i32 {
let now = Instant::now();
self.pending
.iter()
.filter(|p| p.may_relay)
.map(|p| FALLBACK_AFTER.saturating_sub(now.duration_since(p.sent)).as_millis().min(i32::MAX as u128) as i32)
.min()
.unwrap_or(-1)
}
}
/// A UDP socket connected to `dest`:53 with `msg` sent on it, or None if
/// it couldn't be sent (no route, the network down).
fn ask(dest: [u8; 4], msg: &[u8]) -> Option<OwnedFd> {
let sock = udp_socket().ok()?;
let to = sockaddr(dest, 53);
// Connected, so it only receives datagrams from this resolver.
// SAFETY: connecting to a valid sockaddr_in.
if unsafe { libc::connect(sock.as_raw_fd(), (&to as *const libc::sockaddr_in).cast(), std::mem::size_of::<libc::sockaddr_in>() as u32) } != 0 {
return None;
}
// SAFETY: sending a buffer we own on a connected socket.
if unsafe { libc::send(sock.as_raw_fd(), msg.as_ptr().cast(), msg.len(), 0) } < 0 {
return None;
}
Some(sock)
}
/// A stream to the host's DNS relay with `msg` sent on it, non-blocking
/// for the reply.
fn relay_stream(msg: &[u8]) -> Option<OwnedFd> {
let stream = super::transport::dial(kiri_proto::DNS_RELAY_PORT).ok()?;
let mut frame = Vec::with_capacity(2 + msg.len());
frame.extend_from_slice(&u16::try_from(msg.len()).ok()?.to_be_bytes());
frame.extend_from_slice(msg);
// A few hundred bytes on a fresh stream: one write, never short.
// SAFETY: writing a buffer we own to a socket we own.
if unsafe { libc::write(stream.as_raw_fd(), frame.as_ptr().cast(), frame.len()) } != frame.len() as isize {
return None;
}
sys::set_nonblocking(stream.as_raw_fd()).ok()?;
Some(stream)
}
/// The reply in `u16 len | reply`, once all of it is there.
fn framed_reply(got: &[u8]) -> Option<&[u8]> {
let len = u16::from_be_bytes([*got.first()?, *got.get(1)?]) as usize;
got.get(2..2 + len)
}
/// A UDP socket bound to `ip`:53.
@@ -560,9 +730,84 @@ mod tests {
id: 7,
question: b"\x03www\x07example\x03com\x00\x00\x01\x00\x01".to_vec(),
sent: Instant::now(),
query: Vec::new(),
may_relay: false,
relayed: None,
}
}
#[test]
fn a_relayed_reply_is_whole_only_once_its_length_is_there() {
use super::framed_reply;
assert_eq!(framed_reply(&[]), None);
assert_eq!(framed_reply(&[0]), None);
assert_eq!(framed_reply(&[0, 3, 1, 2]), None);
assert_eq!(framed_reply(&[0, 3, 1, 2, 3]), Some(&[1u8, 2, 3][..]));
assert_eq!(framed_reply(&[0, 0]), Some(&[][..]));
}
#[test]
fn only_lookups_the_vm_resolver_may_miss_wait_for_the_host() {
let mut dns = Dns::default();
assert_eq!(dns.timeout_ms(), -1, "nothing pending");
dns.pending.push(pending());
assert_eq!(dns.timeout_ms(), -1, "--dns servers are not second-guessed");
let mut p = pending();
p.may_relay = true;
dns.pending.push(p);
let t = dns.timeout_ms();
assert!((0..=1000).contains(&t), "{t}");
// Past the wait it is tried through the host once, whatever comes of it.
dns.pending[1].sent = Instant::now() - super::FALLBACK_AFTER;
assert_eq!(dns.timeout_ms(), 0);
dns.on_timer();
assert!(!dns.pending[1].may_relay);
assert_eq!(dns.timeout_ms(), -1);
}
#[test]
fn the_hosts_reply_goes_back_to_whoever_asked() {
use std::net::UdpSocket;
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
let client = UdpSocket::bind("127.0.0.1:0").unwrap();
client.set_read_timeout(Some(std::time::Duration::from_secs(2))).unwrap();
let std::net::SocketAddr::V4(addr) = client.local_addr().unwrap() else { panic!() };
let mut dns = Dns::default();
dns.servers.push(Server { bridges: vec!["kiri1".into()], sock: udp_socket().unwrap(), container: None });
let mut fds = [0; 2];
// SAFETY: `fds` has room for the pair.
assert_eq!(unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM | libc::SOCK_NONBLOCK, 0, fds.as_mut_ptr()) }, 0);
// SAFETY: fresh descriptors from socketpair.
let (ours, host) = unsafe { (OwnedFd::from_raw_fd(fds[0]), OwnedFd::from_raw_fd(fds[1])) };
let mut p = pending();
p.sock = ours;
p.server = dns.servers[0].sock.as_raw_fd();
p.client = super::sockaddr(addr.ip().octets(), addr.port());
p.relayed = Some(Vec::new());
let question = p.question.clone();
dns.pending.push(p);
let mut reply = vec![0, 1, 0x81, 0x80, 0, 1, 0, 0, 0, 0, 0, 0];
reply.extend_from_slice(&question);
let mut frame = (reply.len() as u16).to_be_bytes().to_vec();
frame.extend_from_slice(&reply);
let send = |b: &[u8]| {
// SAFETY: writing a buffer we own to our end of the pair.
assert_eq!(unsafe { libc::write(host.as_raw_fd(), b.as_ptr().cast(), b.len()) }, b.len() as isize)
};
// Half a reply waits for the rest.
send(&frame[..5]);
let fd = dns.pending[0].sock.as_raw_fd();
dns.on_readable(fd, &[]);
assert_eq!(dns.pending.len(), 1);
send(&frame[5..]);
dns.on_readable(fd, &[]);
assert!(dns.pending.is_empty());
let mut buf = [0u8; 512];
let n = client.recv(&mut buf).unwrap();
assert_eq!(&buf[..2], &[0, 7], "the client's own ID");
assert_eq!(&buf[2..n], &reply[2..]);
}
#[test]
fn response_must_match_the_whole_question() {
let p = pending();
+5
View File
@@ -167,6 +167,11 @@ pub enum Msg<'a> {
/// vsock port of the guest's copy service: one connection per copy.
pub const COPY_PORT: u32 = 1028;
/// vsock port of the host's DNS relay (VM only). The agent sends a lookup
/// the VM's gateway resolver didn't answer as `u16 len | query`, as DNS over
/// TCP frames it, and gets `u16 len | reply` back: one lookup per connection.
pub const DNS_RELAY_PORT: u32 = 1037;
pub mod copy_op {
pub const IN: u8 = 1;
pub const OUT: u8 = 2;
+2 -1
View File
@@ -257,7 +257,8 @@ fn send_report(text: &str) -> io::Result<String> {
}
text = format!("{MARK}{}", &text[cut..]);
};
let (status, v) = crate::share::post_report(&body)?;
// A report the person sends: signed in, so it can be answered.
let (status, v) = crate::share::post_report(&body, true)?;
let why = v["error"].as_str().map(|e| format!(": {e}")).unwrap_or_default();
match status {
200 | 201 => v["id"]
+21
View File
@@ -46,6 +46,11 @@ mod builds;
#[cfg(windows)]
#[path = "../../kiri/src/buildwith.rs"]
mod buildwith;
// Kiri's program moved or deleted from where it started: the Mac's and
// Linux's own crates/kiri/src/appwatch.rs.
#[cfg(windows)]
#[path = "../../kiri/src/appwatch.rs"]
mod appwatch;
// An image's Layers and Security tabs, asked of the engine in WSL.
#[cfg(windows)]
mod scan;
@@ -139,6 +144,22 @@ fn main() -> std::process::ExitCode {
serve::log(&format!("dns on 127.0.0.1:53: {e}"));
}
engine::start(engine::Env { distro: cfg.distro.clone(), pipe: cfg.pipe.clone() });
// Its folder renamed, moved or deleted around it (Windows won't delete
// a running program itself): docker build handed back as it was before
// Kiri took it, the choice kept for when Kiri runs again, and Kiri quits.
appwatch::watch(|exe| {
serve::log(&format!("{} is gone from where Kiri started; handing docker build back and quitting", exe.display()));
if let Err(e) = buildwith::places().and_then(|p| p.give_back()) {
serve::log(&format!("docker build not handed back: {e}"));
}
app::Handle.run(|_| {
// SAFETY: ends the window's message loop; run on its thread.
unsafe { windows::Win32::UI::WindowsAndMessaging::PostQuitMessage(0) }
});
// No window to quit (it never opened): quit from here.
std::thread::sleep(std::time::Duration::from_secs(5));
std::process::exit(0);
});
// The engine starts when the page says `ready`, and with the window
// hidden (--background, as from the login shortcut) no page loads: after
// kiri-win restarted, docker got no answer until Start was pressed.
+79
View File
@@ -0,0 +1,79 @@
//! Noticing that Kiri's own program is gone from where it started: the app
//! dragged to the Trash, a development build's folder deleted, or (on
//! Windows, where a running program can't be deleted) its folder renamed
//! or moved. What's left running can't do its job any more (on the Mac the
//! VM's kernel went with the app), yet it still holds what "Build with
//! Kiri" took, buildx's builder for every context, and every `docker
//! build` fails on it. The daemon (daemon/mod.rs) and kiri-win both watch,
//! hand the builder back and stop.
//!
//! The same file serves the Mac and Linux (crates/kiri) and Windows
//! (kiri-win includes it).
use std::path::{Path, PathBuf};
use std::time::Duration;
/// How often the program's path is looked at.
pub const EVERY: Duration = Duration::from_secs(30);
/// Calls `on_gone` once, on its own thread, when the program this process
/// started from has been missing from its path on two looks in a row (an
/// update swaps the app in well under that). The path is the one it started
/// with: on a Linux host a package upgrade puts a new file there, which
/// counts as still there.
pub fn watch(on_gone: impl FnOnce(&Path) + Send + 'static) {
if let Ok(exe) = std::env::current_exe() {
watch_path(exe, EVERY, on_gone);
}
}
fn watch_path(path: PathBuf, every: Duration, on_gone: impl FnOnce(&Path) + Send + 'static) {
let _ = std::thread::Builder::new().name("kiri-app-watch".into()).spawn(move || {
let mut missing = 0;
while missing < 2 {
std::thread::sleep(every);
missing = if path.exists() { 0 } else { missing + 1 };
}
on_gone(&path);
});
}
#[cfg(test)]
mod tests {
use std::sync::mpsc;
use std::time::Duration;
#[test]
fn a_program_moved_away_is_noticed_once_and_one_put_back_is_not() {
let dir = std::env::temp_dir().join(format!("kiri-appwatch-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(dir.join("app")).unwrap();
let exe = dir.join("app").join("kiri");
std::fs::write(&exe, b"program").unwrap();
let (tx, rx) = mpsc::channel();
super::watch_path(exe.clone(), Duration::from_millis(20), move |p| tx.send(p.to_owned()).unwrap());
// There all along: nothing.
assert!(rx.recv_timeout(Duration::from_millis(150)).is_err());
// Its folder renamed, as Windows allows for a running program.
std::fs::rename(dir.join("app"), dir.join("moved")).unwrap();
assert_eq!(rx.recv_timeout(Duration::from_secs(5)).unwrap(), exe);
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn a_brief_swap_is_not_taken_for_gone() {
let dir = std::env::temp_dir().join(format!("kiri-appwatch-swap-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let exe = dir.join("kiri");
std::fs::write(&exe, b"old").unwrap();
let (tx, rx) = mpsc::channel();
super::watch_path(exe.clone(), Duration::from_millis(400), move |p| tx.send(p.to_owned()).unwrap());
// Gone for the first look (at 400 ms), back before the second (800 ms).
std::fs::remove_file(&exe).unwrap();
std::thread::sleep(Duration::from_millis(600));
std::fs::write(&exe, b"new").unwrap();
assert!(rx.recv_timeout(Duration::from_millis(1500)).is_err());
std::fs::remove_dir_all(&dir).unwrap();
}
}
+24 -2
View File
@@ -209,8 +209,9 @@ impl Places {
}
/// Build with Docker: puts back what `take` kept, where it is still
/// as Kiri left it.
fn give_back(&self) -> io::Result<()> {
/// as Kiri left it. Also when Kiri's program is gone (appwatch.rs):
/// the choice itself is kept, so `apply` takes it again later.
pub fn give_back(&self) -> io::Result<()> {
let mut s = self.state();
let before = s["before"].take();
if before.is_null() {
@@ -493,6 +494,27 @@ mod tests {
assert!(p.instance("kiri").is_file());
}
#[test]
fn a_second_kiri_whose_app_is_gone_hands_builds_back_to_the_first() {
let d = scratch("second");
let main = places(&d);
builder(&main);
main.choose(With::Kiri).unwrap();
// A development build of Kiri, its own state and builder, takes them.
let dev = Places { state: d.join(".kiri-layers/build.json"), builder: "kiri-layers-build".into(), context: "kiri-layers".into(), ..places(&d) };
let i = json!({"Name": "kiri-layers-build", "Driver": "docker-container", "Nodes": [{"Name": "kiri-layers-build0", "Endpoint": "kiri-layers"}], "Dynamic": false});
write_bytes(&dev.instance("kiri-layers-build"), i.to_string().as_bytes()).unwrap();
dev.choose(With::Kiri).unwrap();
assert!(dev.taken() && !main.taken());
// Its app deleted: the daemon hands back (daemon/mod.rs).
dev.give_back().unwrap();
assert!(main.taken(), "builds go to the first Kiri again");
assert_eq!(dev.saved(), Some(With::Kiri), "the choice stays");
// Taken up again, it takes them again.
dev.apply(None).unwrap();
assert!(dev.taken());
}
#[test]
fn switching_back_restores_exactly() {
let d = scratch("restore");
+215 -2
View File
@@ -3,9 +3,16 @@
//! picks the container from the Host header. macOS sends these lookups here
//! because of `/etc/resolver/kiri.local`, which `kiri setup` installs once
//! (it needs an administrator). Anything else is refused.
//!
//! Also the relay for container lookups the VM's gateway resolver fails
//! (`serve_relay`): the guest agent sends them here over vsock, and they're
//! asked of the Mac's own resolvers.
use std::io;
use std::net::UdpSocket;
use std::io::{self, Read, Write};
use std::net::{IpAddr, SocketAddr, UdpSocket};
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
/// The resolver file's port; unprivileged, so the daemon needs no root.
pub const PORT: u16 = 53535;
@@ -73,9 +80,165 @@ fn answer(q: &[u8]) -> Option<Vec<u8>> {
Some(r)
}
/// How long one resolver gets to answer a relayed lookup.
const RELAY_TRY: Duration = Duration::from_millis(1500);
/// All the resolvers together: the agent stops waiting at five seconds.
const RELAY_BUDGET: Duration = Duration::from_millis(3500);
/// One lookup from the guest agent: `u16 len | query` in, `u16 len | reply`
/// out (kiri_proto::DNS_RELAY_PORT). The agent sends here only what the
/// VM's gateway resolver refused or left unanswered, so this is the path
/// while macOS's resolver for the VM network is down.
pub fn serve_relay(stream: kiri_vmm::VsockStream) {
let _ = std::thread::Builder::new().name("kiri-dns-relay".into()).spawn(move || {
let Ok(fd) = stream.fd.try_clone() else { return };
let mut conn = std::fs::File::from(fd);
let mut len = [0u8; 2];
if conn.read_exact(&mut len).is_err() {
return;
}
let mut query = vec![0u8; u16::from_be_bytes(len) as usize];
if query.len() < 12 || conn.read_exact(&mut query).is_err() {
return;
}
static SAID: AtomicBool = AtomicBool::new(false);
if !SAID.swap(true, Ordering::Relaxed) {
crate::diag::warn!("the VM's DNS at its gateway did not answer; container lookups go through the Mac");
}
let name = question_name(&query).unwrap_or_default();
let servers = mac_resolvers(&name, Path::new("/etc/resolv.conf"), Path::new("/etc/resolver"));
let reply = relay_query(&query, &servers).unwrap_or_else(|| servfail(&query));
let mut out = Vec::with_capacity(2 + reply.len());
out.extend_from_slice(&(reply.len().min(u16::MAX as usize) as u16).to_be_bytes());
out.extend_from_slice(&reply[..reply.len().min(u16::MAX as usize)]);
let _ = conn.write_all(&out);
drop(stream);
});
}
/// The first answer to `query` from `servers`, tried in order.
fn relay_query(query: &[u8], servers: &[SocketAddr]) -> Option<Vec<u8>> {
let start = Instant::now();
let mut buf = vec![0u8; 65_535];
for server in servers {
let left = RELAY_BUDGET.checked_sub(start.elapsed())?;
let bind: SocketAddr = if server.is_ipv4() { ([0, 0, 0, 0], 0).into() } else { (std::net::Ipv6Addr::UNSPECIFIED, 0).into() };
let Ok(sock) = UdpSocket::bind(bind) else { continue };
if sock.connect(server).is_err() || sock.send(query).is_err() {
continue;
}
let until = Instant::now() + RELAY_TRY.min(left);
// Read past stray datagrams until this query's answer or the deadline.
while let Some(wait) = until.checked_duration_since(Instant::now()).filter(|d| !d.is_zero()) {
if sock.set_read_timeout(Some(wait)).is_err() {
break;
}
let Ok(n) = sock.recv(&mut buf) else { break };
let r = &buf[..n];
if n >= 12 && r[..2] == query[..2] && r[2] & 0x80 != 0 {
return Some(r.to_vec());
}
}
}
None
}
/// SERVFAIL for `query`: no resolver on the Mac answered either.
fn servfail(query: &[u8]) -> Vec<u8> {
let end = question_end(query).unwrap_or(12).min(query.len());
let mut r = query[..end].to_vec();
r[2] = 0x80 | (query[2] & 0x79); // QR, opcode and RD kept
r[3] = 0x80 | 2; // RA, SERVFAIL
r[6..12].fill(0);
if end > 12 {
r[5] = 1;
} else {
r[4..6].fill(0);
}
r
}
/// Offset just past the first question, if there is one.
fn question_end(q: &[u8]) -> Option<usize> {
if q.len() < 12 || u16::from_be_bytes([q[4], q[5]]) == 0 {
return None;
}
let mut i = 12;
loop {
let len = *q.get(i)? as usize;
if len == 0 {
break;
}
if len > 63 {
return None;
}
i += 1 + len;
}
(i + 5 <= q.len()).then_some(i + 5)
}
/// The first question's name, lowercase, without the trailing dot.
fn question_name(q: &[u8]) -> Option<String> {
question_end(q)?;
let mut i = 12;
let mut name = String::new();
loop {
let len = q[i] as usize;
if len == 0 {
return Some(name);
}
if !name.is_empty() {
name.push('.');
}
name.push_str(&String::from_utf8_lossy(&q[i + 1..i + 1 + len]).to_ascii_lowercase());
i += 1 + len;
}
}
/// Where the Mac would send a lookup for `name`: the servers of the
/// `/etc/resolver/<domain>` file with the longest domain that `name` is in
/// (VPNs and tools such as dnsmasq set these up), else `/etc/resolv.conf`'s,
/// which macOS keeps to its current primary DNS servers. Read on every
/// lookup, so network changes are followed. Kiri's own `kiri.local` file is
/// skipped: its server answers 127.0.0.1, the Mac's loopback, which means
/// nothing in a container.
fn mac_resolvers(name: &str, resolv_conf: &Path, resolver_dir: &Path) -> Vec<SocketAddr> {
let mut best: Option<(usize, Vec<SocketAddr>)> = None;
for entry in std::fs::read_dir(resolver_dir).into_iter().flatten().flatten() {
let Ok(text) = std::fs::read_to_string(entry.path()) else { continue };
let file = entry.file_name().to_string_lossy().to_ascii_lowercase();
let domain = text
.lines()
.find_map(|l| l.trim().strip_prefix("domain").map(|d| d.trim().trim_end_matches('.').to_ascii_lowercase()))
.filter(|d| !d.is_empty())
.unwrap_or(file);
if domain == SUFFIX {
continue;
}
let inside = name == domain || name.ends_with(&format!(".{domain}"));
if !inside || best.as_ref().is_some_and(|(len, _)| *len >= domain.len()) {
continue;
}
let servers = parse_servers(&text);
if !servers.is_empty() {
best = Some((domain.len(), servers));
}
}
best.map(|(_, s)| s).unwrap_or_else(|| parse_servers(&std::fs::read_to_string(resolv_conf).unwrap_or_default()))
}
/// `nameserver` lines (and a `port` line) of a resolv.conf-style file.
/// Link-local IPv6 servers, which need an interface named, are skipped.
fn parse_servers(text: &str) -> Vec<SocketAddr> {
let field = |key: &'static str| text.lines().filter_map(move |l| l.trim().strip_prefix(key).filter(|v| v.starts_with([' ', '\t'])).map(str::trim));
let port = field("port").find_map(|p| p.parse::<u16>().ok()).unwrap_or(53);
field("nameserver").filter_map(|ip| ip.parse::<IpAddr>().ok()).map(|ip| SocketAddr::new(ip, port)).collect()
}
#[cfg(test)]
mod tests {
use super::answer;
use std::net::UdpSocket;
fn query(name: &str, qtype: u16) -> Vec<u8> {
let mut q = vec![0x12, 0x34, 0x01, 0x00, 0, 1, 0, 0, 0, 0, 0, 0];
@@ -100,4 +263,54 @@ mod tests {
assert_eq!(answer(&query("notkiri.local", 1)).unwrap()[3], 5);
assert!(answer(&[0; 5]).is_none());
}
#[test]
fn relayed_lookups_go_where_the_mac_would_send_them() {
let dir = std::env::temp_dir().join(format!("kiri-dns-test-{}", std::process::id()));
let resolvers = dir.join("resolver");
std::fs::create_dir_all(&resolvers).unwrap();
let conf = dir.join("resolv.conf");
std::fs::write(&conf, "# macOS\nsearch home\nnameserver 192.168.1.1\nnameserver fe80::1%en0\nnameserver 2001:db8::53\n").unwrap();
std::fs::write(resolvers.join("corp.example"), "nameserver 10.0.0.53\n").unwrap();
std::fs::write(resolvers.join("eu.corp.example"), "nameserver 10.1.0.53\nport 5353\n").unwrap();
std::fs::write(resolvers.join("kiri.local"), "nameserver 127.0.0.1\nport 53535\n").unwrap();
let r = |name: &str| super::mac_resolvers(name, &conf, &resolvers).iter().map(ToString::to_string).collect::<Vec<_>>();
assert_eq!(r("registry-1.docker.io"), ["192.168.1.1:53", "[2001:db8::53]:53"]);
assert_eq!(r("git.corp.example"), ["10.0.0.53:53"]);
assert_eq!(r("corp.example"), ["10.0.0.53:53"]);
assert_eq!(r("db.eu.corp.example"), ["10.1.0.53:5353"], "the longest domain wins");
assert_eq!(r("notcorp.example"), ["192.168.1.1:53", "[2001:db8::53]:53"]);
assert_eq!(r("web.kiri.local"), ["192.168.1.1:53", "[2001:db8::53]:53"], "Kiri's own resolver is the Mac's loopback");
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn a_relayed_lookup_takes_the_first_resolver_that_answers() {
let up = UdpSocket::bind("127.0.0.1:0").unwrap();
let addr = up.local_addr().unwrap();
let resolver = std::thread::spawn(move || {
let mut buf = [0u8; 512];
let (n, from) = up.recv_from(&mut buf).unwrap();
// A stray datagram first, then the answer.
up.send_to(&[9; 12], from).unwrap();
buf[2] |= 0x80;
up.send_to(&buf[..n], from).unwrap();
});
// A closed port first: refused, then the next one is asked.
let closed = UdpSocket::bind("127.0.0.1:0").unwrap().local_addr().unwrap();
let q = query("registry-1.docker.io", 1);
let r = super::relay_query(&q, &[closed, addr]).expect("answered");
resolver.join().unwrap();
assert_eq!((&r[..2], r[2] & 0x80, &r[12..]), (&q[..2], 0x80, &q[12..]));
assert_eq!(super::question_name(&q).as_deref(), Some("registry-1.docker.io"));
}
#[test]
fn servfail_keeps_the_id_and_question() {
let q = query("example.com", 1);
let r = super::servfail(&q);
assert_eq!((&r[..2], r[2] & 0x80, r[3] & 0x0f), (&q[..2], 0x80, 2));
assert_eq!((&r[4..12], &r[12..]), (&[0, 1, 0, 0, 0, 0, 0, 0][..], &q[12..]));
assert_eq!(super::servfail(&[0x12, 0x34, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])[3], 0x82);
}
}
+5
View File
@@ -668,6 +668,11 @@ impl Engine {
if cfg!(target_os = "macos") {
vm.listen(super::ports::ENGINE_API_PORT, Box::new(super::ports::serve_engine_api))?;
}
// Container lookups the VM's gateway resolver fails, asked of the
// Mac's own (VM only: a Linux host's agent asks the host's itself).
if cfg!(target_os = "macos") {
vm.listen(kiri_proto::DNS_RELAY_PORT, Box::new(super::dns::serve_relay))?;
}
// Everything else on the guest's disk belongs to containers that are gone.
let keep: Vec<String> = self.lock().containers.keys().cloned().collect();
vm.retain(&keep)?;
+22
View File
@@ -151,6 +151,8 @@ pub fn run(_args: &[String]) -> io::Result<()> {
}
}
watch_own_app(engine.clone(), socket.clone());
let on_signal = engine.clone();
let sock = socket.clone();
std::thread::Builder::new().name("kiri-signals".into()).spawn(move || {
@@ -180,6 +182,26 @@ pub fn run(_args: &[String]) -> io::Result<()> {
Ok(())
}
/// When the app this daemon runs from is deleted (appwatch.rs): docker
/// build handed back (buildwith.rs: what was there before; the choice
/// stays, so the app taken up again takes it again), and the engine stops.
fn watch_own_app(engine: std::sync::Arc<engine::Engine>, socket: std::path::PathBuf) {
crate::appwatch::watch(move |exe| {
diag::error!("the app this engine runs from was deleted; stopping and handing docker build back", path = exe.display());
if let Err(e) = crate::buildwith::places().and_then(|p| p.give_back()) {
diag::warn!("docker build not handed back", error = e);
}
#[cfg(target_os = "macos")]
nfs::unmount();
let _ = std::fs::remove_file(&socket);
engine.shutdown();
std::thread::sleep(Duration::from_millis(50));
// 0: launchd restarts the engine on failure only, and there is
// nothing left to restart.
std::process::exit(0);
});
}
/// Serves container files over NFS and mounts them at ~/Kiri.
/// KIRI_NO_FINDER=1 skips the mount.
#[cfg(target_os = "macos")]
+284 -25
View File
@@ -1,8 +1,10 @@
//! Takes out of logs and reports what must not leave the Mac: the home
//! folder's path (it names the person), bearer and other `Authorization`
//! values, the values of token, password and secret keys in JSON, query
//! strings, `KEY=value` pairs and `--flag value`, passwords in URLs, private
//! keys, and tokens that say what they are (`ks_…`, `ghp_…`, `glpat-…`).
//! Takes out of logs and reports what must not leave the computer: the home
//! folder's path (it names the person), in every form Windows writes it,
//! bearer and other `Authorization` values, the values of token, password,
//! secret and cookie keys in JSON, query strings, `KEY=value`, `key: value`
//! and `key = value` pairs and `--flag value`, passwords in URLs, private
//! keys, JWTs, and tokens that say what they are (`ks_…`, `ghp_…`,
//! `sk_live_…`, `xoxb-…`, `sk-ant-…`).
//!
//! Patterns, not parsing: it runs over any text (log lines, panic
//! messages, macOS crash reports), so it errs towards taking out too much.
@@ -11,15 +13,17 @@ const MARK: &str = "[redacted]";
#[derive(Debug, Default)]
pub struct Redactor {
home: Option<String>,
/// The home folder as it may be written, and whether to match it
/// ignoring case (Windows paths).
homes: Vec<(String, bool)>,
/// Exact strings to take out wherever they appear (the signed-in token).
secrets: Vec<String>,
}
impl Redactor {
pub fn new(home: Option<String>, secrets: Vec<String>) -> Redactor {
let home = home.map(|h| h.trim_end_matches('/').to_owned()).filter(|h| h.len() > 1);
Redactor { home, secrets: secrets.into_iter().filter(|s| s.len() >= 8).collect() }
let homes = home.map(|h| home_forms(&h)).unwrap_or_default();
Redactor { homes, secrets: secrets.into_iter().filter(|s| s.len() >= 8).collect() }
}
/// `$HOME` → `~`, and the patterns.
@@ -37,8 +41,8 @@ impl Redactor {
for secret in &self.secrets {
s = s.replace(secret.as_str(), MARK);
}
if let Some(home) = &self.home {
s = replace_home(&s, home);
for (home, any_case) in &self.homes {
s = replace_home(&s, home, *any_case);
}
patterns(&s)
}
@@ -55,7 +59,10 @@ pub fn patterns(s: &str) -> String {
// The same inside a JSON string: `{\"token\":\"…\"}`.
let s = json_values(&s, "\\\"");
let s = assignments(&s);
let s = spaced_values(&s);
let s = flags(&s);
let s = jwts(&s);
let s = emails(&s);
TOKEN_PREFIXES.iter().fold(s, |s, prefix| prefixed_tokens(&s, prefix))
}
@@ -69,7 +76,34 @@ fn sensitive(key: &str) -> bool {
let k = key.trim_start_matches('-').to_ascii_lowercase().replace(['-', '.'], "_");
matches!(k.as_str(), "auth" | "authorization" | "pass" | "pgpass")
|| k.ends_with("_pass")
|| ["token", "password", "passwd", "passphrase", "secret", "apikey", "api_key", "access_key", "private_key", "credential", "crashreporterkey"].iter().any(|w| k.contains(w))
|| ["token", "password", "passwd", "passphrase", "secret", "apikey", "api_key", "access_key", "private_key", "credential", "crashreporterkey", "cookie", "session"].iter().any(|w| k.contains(w))
}
/// The home folder as logs may write it. A Windows one (`C:\Users\Ada`) is
/// also matched doubled inside JSON (`C:\\Users\\Ada`), with forward
/// slashes, as WSL mounts it (`/mnt/c/Users/Ada`) and as the WSL home of the
/// same name (`/home/ada`), all ignoring case, as Windows does.
fn home_forms(home: &str) -> Vec<(String, bool)> {
let home = home.trim_end_matches(['/', '\\']);
let b = home.as_bytes();
if b.len() > 2 && b[0].is_ascii_alphabetic() && b[1] == b':' && (b[2] == b'\\' || b[2] == b'/') {
let parts: Vec<&str> = home[2..].split(['\\', '/']).filter(|p| !p.is_empty()).collect();
if parts.is_empty() {
return Vec::new();
}
let drive = &home[..2];
let mut forms = vec![
format!("{drive}\\\\{}", parts.join("\\\\")),
format!("{drive}\\{}", parts.join("\\")),
format!("{drive}/{}", parts.join("/")),
format!("/mnt/{}/{}", drive[..1].to_ascii_lowercase(), parts.join("/")),
];
if let Some(user) = parts.last().filter(|u| u.len() > 1) {
forms.push(format!("/home/{user}"));
}
return forms.into_iter().map(|f| (f, true)).collect();
}
if home.starts_with('/') && home.len() > 1 { vec![(home.to_owned(), false)] } else { Vec::new() }
}
/// A PEM private key, whole; without its end line, everything after its
@@ -159,18 +193,25 @@ fn authorization(s: &str) -> String {
out
}
/// `/Users/ada/x` → `~/x`, but not `/Users/adam`.
fn replace_home(s: &str, home: &str) -> String {
/// `/Users/ada/x` → `~/x`, but not `/Users/adam`. `any_case` matches
/// `c:\users\ADA` too.
fn replace_home(s: &str, home: &str, any_case: bool) -> String {
// ASCII lower-casing keeps every byte where it was.
let (hay, needle) = if any_case { (s.to_ascii_lowercase(), home.to_ascii_lowercase()) } else { (s.to_owned(), home.to_owned()) };
let mut out = String::with_capacity(s.len());
let mut rest = s;
while let Some(i) = rest.find(home) {
let after = &rest[i + home.len()..];
let whole = after.bytes().next().is_none_or(|b| !(is_word(b) || b == b'-' || b == b'.'));
out.push_str(&rest[..i]);
out.push_str(if whole { "~" } else { home });
rest = after;
let mut last = 0;
let mut from = 0;
while let Some(i) = hay[from..].find(&needle).map(|i| i + from) {
let end = i + needle.len();
let whole = s.as_bytes().get(end).is_none_or(|&b| !(is_word(b) || b == b'-' || b == b'.'));
if whole {
out.push_str(&s[last..i]);
out.push('~');
last = end;
}
from = end;
}
out.push_str(rest);
out.push_str(&s[last..]);
out
}
@@ -282,8 +323,141 @@ fn assignments(s: &str) -> String {
out.push_str(MARK);
}
last = end;
i = end;
} else {
// Not a secret: the value may hold one (`env=[DB_PASSWORD=x`).
i += 1;
}
i = end.max(i + 1);
}
out.push_str(&s[last..]);
out
}
/// `password: hunter2`, `token = "abc"`, `aws_secret_access_key = …`,
/// `Cookie: a=b; c=d`: the value after a sensitive key, a `:` or an `=`
/// with spaces around it. A cookie header loses the rest of its line.
/// `Authorization` has its own pass, and `key=value` with no spaces is
/// [`assignments`]'.
fn spaced_values(s: &str) -> String {
let b = s.as_bytes();
let key_byte = |c: u8| is_word(c) || c == b'-' || c == b'.';
let blank = |c: u8| c == b' ' || c == b'\t';
let (mut out, mut last) = (String::with_capacity(s.len()), 0);
let mut i = 0;
while i < b.len() {
let sep = b[i];
if !(sep == b':' || sep == b'=') || i < last {
i += 1;
continue;
}
let mut j = i;
while j > 0 && blank(b[j - 1]) {
j -= 1;
}
let mut k = j;
while k > 0 && key_byte(b[k - 1]) {
k -= 1;
}
let mut start = i + 1;
while start < b.len() && blank(b[start]) {
start += 1;
}
let key = &s[k..j];
let lower = key.to_ascii_lowercase();
let spaced = j < i || start > i + 1;
// `=` with no spaces is `assignments`; `==`, `!=` and `<=` compare;
// `://` is a URL and `::` a path.
let next = b.get(i + 1).copied();
let prev = if i > 0 { Some(b[i - 1]) } else { None };
let skip = k == j
|| (sep == b'=' && (!spaced || matches!(next, Some(b'=')) || matches!(prev, Some(b'=' | b'!' | b'<' | b'>'))))
|| (sep == b':' && (matches!(next, Some(b'/' | b':')) || prev == Some(b':')))
|| matches!(lower.as_str(), "authorization" | "proxy-authorization")
|| !sensitive(key)
|| start >= b.len()
|| b[start] == b'\n'
|| b[start] == b'\r';
if skip {
i += 1;
continue;
}
let cookie = lower.ends_with("cookie");
let quote = matches!(b[start], b'"' | b'\'').then_some(b[start] as char);
let end = match quote {
Some(q) => s[start + 1..].find(q).map_or(b.len(), |n| start + 1 + n + 1),
None if cookie => s[start..].find(['\n', '\r']).map_or(b.len(), |n| start + n),
None => s[start..].find(|c: char| c.is_whitespace() || ",;&)<>\"'".contains(c)).map_or(b.len(), |n| start + n),
};
let value = &s[start..end];
if end <= start || value.trim_matches(['"', '\'']).starts_with(MARK) {
i += 1;
continue;
}
out.push_str(&s[last..start]);
match quote {
Some(q) => {
out.push(q);
out.push_str(MARK);
out.push(q);
}
None => out.push_str(MARK),
}
last = end;
i = end;
}
out.push_str(&s[last..]);
out
}
/// `ada@example.org`, whole: an email address names the person. Not
/// `git@github.com:…`, and not `image@sha256:…`.
fn emails(s: &str) -> String {
let b = s.as_bytes();
let local = |c: u8| c.is_ascii_alphanumeric() || b"._%+-".contains(&c);
let domain = |c: u8| c.is_ascii_alphanumeric() || c == b'-' || c == b'.';
let (mut out, mut last, mut from) = (String::with_capacity(s.len()), 0, 0);
while let Some(at) = s[from..].find('@').map(|i| i + from) {
from = at + 1;
let mut i = at;
while i > last && local(b[i - 1]) {
i -= 1;
}
let mut j = at + 1;
while j < b.len() && domain(b[j]) {
j += 1;
}
let host = s[at + 1..j].trim_end_matches('.');
let j = at + 1 + host.len();
let tld = host.rsplit('.').next().unwrap_or("");
let ok = i < at && &s[i..at] != "git" && host.contains('.') && tld.len() >= 2 && tld.bytes().all(|c| c.is_ascii_alphabetic());
if ok {
out.push_str(&s[last..i]);
out.push_str(MARK);
last = j;
from = j;
}
}
out.push_str(&s[last..]);
out
}
/// A JWT (`eyJ….eyJ….sig`), whole.
fn jwts(s: &str) -> String {
let b = s.as_bytes();
let part = |c: u8| c.is_ascii_alphanumeric() || c == b'_' || c == b'-';
let (mut out, mut last, mut from) = (String::with_capacity(s.len()), 0, 0);
while let Some(i) = s[from..].find("eyJ").map(|i| i + from) {
let (mut j, mut dots) = (i, 0);
while j < b.len() && (part(b[j]) || (b[j] == b'.' && dots < 2)) {
dots += usize::from(b[j] == b'.');
j += 1;
}
if (i == 0 || !is_word(b[i - 1])) && dots == 2 && j - i >= 24 && s[i..j].split('.').nth(1).is_some_and(|p| p.starts_with("eyJ")) {
out.push_str(&s[last..i]);
out.push_str(MARK);
last = j;
}
from = j.max(i + 3);
}
out.push_str(&s[last..]);
out
@@ -333,9 +507,13 @@ fn flags(s: &str) -> String {
out
}
/// What starts a token that says what it is: Kiri share's, GitHub's, GitLab's,
/// Docker Hub's, and an AWS access key id.
const TOKEN_PREFIXES: [&str; 10] = ["ks_", "ghp_", "gho_", "ghu_", "ghs_", "ghr_", "github_pat_", "glpat-", "dckr_pat_", "AKIA"];
/// What starts a token that says what it is: Kiri share's, GitHub's,
/// GitLab's, Docker Hub's, an AWS access key id, Stripe's, Slack's,
/// Anthropic's, OpenAI's, Google's, npm's and PyPI's.
const TOKEN_PREFIXES: [&str; 26] = [
"ks_", "ghp_", "gho_", "ghu_", "ghs_", "ghr_", concat!("github", "_pat_"), "glpat-", "glptt-", "dckr_pat_", "AKIA", "ASIA", "sk_live_", "sk_test_", "rk_live_", "rk_test_",
"xoxb-", "xoxp-", "xoxa-", "xoxr-", "sk-ant-", "sk-proj-", "sk-svcacct-", "AIza", "npm_", "pypi-",
];
/// `prefix…`, a token of that kind, wherever it appears.
fn prefixed_tokens(s: &str, prefix: &str) -> String {
@@ -486,6 +664,87 @@ mod tests {
assert!(!once.contains("abcdefghijkl") && !once.contains("0123456789abcdef") && !once.contains("/Users/ada"), "{once}");
}
#[test]
fn windows_home_in_every_form() {
let r = Redactor::new(Some(r"C:\Users\Alex".into()), Vec::new());
for (text, want) in [
(r"opened C:\Users\Alex\proj", r"opened ~\proj"),
(r#"{"path":"C:\\Users\\Alex\\proj"}"#, r#"{"path":"~\\proj"}"#),
("C:/Users/Alex/proj", "~/proj"),
(r"c:\users\ALEX\proj", r"~\proj"),
("/mnt/c/Users/Alex/proj", "~/proj"),
("/home/alex/.docker/config.json", "~/.docker/config.json"),
] {
assert_eq!(r.apply(text), want, "{text}");
}
// A longer name is someone else.
assert_eq!(r.apply(r"C:\Users\Alexandra\x"), r"C:\Users\Alexandra\x");
assert_eq!(Redactor::new(Some(r"C:\".into()), Vec::new()).apply(r"C:\x"), r"C:\x");
}
#[test]
fn colon_and_spaced_values() {
for (text, want) in [
("password: hunter2", "password: [redacted]"),
("token : abc123 next", "token : [redacted] next"),
(r#"token: "two words""#, r#"token: "[redacted]""#),
("aws_secret_access_key = wJalrXUtnFEMI/K7MDENG", "aws_secret_access_key = [redacted]"),
(r#"Config { password: "x", port: 5432 }"#, r#"Config { password: "[redacted]", port: 5432 }"#),
("X-Api-Key: abcdef0123456789", "X-Api-Key: [redacted]"),
("Cookie: session=abc; theme=dark\nnext", "Cookie: [redacted]\nnext"),
("Set-Cookie: sg_session=abc; Path=/", "Set-Cookie: [redacted]"),
] {
assert_eq!(patterns(text), want, "{text}");
}
for text in ["error: could not connect", "at 12:30: done", "see https://runkiri.com/token", "token refresh failed", "port = 5432", "password:\nnext"] {
assert_eq!(patterns(text), text);
}
}
#[test]
fn a_secret_inside_another_value() {
assert_eq!(patterns("env=[DB_PASSWORD=hunter2 STRIPE=1]"), "env=[DB_PASSWORD=[redacted] STRIPE=1]");
assert_eq!(patterns("args=--password=hunter2"), "args=--password=[redacted]");
}
#[test]
fn email_addresses() {
assert_eq!(patterns("logged in as ada.lovelace@example.org."), "logged in as [redacted].");
for text in ["git@github.com:a/b.git", "nginx@sha256:abcd", "a @ b", "x@localhost"] {
assert_eq!(patterns(text), text);
}
}
#[test]
fn jwts_whole() {
let jwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abcdefghijklmn";
assert_eq!(patterns(&format!("got {jwt} ok")), "got [redacted] ok");
assert_eq!(patterns("eyJustAWord and eyJx.y"), "eyJustAWord and eyJx.y");
}
#[test]
fn more_tokens_that_say_what_they_are() {
for (text, want) in [
("sk_live_abcdefghijklmnopqrstu", "sk_live_[redacted]"),
("xoxb-123456789012-abcdefghijkl", "xoxb-[redacted]"),
("sk-ant-api03-abcdefghijklmnopqrstuvwxyz", "sk-ant-[redacted]"),
("sk-proj-abcdefghijklmnopqrstuvwxyz012345", "sk-proj-[redacted]"),
("AIzaSyA1234567890abcdefghijklmnop", "AIza[redacted]"),
("npm_abcdefghijklmnopqrstuvwxyz0123456789", "npm_[redacted]"),
] {
assert_eq!(patterns(text), want, "{text}");
}
}
#[test]
fn redacting_the_new_forms_twice_changes_nothing() {
let text = r#"password: hunter2 Cookie: a=b eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abcdefghijklmn sk_live_abcdefghijklmnop env=[DB_PASSWORD=x ada@example.org C:/Users/Ada/x"#;
let r = Redactor::new(Some(r"C:\Users\Ada".into()), Vec::new());
let once = r.apply(text);
assert_eq!(r.apply(&once), once);
assert!(!once.contains("hunter2") && !once.contains("ada@") && !once.contains("Users/Ada"), "{once}");
}
#[test]
fn leaves_other_text_and_unicode_alone() {
let text = "VM booted in 112 ms → 4 CPUs, café=ok, a = b";
+62 -11
View File
@@ -17,8 +17,10 @@
//! "created_at":"<RFC 3339>","text":"<the redacted report or crash>"}
//! ```
//!
//! with `Authorization: Bearer <token>` when signed in to Kiri Cloud. It
//! answers `201 {"id":"rep_…"}`, the id a person can quote to us. Crash
//! A report the person sends carries `Authorization: Bearer <token>` when
//! signed in to Kiri Cloud, so it can be answered. A crash never does: it
//! goes without the person's account. Crash uploads also leave out the image
//! and container names their log lines name. It answers `201 {"id":"rep_…"}`, the id a person can quote to us. Crash
//! files that went become `<name>.sent.txt`; any other answer leaves them
//! for the next try.
@@ -532,7 +534,8 @@ pub fn body(kind: &str, part: Part, created: SystemTime, text: &str, install_id:
pub fn send(kind: &str, part: Part, created: SystemTime, text: &str) -> io::Result<String> {
let state = super::state_dir().ok_or_else(|| io::Error::other("HOME is not set"))?;
let body = body(kind, part, created, text, &install_id(&state));
let (status, v) = crate::share::post_report(&body)?;
// Only a report the person sends carries their sign-in; a crash never does.
let (status, v) = crate::share::post_report(&body, kind == "report")?;
let why = v["error"].as_str().map(|e| format!(": {e}")).unwrap_or_default();
match status {
200 | 201 => v["id"]
@@ -637,22 +640,57 @@ fn send_claimed(dir: &Path, name: &str, claimed: &Path, redactor: &Redactor) ->
}
}
/// Log fields that name the person's images and containers.
const NAME_FIELDS: [&str; 5] = ["image", "name", "container", "reference", "repo"];
/// What a crash upload holds: the crash file, then the last lines its part
/// logged up to the crash.
/// logged up to the crash, without the image and container names they
/// carry, wherever those appear.
fn crash_upload(state: &Path, secs: u64, part: Part, text: &str) -> String {
let until = time::rfc3339(UNIX_EPOCH + Duration::from_secs(secs + 1));
let lines: Vec<String> = read_lines(state, &[part], Filter::default(), 2000)
.iter()
let mut lines: Vec<Value> = read_lines(state, &[part], Filter::default(), 2000)
.into_iter()
.filter(|v| v["time"].as_str().is_some_and(|t| t < until.as_str()))
.map(|v| render(v, true, false))
.collect();
let lines = &lines[lines.len().saturating_sub(CRASH_LOG_LINES)..];
lines.drain(..lines.len().saturating_sub(CRASH_LOG_LINES));
let mut s = text.trim_end().to_owned();
let _ = writeln!(s, "\n\n==== The last {} log lines before it ====", lines.len());
for l in lines {
let _ = writeln!(s, "{l}");
for l in &lines {
let _ = writeln!(s, "{}", render(l, true, false));
}
s
without_names(&s, &lines)
}
/// `text` with every image and container name that `lines` log taken out,
/// longest first, so `web` doesn't leave half of `web-admin`.
fn without_names(text: &str, lines: &[Value]) -> String {
let mut names: Vec<&str> = lines
.iter()
.flat_map(|v| NAME_FIELDS.iter().filter_map(move |k| v["fields"][*k].as_str()))
.map(str::trim)
.filter(|n| n.len() >= 3 && *n != "[redacted]")
.collect();
names.sort_by_key(|n| std::cmp::Reverse(n.len()));
names.dedup();
names.into_iter().fold(text.to_owned(), |s, n| replace_whole(&s, n, "[name]"))
}
/// Every `name` in `s` that stands alone (not inside a longer word, so a
/// container `web` leaves `webpki` be, but not `web.kiri.local`).
fn replace_whole(s: &str, name: &str, with: &str) -> String {
let joins = |c: Option<char>| c.is_some_and(|c| c.is_alphanumeric() || c == '_' || c == '-');
let (mut out, mut last, mut from) = (String::with_capacity(s.len()), 0, 0);
while let Some(i) = s[from..].find(name).map(|i| i + from) {
let end = i + name.len();
if !joins(s[..i].chars().next_back()) && !joins(s[end..].chars().next()) {
out.push_str(&s[last..i]);
out.push_str(with);
last = end;
}
from = end;
}
out.push_str(&s[last..]);
out
}
/// The id a sent crash file ends with.
@@ -794,6 +832,19 @@ mod tests {
let _ = std::fs::remove_dir_all(&home);
}
#[test]
fn crash_uploads_leave_out_image_and_container_names() {
let line = |msg: &str, fields: &[(&str, String)]| -> Value { serde_json::from_str(&super::super::json_line("2026-10-28T09:41:07.123Z", Level::Info, Part::Daemon, msg, fields)).unwrap() };
let lines = [
line("image pull failed", &[("image", "registry.acme.corp/secret-app:1.2".into()), ("error", "registry.acme.corp/secret-app:1.2: unauthorized".into())]),
line("container exited", &[("name", "web".into()), ("image", "nginx".into())]),
];
let text = format!("panic at webpki: web.kiri.local is gone\n{}\n{}", render(&lines[0], true, false), render(&lines[1], true, false));
let out = without_names(&text, &lines);
assert!(!out.contains("secret-app") && !out.contains("acme") && !out.contains("nginx"), "{out}");
assert!(out.contains("webpki") && out.contains("[name].kiri.local") && out.contains("name=[name]"), "{out}");
}
#[test]
fn renders_lines_for_people() {
let v: Value = serde_json::from_str(&super::super::json_line("2026-10-28T09:41:07.123Z", Level::Warn, Part::Daemon, "container exited", &[("id", "3f2a".into()), ("error", "no such file".into())])).unwrap();
+14
View File
@@ -141,6 +141,9 @@ impl Guest {
share: opts.data_disk.then(|| (PathBuf::from("/"), "kiri-mac".to_owned())),
rosetta_tag: opts.data_disk.then(|| "rosetta".to_owned()),
};
if !cfg.kernel.is_file() {
return Err(missing_kernel(&cfg.kernel, std::env::current_exe().ok().as_deref()));
}
Ok(cfg)
}
@@ -404,6 +407,17 @@ fn translated() -> bool {
on == 1
}
/// The error for a guest kernel that isn't there. Mostly the app was
/// deleted or moved while its engine ran: say that, not a bare path.
#[cfg(target_os = "macos")]
fn missing_kernel(kernel: &std::path::Path, exe: Option<&std::path::Path>) -> io::Error {
let msg = match exe {
Some(exe) if !exe.exists() => format!("{} was deleted or moved while it ran: open Kiri again from where it is now", crate::flavor::APP),
_ => format!("the guest kernel {} is missing: reinstall Kiri", kernel.display()),
};
io::Error::new(io::ErrorKind::NotFound, msg)
}
#[cfg(target_os = "macos")]
/// Where the kernel and initramfs live: `KIRI_GUEST_DIR`, else
/// `Kiri.app/Contents/Resources/guest` when running from the app, else the
+4
View File
@@ -12,6 +12,10 @@ mod boot;
#[cfg(unix)]
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
mod builds;
// The engine stops when its app is deleted under it (kiri-win includes it
// for Windows).
#[cfg(unix)]
mod appwatch;
// Which builder plain `docker build` uses: Docker's or Kiri's.
#[cfg(unix)]
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
+7 -5
View File
@@ -429,12 +429,14 @@ fn api_error(v: &Value, status: u16) -> io::Error {
}
/// Kiri Cloud's diagnostics intake, `POST /v1/reports` on the same edge
/// (`KIRI_SHARE_SERVER` and the config's `server` move it, as for sharing),
/// signed in when there is a token, anonymous when not. See `crate::diag::report`
/// (and crates/kiri-win/src/diag.rs on Windows).
pub fn post_report(body: &Value) -> io::Result<(u16, Value)> {
/// (`KIRI_SHARE_SERVER` and the config's `server` move it, as for sharing).
/// `signed` sends the Kiri Cloud token when there is one, so a report the
/// person sent can be answered; crashes always go without it, so they never
/// name the person's GitHub account. See `crate::diag::report` (and
/// crates/kiri-win/src/diag.rs on Windows).
pub fn post_report(body: &Value, signed: bool) -> io::Result<(u16, Value)> {
let cfg = read_config();
api(&server(&cfg), "POST", "/v1/reports", Some(body), cfg.token.as_deref())
api(&server(&cfg), "POST", "/v1/reports", Some(body), cfg.token.as_deref().filter(|_| signed))
}
// ---------------------------------------------------------------- account
+11 -5
View File
@@ -5171,9 +5171,15 @@ function stopReason(c) {
// the strictest images take it.
function genPassword() {
const sets = ["ABCDEFGHJKLMNPQRSTUVWXYZ", "abcdefghijkmnpqrstuvwxyz", "23456789", "-_.@%"], all = sets.join("");
const r = crypto.getRandomValues(new Uint32Array(20));
const out = [...r].map((n, i) => (i < 4 ? sets[i] : all)[n % (i < 4 ? sets[i] : all).length]);
for (let i = out.length - 1; i > 0; i--) { const j = r[i] % (i + 1); [out[i], out[j]] = [out[j], out[i]]; }
// A uniform number below n: fresh random values, dropping the few at the
// top of the range that would make some answers likelier than others.
const below = (n) => {
const limit = 2 ** 32 - (2 ** 32 % n), r = new Uint32Array(1);
do crypto.getRandomValues(r); while (r[0] >= limit);
return r[0] % n;
};
const out = Array.from({ length: 20 }, (_, i) => { const set = i < 4 ? sets[i] : all; return set[below(set.length)]; });
for (let i = out.length - 1; i > 0; i--) { const j = below(i + 1); [out[i], out[j]] = [out[j], out[i]]; }
return out.join("");
}
const strong = (v) => v.length >= 8 && /[A-Z]/.test(v) && /[a-z]/.test(v) && /\d/.test(v) && /[^A-Za-z0-9]/.test(v);
@@ -5474,7 +5480,7 @@ function diagPane() {
const crashes = dg.crashes == null ? `<div class="none">Looking for crash reports…</div>` : dg.crashes.length ? dg.crashes.map(crash).join("") : `<div class="none">No crashes. Kiri keeps a report here if one of its parts ever stops unexpectedly.</div>`;
return `<div class="pane diag"><h3>Diagnostics</h3>
<div class="pref"><span class="t">Send crash reports automatically</span>
<span class="d">When part of Kiri crashes, the stack trace, versions and the last 200 log lines before it go to Kiri Cloud. Nothing from inside your containers; your home folder, tokens and passwords are blanked.</span>
<span class="d">When part of Kiri crashes, the stack trace and the last 200 log lines before it go to Kiri Cloud, with Kiri's and the system's versions, the computer's model and a random ID for this install. Never your Kiri Cloud account, and nothing from inside your containers. Your home folder, image and container names, tokens and passwords are taken out.</span>
<div class="seg" role="group" aria-label="Send crash reports automatically"><button data-dgauto="0" aria-pressed="${prefs.crashReports !== true}">Off</button><button data-dgauto="1" aria-pressed="${prefs.crashReports === true}">On</button></div></div>
<div class="pref"><span class="t">Diagnostics report</span>
<span class="d">Recent logs, crash reports and versions in one redacted file, for when something goes wrong.</span>
@@ -5557,7 +5563,7 @@ function drawReport() {
const item = (t, d) => `<div class="rp-item">${dgIcon("check")}<span class="t">${t}</span><span class="d">${d}</span></div>`;
scrim.innerHTML = `<div class="dialog rp-dialog" role="dialog" aria-modal="true" aria-labelledby="rp-t">
<h3 id="rp-t">${send_ ? "Send a report to Kiri" : "Create a diagnostics report"}</h3>
<p>${send_ ? "We get the file below, redacted, and you get an ID to quote when you write to us." : "One text file, redacted, saved to your Desktop and shown in Finder. Read it before you share it."}</p>
<p>${send_ ? "We get the file below, redacted, and you get an ID to quote when you write to us. If you're signed in to Kiri Cloud, it says it's from you, so we can reply." : "One text file, redacted, saved to your Desktop and shown in Finder. Read it before you share it."}</p>
<div class="rp-list">${item("Kiri's logs", "The last 300 lines from the window, the engine and kiri commands, and the engine's own output")}
${item("Crash reports", "The 5 newest, and macOS's own crash reports for Kiri from the last 30 days")}
${item("Kiri and this Mac", "Versions, macOS, whether the engine runs, how many containers and images")}
-7
View File
@@ -1,7 +0,0 @@
## Fixed
- **Turning off automatic updates now sticks.** On Mac, Windows and Linux, Settings showed **Off**, but the choice wasn't saved, so Kiri checked for updates again at the next launch. It's saved now.
- **Turning on crash reports sends only new crashes.** Switching them on used to send every crash still waiting, including ones you'd answered **Not now** to. Kiri now sends only crashes from after you turned reports on. You can still send an older one yourself from its card.
- **Logs and reports take out more secrets.** Passwords in URLs, `Authorization` values of any kind, PEM private keys, values after flags such as `--password`, GitHub, GitLab, Docker Hub and AWS access key tokens, and keys such as `PGPASS`, `API-KEY` and `*_PRIVATE_KEY` are now replaced with `[redacted]` before anything leaves your computer. It errs towards taking out too much: the whole user part of a URL goes, not only its password.
- **Windows: updates stay on HTTPS.** Kiri no longer follows a redirect from the update feed down to plain HTTP, and release builds no longer accept a feed from a local file.
Thanks to [@9trocode](https://github.com/9trocode) for all four fixes, Kiri's first outside contribution.
+14
View File
@@ -0,0 +1,14 @@
## Fixed
- **Turning off automatic updates now sticks.** On Mac, Windows and Linux, Settings showed **Off**, but the choice wasn't saved, so Kiri checked for updates again at the next launch. It's saved now.
- **Turning on crash reports sends only new crashes.** Switching them on used to send every crash still waiting, including ones you'd answered **Not now** to. Kiri now sends only crashes from after you turned reports on. You can still send an older one yourself from its card.
- **Logs and reports take out more secrets.** Passwords in URLs, `Authorization` values of any kind, PEM private keys, values after flags such as `--password`, GitHub, GitLab, Docker Hub and AWS access key tokens, and keys such as `PGPASS`, `API-KEY` and `*_PRIVATE_KEY` are now replaced with `[redacted]` before anything leaves your computer. It errs towards taking out too much: the whole user part of a URL goes, not only its password.
- **Windows: updates stay on HTTPS.** Kiri no longer follows a redirect from the update feed down to plain HTTP, and release builds no longer accept a feed from a local file.
- **Crash reports never carry your Kiri Cloud account.** A crash sent while you were signed in to Kiri Cloud went with your sign-in, so it named your GitHub account. Crashes now always go without it. A diagnostics report you send yourself still says it's from you, so we can reply, and the Send dialog says so.
- **Crash reports leave out your image and container names.** The log lines a crash report carries named the images you pulled and the containers that stopped, including private registries. Those names are now taken out wherever they appear in the report.
- **Windows: reports take out your user name in every form.** Your home folder was only blanked when written exactly as `C:\Users\you`. Now it also goes in lower case, with forward slashes, doubled inside JSON, as WSL's `/mnt/c/Users/you`, and as `/home/you` in the engine's log.
- **Still more secrets are redacted.** `password: …` and `key = …` with spaces, `Cookie` and `Set-Cookie` headers, `X-Api-Key`, JWTs, Stripe, Slack, Anthropic, OpenAI, Google, npm and PyPI tokens, and email addresses. A secret written inside another value, such as `env=[DB_PASSWORD=…`, is no longer missed.
- **Settings says exactly what a crash report sends**: the stack trace, the last 200 log lines, versions, the computer's model and a random ID for this install.
0.1.16 was tagged but never released; its fixes are in this release.
Thanks to [@9trocode](https://github.com/9trocode) for the first four fixes, Kiri's first outside contribution.