mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Merge pull request #3 from aziascreations/dev-improvements
Simplified server's topic configs, Fixed some issues and more
This commit is contained in:
Generated
+8
-8
@@ -123,7 +123,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-capi"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bakashrot-client",
|
||||
"bakashrot-config",
|
||||
@@ -137,7 +137,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-client"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"bakashrot-pki",
|
||||
@@ -147,7 +147,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-config"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bakashrot-proto",
|
||||
"indexmap",
|
||||
@@ -157,7 +157,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-pki"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bakashrot-proto",
|
||||
"rcgen",
|
||||
@@ -169,7 +169,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-proto"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"rmp-serde",
|
||||
@@ -180,7 +180,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-server"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"bakashrot-client",
|
||||
@@ -200,7 +200,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-storage"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bakashrot-config",
|
||||
"bakashrot-proto",
|
||||
@@ -210,7 +210,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bakashrot-tools"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bakashrot-client",
|
||||
"bakashrot-config",
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ resolver = "3"
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.100"
|
||||
license = "CC0-1.0"
|
||||
|
||||
@@ -226,13 +226,15 @@ ptrdiff_t BakaShrot_GetMessageNodeA(char *buffer, ptrdiff_t size);
|
||||
ptrdiff_t BakaShrot_GetMessageNodeW(uint16_t *buffer, ptrdiff_t size);
|
||||
|
||||
/**
|
||||
* Lists the topics this client may push to or read (every one if it may
|
||||
* query): how many, -1 on failure. Then `BakaShrot_GetNamesList()`.
|
||||
* Lists the topics with messages that this client may push to or read
|
||||
* (every one if its roles have `list_topics` or `query`): how many, -1 on
|
||||
* failure. Then `BakaShrot_GetNamesList()`.
|
||||
*/
|
||||
int32_t BakaShrot_ListTopics(void);
|
||||
|
||||
/**
|
||||
* Lists every node with messages: how many, -1 on failure. Then
|
||||
* Lists the nodes with messages in the topics this client may read (every
|
||||
* one if its roles have `list_nodes` or `query`): how many, -1 on failure. Then
|
||||
* `BakaShrot_GetNamesList()`.
|
||||
*/
|
||||
int32_t BakaShrot_ListNodes(void);
|
||||
|
||||
@@ -311,7 +311,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
PrintN("Topics: " + BakaShrot_GetNamesListString())
|
||||
|
||||
If BakaShrot_PushMessageTo("nothing", "{}") < 0
|
||||
PrintN("A push to an unknown topic: " + BakaShrot_ErrorName(BakaShrot_GetLastError()) + ", " + BakaShrot_GetRefusalReasonString())
|
||||
PrintN("A push to a topic it may not push to: " + BakaShrot_ErrorName(BakaShrot_GetLastError()) + ", " + BakaShrot_GetRefusalReasonString())
|
||||
EndIf
|
||||
|
||||
BakaShrot_Disconnect()
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
; Not allowed to this client: its roles' permissions (or, when connecting,
|
||||
; none of its roles is the server's).
|
||||
#BakaShrot_Refused_NotAllowed = 1
|
||||
; A topic or node this server doesn't know.
|
||||
; A node this server has no message of.
|
||||
#BakaShrot_Refused_UnknownName = 2
|
||||
; No such message or attachment.
|
||||
#BakaShrot_Refused_NotFound = 3
|
||||
|
||||
@@ -58,7 +58,7 @@ from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Iterator, Optional, Union
|
||||
|
||||
__version__ = "0.2.0"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
__all__ = [
|
||||
"Client", "Message", "MessagesPage", "NamesList",
|
||||
@@ -79,7 +79,7 @@ class ErrorCode(enum.IntEnum):
|
||||
NONE = 0
|
||||
# Refused by the server, the connection still open.
|
||||
NOT_ALLOWED = 1 # its roles don't allow it (or none is the server's, when connecting)
|
||||
UNKNOWN_NAME = 2 # a topic or node this server doesn't know
|
||||
UNKNOWN_NAME = 2 # a node this server has no message of
|
||||
NOT_FOUND = 3 # no such message or attachment
|
||||
NOT_READY = 4 # the attachment isn't on this server yet: retry later
|
||||
TOO_BIG = 5 # over a limit, or more than this server keeps
|
||||
@@ -542,11 +542,11 @@ class Client:
|
||||
time.sleep(interval)
|
||||
|
||||
def list_topics(self) -> NamesList:
|
||||
"""The topics the client may push to or read (every one if it may query)."""
|
||||
"""The topics with messages that the client may push to or read (every one with list_topics or query)."""
|
||||
return self._list(self._dll.ListTopics, "List topics")
|
||||
|
||||
def list_nodes(self) -> NamesList:
|
||||
"""Every node with messages."""
|
||||
"""The nodes with messages in the topics the client may read (every one with list_nodes or query)."""
|
||||
return self._list(self._dll.ListNodes, "List nodes")
|
||||
|
||||
def _list(self, function, what: str) -> NamesList:
|
||||
|
||||
@@ -131,8 +131,8 @@ with kitchen:
|
||||
check("limit 0: ValueError, before asking", ok, detail)
|
||||
ok, detail = raises(lambda: kitchen.get_messages("logs", "kitchen", after=-1), ValueError)
|
||||
check("after -1: ValueError", ok, detail)
|
||||
ok, detail = raises(lambda: kitchen.push("x", "nothing"), RefusedError, "unknown topic", ErrorCode.UNKNOWN_NAME)
|
||||
check("Push to an unknown topic: RefusedError, UNKNOWN_NAME", ok, detail)
|
||||
ok, detail = raises(lambda: kitchen.push("x", "nothing"), RefusedError, "may not push to 'nothing'", ErrorCode.NOT_ALLOWED)
|
||||
check("Push to a topic not in its push_topics: RefusedError, NOT_ALLOWED", ok, detail)
|
||||
ok, detail = raises(lambda: kitchen.push("x", "a b"), BakaShrotError, "isn't a topic name", ErrorCode.INVALID_ARGUMENT)
|
||||
check("A topic that isn't a name: refused before sending", ok, detail)
|
||||
ok, detail = raises(lambda: kitchen.push("x" * (bakashrot.MAX_MESSAGE_SIZE + 1), "logs"), BakaShrotError, "too big",
|
||||
|
||||
@@ -668,14 +668,16 @@ fn list(kind: NameKind) -> i32 {
|
||||
})
|
||||
}
|
||||
|
||||
/// Lists the topics this client may push to or read (every one if it may
|
||||
/// query): how many, -1 on failure. Then `BakaShrot_GetNamesList()`.
|
||||
/// Lists the topics with messages that this client may push to or read
|
||||
/// (every one if its roles have `list_topics` or `query`): how many, -1 on
|
||||
/// failure. Then `BakaShrot_GetNamesList()`.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn BakaShrot_ListTopics() -> i32 {
|
||||
list(NameKind::Topic)
|
||||
}
|
||||
|
||||
/// Lists every node with messages: how many, -1 on failure. Then
|
||||
/// Lists the nodes with messages in the topics this client may read (every
|
||||
/// one if its roles have `list_nodes` or `query`): how many, -1 on failure. Then
|
||||
/// `BakaShrot_GetNamesList()`.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn BakaShrot_ListNodes() -> i32 {
|
||||
|
||||
@@ -12,7 +12,6 @@ listen = "127.0.0.1:0"
|
||||
ca = "ca.crt"
|
||||
certificate = "server.crt"
|
||||
key = "server.key"
|
||||
topics = ["logs", "secret"]
|
||||
|
||||
[roles.home]
|
||||
push_topics = ["logs", "secret"]
|
||||
|
||||
@@ -125,8 +125,8 @@ fn exports() {
|
||||
-1
|
||||
);
|
||||
let (failed, why) = error();
|
||||
assert_eq!(failed, code(ErrorCode::UnknownName));
|
||||
assert!(why.contains("unknown topic"), "{why}");
|
||||
assert_eq!(failed, code(ErrorCode::NotAllowed));
|
||||
assert!(why.contains("may not push to 'nothing'"), "{why}");
|
||||
|
||||
// The latest; none yet in another topic.
|
||||
assert_eq!(
|
||||
@@ -199,10 +199,11 @@ fn exports() {
|
||||
assert_eq!(bytes[1..3], [b'{', 0]);
|
||||
|
||||
// Names, queries.
|
||||
assert_eq!(BakaShrot_ListTopics(), 2);
|
||||
// Topics: those with messages (nothing in `secret` yet).
|
||||
assert_eq!(BakaShrot_ListTopics(), 1);
|
||||
assert_eq!(
|
||||
get_w(BakaShrot_GetNamesListW),
|
||||
r#"{"kind":"topic","names":["logs","secret"],"truncated":false}"#
|
||||
r#"{"kind":"topic","names":["logs"],"truncated":false}"#
|
||||
);
|
||||
assert_eq!(BakaShrot_ListNodes(), 1);
|
||||
assert_eq!(
|
||||
|
||||
@@ -413,8 +413,10 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
/// The topics this client may push to or read (every one if it may
|
||||
/// query), or every node with messages. `truncated` if some didn't fit.
|
||||
/// The topics with messages that this client may push to or read, or
|
||||
/// the nodes with messages in the topics it may read; every one if its
|
||||
/// roles have `list_topics` / `list_nodes`, or `query`. `truncated` if
|
||||
/// some didn't fit.
|
||||
pub fn list_names(&mut self, kind: NameKind) -> Result<NamesList> {
|
||||
match self.request(ListNames { kind }.into())? {
|
||||
Packet::NamesList(names) => Ok(names),
|
||||
|
||||
@@ -20,9 +20,6 @@ key = "server-1.key"
|
||||
|
||||
database = "bakashrot.sqlite"
|
||||
|
||||
# The topics clients push to. Peers may bring others (accept_topics).
|
||||
topics = ["logs", "sensors.kitchen", "sensors.garage"]
|
||||
|
||||
# "full": every push flushed to disk before it's answered, it survives a
|
||||
# power loss. "normal": about twice the pushes, a power loss loses the last
|
||||
# second or so. ("off" isn't allowed.)
|
||||
@@ -44,22 +41,25 @@ logs = "30d"
|
||||
[replication]
|
||||
push_to = [] # dialed and sent to: ["10.0.0.2:7000", "server-2.lan:7000"]
|
||||
accept_from = [] # taken from: ["10.0.0.2", "server-2.lan"], or ["*"]
|
||||
# The only topics replicated at all, whatever the roles say: a filter for
|
||||
# edge nodes. Without it, no filter; [] replicates nothing.
|
||||
# replicated_topics = ["logs", "alerts.*"]
|
||||
retry_delay = "10s"
|
||||
sync_interval = "5s"
|
||||
batch_size = 1000 # messages per packet, 1-10000
|
||||
|
||||
# What certificates with a role may do. A certificate gets everything its
|
||||
# roles allow; one without any role listed here is refused. Every key is
|
||||
# optional: an empty list allows nothing.
|
||||
# optional: an empty list allows nothing. The topics are only named here:
|
||||
# one exists from its first message, pushed (push_topics) or replicated
|
||||
# (accept_topics).
|
||||
[roles.sensor]
|
||||
push_topics = ["sensors.*"] # always as its own node (its name)
|
||||
|
||||
[roles.dashboard]
|
||||
read_topics = ["*"]
|
||||
query = true # read-only SQL, reads every topic
|
||||
# Listing answers the topics it may push to or read, and the nodes of the
|
||||
# topics it may read. These answer every one (query does too):
|
||||
# list_topics = true
|
||||
# list_nodes = true
|
||||
|
||||
# Peers are roles too: what's replicated with a server whose certificate
|
||||
# has this role, whichever end dials.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//! The server's config: a TOML file, read and checked in one go.
|
||||
//!
|
||||
//! - [`Server`]: where it listens, its files, its topics, its database.
|
||||
//! - [`Server`]: where it listens, its files, its database.
|
||||
//! - [`Retention`]: how long each topic's messages are kept.
|
||||
//! - [`Replication`]: the servers it sends to and takes from, what it
|
||||
//! replicates, how often.
|
||||
//! - [`Replication`]: the servers it sends to and takes from, how often.
|
||||
//! - [`Role`]: what certificates with a role may do; [`Permissions`]: what
|
||||
//! a certificate's roles allow together.
|
||||
//!
|
||||
//! Who connects is the certificate's (`bakashrot-pki`): its name is its
|
||||
//! node, its roles are looked up here. Peers too: what's replicated with a
|
||||
//! peer is its roles'. The file, every key and its default:
|
||||
//! peer is its roles'. Topics aren't listed anywhere else: one exists
|
||||
//! once a role let a message in. The file, every key and its default:
|
||||
//! `docs/config.md`.
|
||||
//!
|
||||
//! Every value is checked as serde reads it, so a wrong one is refused with
|
||||
@@ -80,9 +80,6 @@ pub struct Server {
|
||||
/// The SQLite database; `bakashrot.sqlite` by default.
|
||||
#[serde(default = "defaults::database")]
|
||||
pub database: PathBuf,
|
||||
/// The topics clients push to, by name.
|
||||
#[serde(default, deserialize_with = "values::topic_names")]
|
||||
pub topics: Vec<String>,
|
||||
/// How hard a push is made sure to be on disk.
|
||||
#[serde(default)]
|
||||
pub synchronous: Synchronous,
|
||||
@@ -100,13 +97,6 @@ pub struct Server {
|
||||
pub retention_interval: Duration,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
/// Whether `topic` is one of its topics.
|
||||
pub fn has_topic(&self, topic: &str) -> bool {
|
||||
self.topics.iter().any(|own| names_equal(own, topic))
|
||||
}
|
||||
}
|
||||
|
||||
/// How hard the database makes sure a push is on disk before answering it
|
||||
/// (SQLite's `synchronous`).
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize)]
|
||||
@@ -210,9 +200,6 @@ pub struct Replication {
|
||||
/// roles' `accept_*`.
|
||||
#[serde(deserialize_with = "values::hosts")]
|
||||
pub accept_from: Vec<String>,
|
||||
/// The only topics replicated at all, whatever the roles say (an edge
|
||||
/// node's filter); none: no filter.
|
||||
pub replicated_topics: Option<NameList>,
|
||||
/// How long to wait before dialing a peer again; 10s by default.
|
||||
#[serde(deserialize_with = "values::duration")]
|
||||
pub retry_delay: Duration,
|
||||
@@ -230,7 +217,6 @@ impl Default for Replication {
|
||||
Replication {
|
||||
push_to: Vec::new(),
|
||||
accept_from: Vec::new(),
|
||||
replicated_topics: None,
|
||||
retry_delay: Duration::from_secs(10),
|
||||
sync_interval: Duration::from_secs(5),
|
||||
batch_size: 1000,
|
||||
@@ -317,9 +303,6 @@ impl Config {
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
(!roles.is_empty()).then(|| Permissions {
|
||||
roles,
|
||||
replicated_topics: self.replication.replicated_topics.clone(),
|
||||
})
|
||||
(!roles.is_empty()).then_some(Permissions { roles })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ impl TryFrom<Vec<String>> for NameList {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(list: Vec<String>) -> Result<Self, String> {
|
||||
check_names(&list, true)?;
|
||||
check_names(&list)?;
|
||||
Ok(NameList(list))
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,14 @@ pub struct Role {
|
||||
/// Whether it may run read-only SQL, which reads every topic.
|
||||
#[serde(default)]
|
||||
pub query: bool,
|
||||
/// Whether listing topics answers every topic with messages, not only
|
||||
/// those it may push to or read.
|
||||
#[serde(default)]
|
||||
pub list_topics: bool,
|
||||
/// Whether listing nodes answers every node with messages, not only
|
||||
/// those of the topics it may read.
|
||||
#[serde(default)]
|
||||
pub list_nodes: bool,
|
||||
/// Replication: the topics sent to it.
|
||||
#[serde(default)]
|
||||
pub send_topics: NameList,
|
||||
@@ -77,12 +85,11 @@ pub struct Role {
|
||||
}
|
||||
|
||||
/// What a certificate may do: everything one of its roles allows, each role
|
||||
/// on its own (a role's topics go with that role's nodes), replication
|
||||
/// within the server's `replicated_topics`.
|
||||
/// on its own (a role's topics go with that role's nodes). The roles are
|
||||
/// all there is: no other list of topics.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Permissions {
|
||||
pub(crate) roles: Vec<Role>,
|
||||
pub(crate) replicated_topics: Option<NameList>,
|
||||
}
|
||||
|
||||
impl Permissions {
|
||||
@@ -110,22 +117,29 @@ impl Permissions {
|
||||
self.roles.iter().any(|role| role.query)
|
||||
}
|
||||
|
||||
/// Whether listing topics answers every one: `list_topics`, or
|
||||
/// `query` (which reads them all anyway).
|
||||
pub fn lists_every_topic(&self) -> bool {
|
||||
self.roles.iter().any(|role| role.list_topics || role.query)
|
||||
}
|
||||
|
||||
/// Whether listing nodes answers every one: `list_nodes`, or `query`.
|
||||
pub fn lists_every_node(&self) -> bool {
|
||||
self.roles.iter().any(|role| role.list_nodes || role.query)
|
||||
}
|
||||
|
||||
/// Whether `node`'s messages in `topic` are sent to it.
|
||||
pub fn sends(&self, topic: &str, node: &str) -> bool {
|
||||
self.replicated(topic)
|
||||
&& self
|
||||
.roles
|
||||
.iter()
|
||||
.any(|role| role.send_topics.matches(topic) && role.send_nodes.matches(node))
|
||||
self.roles
|
||||
.iter()
|
||||
.any(|role| role.send_topics.matches(topic) && role.send_nodes.matches(node))
|
||||
}
|
||||
|
||||
/// Whether `node`'s messages in `topic` are taken from it.
|
||||
pub fn accepts(&self, topic: &str, node: &str) -> bool {
|
||||
self.replicated(topic)
|
||||
&& self
|
||||
.roles
|
||||
.iter()
|
||||
.any(|role| role.accept_topics.matches(topic) && role.accept_nodes.matches(node))
|
||||
self.roles
|
||||
.iter()
|
||||
.any(|role| role.accept_topics.matches(topic) && role.accept_nodes.matches(node))
|
||||
}
|
||||
|
||||
/// The topics and the nodes taken from it, as `SyncState` lists them:
|
||||
@@ -158,10 +172,4 @@ impl Permissions {
|
||||
.iter()
|
||||
.any(|role| !role.send_topics.is_empty() || !role.accept_topics.is_empty())
|
||||
}
|
||||
|
||||
fn replicated(&self, topic: &str) -> bool {
|
||||
self.replicated_topics
|
||||
.as_ref()
|
||||
.is_none_or(|topics| topics.matches(topic))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! addresses, names.
|
||||
|
||||
use bakashrot_proto::limits::{MAX_ATTACHMENT_SIZE, MAX_MESSAGES_PER_PACKET};
|
||||
use bakashrot_proto::names::{is_valid_name, is_valid_name_or_pattern, names_equal};
|
||||
use bakashrot_proto::names::{is_valid_name_or_pattern, names_equal};
|
||||
use serde::de::Error as _;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::net::{Ipv6Addr, SocketAddr};
|
||||
@@ -184,23 +184,11 @@ pub(crate) fn batch_size<'de, D: Deserializer<'de>>(reader: D) -> Result<u32, D:
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
/// Topic names (no patterns), none twice.
|
||||
pub(crate) fn topic_names<'de, D: Deserializer<'de>>(reader: D) -> Result<Vec<String>, D::Error> {
|
||||
let names = Vec::<String>::deserialize(reader)?;
|
||||
check_names(&names, false).map_err(D::Error::custom)?;
|
||||
Ok(names)
|
||||
}
|
||||
|
||||
/// Checks a list of names (`patterns`: or patterns), none twice.
|
||||
pub(crate) fn check_names(list: &[String], patterns: bool) -> Result<(), String> {
|
||||
/// Checks a list of names or patterns, none twice.
|
||||
pub(crate) fn check_names(list: &[String]) -> Result<(), String> {
|
||||
for (at, entry) in list.iter().enumerate() {
|
||||
let (valid, what) = if patterns {
|
||||
(is_valid_name_or_pattern(entry), "a name or a pattern")
|
||||
} else {
|
||||
(is_valid_name(entry), "a name")
|
||||
};
|
||||
if !valid {
|
||||
return Err(format!("'{entry}' isn't {what} ({NAME_HELP})"));
|
||||
if !is_valid_name_or_pattern(entry) {
|
||||
return Err(format!("'{entry}' isn't a name or a pattern ({NAME_HELP})"));
|
||||
}
|
||||
if list[..at].iter().any(|before| names_equal(before, entry)) {
|
||||
return Err(format!("'{entry}' is given twice"));
|
||||
|
||||
@@ -37,9 +37,6 @@ fn the_example() {
|
||||
let server = &config.server;
|
||||
assert_eq!(server.listen, "0.0.0.0:7000".parse().unwrap());
|
||||
assert_eq!(server.crl, None);
|
||||
assert_eq!(server.topics.len(), 3);
|
||||
assert!(server.has_topic("Sensors.Kitchen"));
|
||||
assert!(!server.has_topic("sensors"));
|
||||
assert_eq!(server.synchronous, Synchronous::Full);
|
||||
assert_eq!(server.max_attachment_size, 1 << 30);
|
||||
assert_eq!(config.replication.push_to, Vec::<String>::new());
|
||||
@@ -59,7 +56,6 @@ fn defaults() {
|
||||
let config = Config::parse(MINIMAL).unwrap();
|
||||
let server = &config.server;
|
||||
assert_eq!(server.database, Path::new("bakashrot.sqlite"));
|
||||
assert!(server.topics.is_empty());
|
||||
assert_eq!(server.synchronous, Synchronous::Full);
|
||||
assert_eq!(server.max_attachment_size, 1 << 30);
|
||||
assert_eq!(server.retention_interval, Duration::from_secs(60));
|
||||
@@ -67,7 +63,6 @@ fn defaults() {
|
||||
assert_eq!(config.replication.retry_delay, Duration::from_secs(10));
|
||||
assert_eq!(config.replication.sync_interval, Duration::from_secs(5));
|
||||
assert_eq!(config.replication.batch_size, 1000);
|
||||
assert_eq!(config.replication.replicated_topics, None);
|
||||
assert!(config.roles.is_empty());
|
||||
assert!(config.permissions(&["anything"]).is_none());
|
||||
}
|
||||
@@ -87,7 +82,6 @@ accept_from = ["10.0.0.2", "server-3.lan", "fd00::4"]
|
||||
retry_delay = "1m"
|
||||
sync_interval = "2s"
|
||||
batch_size = 10000
|
||||
replicated_topics = ["logs"]
|
||||
"#,
|
||||
))
|
||||
.unwrap();
|
||||
@@ -170,7 +164,19 @@ accept_nodes = ["garage"]
|
||||
assert!(both.can_read("Logs"));
|
||||
assert!(!both.can_read("sensors.garage"));
|
||||
assert!(!both.can_query());
|
||||
assert!(config.permissions(&["admin"]).unwrap().can_query());
|
||||
assert!(!both.lists_every_topic() && !both.lists_every_node());
|
||||
let admin = config.permissions(&["admin"]).unwrap();
|
||||
assert!(admin.can_query());
|
||||
// A query reads them all anyway.
|
||||
assert!(admin.lists_every_topic() && admin.lists_every_node());
|
||||
let listing = Config::parse(&with(
|
||||
"[roles.a]\nlist_topics = true\n[roles.b]\nlist_nodes = true\n",
|
||||
))
|
||||
.unwrap();
|
||||
let a = listing.permissions(&["a"]).unwrap();
|
||||
assert!(a.lists_every_topic() && !a.lists_every_node() && !a.can_query());
|
||||
let b = listing.permissions(&["b", "a"]).unwrap();
|
||||
assert!(b.lists_every_topic() && b.lists_every_node());
|
||||
|
||||
// Replication: each role's topics with that role's nodes, not mixed.
|
||||
let peer = config.permissions(&["peer", "backup"]).unwrap();
|
||||
@@ -191,41 +197,13 @@ accept_nodes = ["garage"]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replicated_topics_filter_the_roles() {
|
||||
let config = Config::parse(&with(
|
||||
r#"
|
||||
[replication]
|
||||
replicated_topics = ["logs", "alerts.*"]
|
||||
|
||||
[roles.peer]
|
||||
send_topics = ["*"]
|
||||
accept_topics = ["*"]
|
||||
|
||||
[roles.sensor]
|
||||
push_topics = ["*"]
|
||||
"#,
|
||||
))
|
||||
.unwrap();
|
||||
let peer = config.permissions(&["peer", "sensor"]).unwrap();
|
||||
assert!(peer.sends("logs", "kitchen") && peer.accepts("Logs", "kitchen"));
|
||||
assert!(peer.sends("alerts.fire", "kitchen"));
|
||||
assert!(!peer.sends("sensors.a", "kitchen") && !peer.accepts("sensors.a", "kitchen"));
|
||||
assert!(peer.replicates());
|
||||
// Only replication: pushing isn't filtered.
|
||||
assert!(peer.can_push("sensors.a"));
|
||||
|
||||
// Empty: nothing replicated.
|
||||
let none = Config::parse(&with(
|
||||
"[replication]\nreplicated_topics = []\n[roles.peer]\nsend_topics = [\"*\"]\n",
|
||||
))
|
||||
.unwrap();
|
||||
fn topics_are_only_in_the_roles() {
|
||||
// No list of topics beside the roles': the old keys are refused.
|
||||
assert!(refused(&with("topics = [\"logs\"]\n")).contains("unknown field `topics`"));
|
||||
assert!(
|
||||
!none
|
||||
.permissions(&["peer"])
|
||||
.unwrap()
|
||||
.sends("logs", "kitchen")
|
||||
refused(&with("[replication]\nreplicated_topics = [\"logs\"]\n"))
|
||||
.contains("unknown field `replicated_topics`")
|
||||
);
|
||||
assert!(refused(&with("[replication]\nreplicated_topics = [\"a b\"]\n")).contains("'a b'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -272,16 +250,6 @@ fn refusals() {
|
||||
&MINIMAL.replace("127.0.0.1:7000", "127.0.0.1"),
|
||||
"'127.0.0.1' isn't an address and a port",
|
||||
),
|
||||
(&with("topics = [\"a b\"]\n"), "'a b' isn't a name ("),
|
||||
(
|
||||
&with("topics = [\"sensors.*\"]\n"),
|
||||
"'sensors.*' isn't a name (",
|
||||
),
|
||||
(&with("topics = [\"12\"]\n"), "'12' isn't a name"),
|
||||
(
|
||||
&with("topics = [\"logs\", \"Logs\"]\n"),
|
||||
"'Logs' is given twice",
|
||||
),
|
||||
(
|
||||
&with("synchronous = \"OFF\"\n"),
|
||||
"isn't allowed: a power loss",
|
||||
|
||||
@@ -23,19 +23,12 @@ pub use revocation::{Revocations, SharedRevocations, serial};
|
||||
use std::fmt;
|
||||
use x509_parser::certificate::X509Certificate;
|
||||
|
||||
/// The identity extension's OID.
|
||||
///
|
||||
/// **A placeholder** ([`IDENTITY_OID_IS_PLACEHOLDER`]): under PEN 32473,
|
||||
/// which RFC 5612 reserves for documentation. Replace it with one under
|
||||
/// NibblePoker's own PEN once IANA gave it (`docs/oid.md`), before
|
||||
/// issuing certificates for real: certificates made with this one stop
|
||||
/// being read once it changes.
|
||||
pub const IDENTITY_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 32473, 1, 1];
|
||||
|
||||
/// Whether [`IDENTITY_OID`] is still the placeholder: `bakashrot-cert`
|
||||
/// warns when it makes a CA or a certificate then. Set it to `false` with
|
||||
/// the real OID.
|
||||
pub const IDENTITY_OID_IS_PLACEHOLDER: bool = true;
|
||||
/// The identity extension's OID: `1.3.6.1.4.1.67681.1.1`, under
|
||||
/// NibblePoker's Private Enterprise Number (67681, from IANA), BakaShrot's
|
||||
/// branch (`.1`), its identity extension (`.1`). `docs/oid.md` has the
|
||||
/// branches. It never changes: certificates made with another one aren't
|
||||
/// read (those of 0.2.0 and before had a placeholder).
|
||||
pub const IDENTITY_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 67681, 1, 1];
|
||||
|
||||
/// The DNS name every server certificate has, and every client asks for:
|
||||
/// a label, not a host. Servers are known by their certificate, wherever
|
||||
|
||||
@@ -67,7 +67,7 @@ macro_rules! error_codes {
|
||||
error_codes! {
|
||||
// Refused by the server: the connection is still open.
|
||||
NotAllowed = 1, "Not allowed to this client: its roles' permissions, or a request only peers may make.";
|
||||
UnknownName = 2, "A topic or node this server doesn't know.";
|
||||
UnknownName = 2, "A node this server has no message of.";
|
||||
NotFound = 3, "No such message or attachment.";
|
||||
NotReady = 4, "The attachment isn't on this server yet (still being replicated).";
|
||||
TooBig = 5, "A message, attachment or query result over a limit, or an attachment bigger than this server keeps.";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//! field names is taken too, `serde`'s derive: nothing writes that form, it
|
||||
//! isn't part of the format, its values are checked all the same.) Whatever isn't right is a
|
||||
//! [`DecodeError`]: the connection is aborted. What's well-formed but not
|
||||
//! allowed or not found (a topic this server doesn't have) is the server's
|
||||
//! allowed or not found (a node without messages) is the server's
|
||||
//! to refuse, with a `RequestRefused`.
|
||||
//!
|
||||
//! Topics and nodes are names everywhere, never ids.
|
||||
|
||||
@@ -35,6 +35,10 @@ const IDLE_TIMEOUT: Duration = Duration::from_secs(300);
|
||||
/// How long an attachment's next part may take to come.
|
||||
const PART_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// How long a packet may take to be sent (an attachment's part is 1 MiB):
|
||||
/// a client that stopped reading is dropped rather than waited for.
|
||||
pub(crate) const SEND_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// An upload's parts given to the writer and not written yet, at most: the
|
||||
/// next ones wait (the client with them, through TCP).
|
||||
const PARTS_IN_FLIGHT: usize = 4;
|
||||
@@ -219,12 +223,6 @@ async fn push(
|
||||
frames: &mut Frames,
|
||||
push: PushMessage,
|
||||
) -> Result<Packet, String> {
|
||||
if !shared.config.server.has_topic(&push.topic) {
|
||||
return Ok(refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", push.topic),
|
||||
));
|
||||
}
|
||||
if !peer.permissions.can_push(&push.topic) {
|
||||
return Ok(refused(
|
||||
ErrorCode::NotAllowed,
|
||||
@@ -378,12 +376,6 @@ async fn get_attachment(
|
||||
format!("{} may not read '{}'", peer.node, get.topic),
|
||||
)));
|
||||
}
|
||||
if !shared.config.server.has_topic(&get.topic) {
|
||||
return Ok(Some(refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", get.topic),
|
||||
)));
|
||||
}
|
||||
let message = format!("{}:{}#{}", get.topic, get.node, get.message_id);
|
||||
let GetAttachment {
|
||||
topic,
|
||||
@@ -462,12 +454,6 @@ async fn get_messages(shared: &Arc<Shared>, peer: &Peer, get: GetMessages) -> Pa
|
||||
format!("{} may not read '{}'", peer.node, get.topic),
|
||||
);
|
||||
}
|
||||
if !shared.config.server.has_topic(&get.topic) {
|
||||
return refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", get.topic),
|
||||
);
|
||||
}
|
||||
let GetMessages {
|
||||
topic,
|
||||
node,
|
||||
@@ -490,26 +476,41 @@ async fn get_messages(shared: &Arc<Shared>, peer: &Peer, get: GetMessages) -> Pa
|
||||
}
|
||||
}
|
||||
|
||||
/// Topics: the server's, those it may push to or read unless it may query
|
||||
/// (queries read everything). Nodes: every one with messages.
|
||||
/// Topics: those with messages (pushed here or replicated) that it may
|
||||
/// push to or read; every one with `list_topics` or `query`. Nodes: those
|
||||
/// with messages in the topics it may read; every one with `list_nodes`
|
||||
/// or `query`.
|
||||
async fn list_names(shared: &Arc<Shared>, peer: &Peer, list: ListNames) -> Packet {
|
||||
let mut names = match list.kind {
|
||||
let permissions = &peer.permissions;
|
||||
let found = match list.kind {
|
||||
NameKind::Topic => shared
|
||||
.config
|
||||
.server
|
||||
.topics
|
||||
.iter()
|
||||
.filter(|topic| {
|
||||
peer.permissions.can_query()
|
||||
|| peer.permissions.can_push(topic)
|
||||
|| peer.permissions.can_read(topic)
|
||||
})
|
||||
.cloned()
|
||||
.collect(),
|
||||
NameKind::Node => match shared.read(|reader| reader.nodes()).await {
|
||||
Ok(nodes) => nodes,
|
||||
Err(refused) => return refused.into(),
|
||||
},
|
||||
.read(|reader| reader.topics())
|
||||
.await
|
||||
.map(|mut topics| {
|
||||
if !permissions.lists_every_topic() {
|
||||
topics
|
||||
.retain(|topic| permissions.can_push(topic) || permissions.can_read(topic));
|
||||
}
|
||||
topics
|
||||
}),
|
||||
NameKind::Node if permissions.lists_every_node() => {
|
||||
shared.read(|reader| reader.nodes()).await
|
||||
}
|
||||
NameKind::Node => shared.read(|reader| reader.heads()).await.map(|heads| {
|
||||
let mut nodes: Vec<String> = heads
|
||||
.into_iter()
|
||||
.filter(|head| permissions.can_read(&head.topic))
|
||||
.map(|head| head.node)
|
||||
.collect();
|
||||
// As `reader.nodes()` answers them: in order, none twice.
|
||||
nodes.sort_by_cached_key(|node| node.to_ascii_lowercase());
|
||||
nodes.dedup_by(|a, b| names_equal(a, b));
|
||||
nodes
|
||||
}),
|
||||
};
|
||||
let mut names = match found {
|
||||
Ok(names) => names,
|
||||
Err(refused) => return refused.into(),
|
||||
};
|
||||
let truncated = names.len() > MAX_NAMES_LIST_ENTRIES;
|
||||
names.truncate(MAX_NAMES_LIST_ENTRIES);
|
||||
@@ -538,6 +539,18 @@ pub(crate) fn refused(code: ErrorCode, reason: String) -> Packet {
|
||||
RequestRefused::new(code, reason).into()
|
||||
}
|
||||
|
||||
/// Sends a packet, within [`SEND_TIMEOUT`]: an error closes the connection.
|
||||
pub(crate) async fn send(frames: &mut Frames, packet: Packet) -> std::io::Result<()> {
|
||||
frames.send(bytes::Bytes::from(packet.encode())).await
|
||||
match timeout(
|
||||
SEND_TIMEOUT,
|
||||
frames.send(bytes::Bytes::from(packet.encode())),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(sent) => sent,
|
||||
Err(_) => Err(std::io::Error::new(
|
||||
std::io::ErrorKind::TimedOut,
|
||||
"too slow to take an answer",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//! `send_*` allow. `accept_from.rs` is the other end.
|
||||
|
||||
use crate::Shared;
|
||||
use crate::connection::SEND_TIMEOUT;
|
||||
use crate::writer::Write;
|
||||
use bakashrot_config::Permissions;
|
||||
use bakashrot_pki::tls;
|
||||
@@ -297,10 +298,11 @@ impl Link {
|
||||
}
|
||||
|
||||
async fn send(&mut self, packet: Packet) -> Result<(), String> {
|
||||
self.frames
|
||||
.send(bytes::Bytes::from(packet.encode()))
|
||||
.await
|
||||
.map_err(|error| error.to_string())
|
||||
let sending = self.frames.send(bytes::Bytes::from(packet.encode()));
|
||||
match timeout(SEND_TIMEOUT, sending).await {
|
||||
Ok(sent) => sent.map_err(|error| error.to_string()),
|
||||
Err(_) => Err("too slow to take a packet".into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn receive(&mut self) -> Result<Packet, String> {
|
||||
|
||||
@@ -28,7 +28,6 @@ ca = "ca.crt"
|
||||
certificate = "server.crt"
|
||||
key = "server.key"
|
||||
crl = "ca.crl"
|
||||
topics = ["logs", "sensors"]
|
||||
|
||||
[roles.sensor]
|
||||
push_topics = ["logs", "sensors"]
|
||||
@@ -42,6 +41,10 @@ read_topics = ["logs"]
|
||||
[roles.analyst]
|
||||
query = true
|
||||
|
||||
[roles.explorer]
|
||||
list_topics = true
|
||||
list_nodes = true
|
||||
|
||||
[roles.peer]
|
||||
send_topics = ["*"]
|
||||
accept_topics = ["*"]
|
||||
@@ -237,9 +240,10 @@ fn refusals_keep_the_connection() {
|
||||
refused(reader.push("logs", "{}")),
|
||||
ErrorCode::NotAllowed.code()
|
||||
);
|
||||
// A topic is its roles': one that none of them names.
|
||||
assert_eq!(
|
||||
refused(sensor.push("nope", "{}")),
|
||||
ErrorCode::UnknownName.code()
|
||||
ErrorCode::NotAllowed.code()
|
||||
);
|
||||
// The client checks names before sending.
|
||||
assert_eq!(
|
||||
@@ -487,9 +491,13 @@ fn runs_of_messages() {
|
||||
refused(screen.get_messages("sensors", "kitchen", None, 1)),
|
||||
ErrorCode::NotAllowed.code()
|
||||
);
|
||||
assert_eq!(
|
||||
refused(kitchen.get_messages("nothing", "kitchen", None, 1)),
|
||||
ErrorCode::UnknownName.code()
|
||||
// A topic without messages: none, for a node that has some elsewhere.
|
||||
assert!(
|
||||
kitchen
|
||||
.get_messages("nothing", "kitchen", None, 1)
|
||||
.unwrap()
|
||||
.messages
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
refused(kitchen.get_messages("logs", "nobody", None, 1)),
|
||||
@@ -600,8 +608,24 @@ fn names() {
|
||||
assert_eq!(names(&mut sensor, NameKind::Topic), ["logs", "sensors"]);
|
||||
assert_eq!(names(&mut screen, NameKind::Topic), ["logs"]);
|
||||
assert_eq!(names(&mut analyst, NameKind::Topic), ["logs", "sensors"]);
|
||||
// Nodes: every one with messages.
|
||||
assert_eq!(names(&mut screen, NameKind::Node), ["garage", "kitchen"]);
|
||||
// Nodes: those of the topics it may read; every one for a query role.
|
||||
assert!(names(&mut sensor, NameKind::Node).is_empty());
|
||||
assert_eq!(names(&mut screen, NameKind::Node), ["kitchen"]);
|
||||
assert_eq!(names(&mut analyst, NameKind::Node), ["garage", "kitchen"]);
|
||||
// `list_topics` and `list_nodes`: every one, without reading any.
|
||||
let mut explorer = running
|
||||
.connect(&running.issue("browser", &["explorer"]))
|
||||
.unwrap();
|
||||
assert_eq!(names(&mut explorer, NameKind::Topic), ["logs", "sensors"]);
|
||||
assert_eq!(names(&mut explorer, NameKind::Node), ["garage", "kitchen"]);
|
||||
assert_eq!(
|
||||
code(
|
||||
explorer
|
||||
.get_messages("logs", "kitchen", None, 1)
|
||||
.unwrap_err()
|
||||
),
|
||||
ErrorCode::NotAllowed.code()
|
||||
);
|
||||
}
|
||||
|
||||
/// The query parts of `OldSource/Tests/BigMessages-Test.ps1`.
|
||||
@@ -746,7 +770,7 @@ fn attachments() {
|
||||
let error = kitchen
|
||||
.get_attachment("nothing", "kitchen", 1, &mut Vec::new())
|
||||
.unwrap_err();
|
||||
assert_eq!(error.code(), ErrorCode::UnknownName.code(), "{error}");
|
||||
assert_eq!(error.code(), ErrorCode::NotFound.code(), "{error}");
|
||||
let mut logs_only = running
|
||||
.connect(&running.issue("lounge", &["logs"]))
|
||||
.unwrap();
|
||||
@@ -1511,6 +1535,42 @@ fn replication_edges() {
|
||||
raw.refused(ErrorCode::DataMismatch);
|
||||
assert_eq!(sync_state(&mut raw).missing[0].next_part, 0);
|
||||
|
||||
// A topic nobody pushed here: it's there from its first replicated
|
||||
// message, read and listed by the roles that name it.
|
||||
raw.send(ReplicateMessages {
|
||||
topic: "elsewhere".into(),
|
||||
node: "far".into(),
|
||||
messages: vec![message(1, now, None)],
|
||||
});
|
||||
assert_eq!(raw.receive(), Some(MessagePushed { message_id: 1 }.into()));
|
||||
let mut reader = running
|
||||
.connect(&running.issue("screen", &["reader"]))
|
||||
.unwrap();
|
||||
let got = reader
|
||||
.get_messages("elsewhere", "far", Some(0), 10)
|
||||
.unwrap();
|
||||
assert_eq!(got.messages[0].data, "m1");
|
||||
// (`old` had a message, past its age.)
|
||||
assert_eq!(
|
||||
reader.list_names(NameKind::Topic).unwrap().names,
|
||||
["elsewhere", "logs", "old"]
|
||||
);
|
||||
let mut logs_only = running
|
||||
.connect(&running.issue("lounge", &["logs"]))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
logs_only.list_names(NameKind::Topic).unwrap().names,
|
||||
["logs"]
|
||||
);
|
||||
assert_eq!(
|
||||
code(
|
||||
logs_only
|
||||
.get_messages("elsewhere", "far", Some(0), 10)
|
||||
.unwrap_err()
|
||||
),
|
||||
ErrorCode::NotAllowed.code()
|
||||
);
|
||||
|
||||
// A certificate whose roles take nothing: refused.
|
||||
let mut other = Raw::connect(&running, &running.issue("nosy", &["reader"]));
|
||||
let state = sync_state(&mut other);
|
||||
|
||||
@@ -16,8 +16,9 @@ bakashrot-proto = { path = "../bakashrot-proto" }
|
||||
bakashrot-config = { path = "../bakashrot-config" }
|
||||
# SQLite itself compiled in (`bundled`): the same version everywhere, with
|
||||
# its JSON functions, no system library to install. `fallible_uint`: u64
|
||||
# in and out, an error past i64::MAX instead of a wrap.
|
||||
rusqlite = { version = "0.42.0", features = ["bundled", "fallible_uint"] }
|
||||
# in and out, an error past i64::MAX instead of a wrap. `hooks`: the
|
||||
# authorizer that refuses PRAGMAs in clients' queries.
|
||||
rusqlite = { version = "0.42.0", features = ["bundled", "fallible_uint", "hooks"] }
|
||||
# Query results as JSON.
|
||||
serde_json = "1.0.154"
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::{Error, QueryRunner, Reader, Result, SCHEMA_VERSION, Writer};
|
||||
use bakashrot_config::Synchronous;
|
||||
use rusqlite::hooks::{AuthAction, AuthContext, Authorization};
|
||||
use rusqlite::{Connection, OptionalExtension, TransactionBehavior};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
@@ -126,10 +127,18 @@ impl Database {
|
||||
Ok(Reader::new(self.connect()?))
|
||||
}
|
||||
|
||||
/// A connection for clients' queries: read-only (`query_only`).
|
||||
/// A connection for clients' queries: read-only (`query_only`), and
|
||||
/// every PRAGMA refused from then on (SQLite's authorizer). Some take
|
||||
/// effect when they're prepared, before a statement can be refused
|
||||
/// for what it is: `PRAGMA query_only = 0` turned `query_only` off
|
||||
/// for the connection's next queries.
|
||||
pub fn query_runner(&self) -> Result<QueryRunner> {
|
||||
let connection = self.connect()?;
|
||||
let mut connection = self.connect()?;
|
||||
connection.pragma_update(None, "query_only", true)?;
|
||||
connection.authorizer(Some(|context: AuthContext<'_>| match context.action {
|
||||
AuthAction::Pragma { .. } => Authorization::Deny,
|
||||
_ => Authorization::Allow,
|
||||
}))?;
|
||||
Ok(QueryRunner::new(connection))
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
//! Read-only three ways: the connection has `query_only` on (SQLite
|
||||
//! refuses any write), the statement must be one SQLite says only reads
|
||||
//! (`sqlite3_stmt_readonly`), and only one statement runs (more is an
|
||||
//! error, not ignored). The result is JSON, every value a string or null
|
||||
//! error, not ignored). PRAGMAs are refused as they're prepared
|
||||
//! (`Database::query_runner`'s authorizer): some would change the
|
||||
//! connection, `query_only` included, before the statement is looked
|
||||
//! at. The result is JSON, every value a string or null
|
||||
//! (as in protocol 6): `{"columns":[...],"rows":[[...],...]}`.
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
@@ -702,6 +702,25 @@ fn queries() {
|
||||
] {
|
||||
assert!(matches!(runner.run(sql), Err(Error::Query(_))), "{sql}");
|
||||
}
|
||||
// PRAGMAs are refused as they're prepared, reading ones too: one that
|
||||
// changes the connection would have by the time it's looked at.
|
||||
for sql in [
|
||||
"PRAGMA query_only = 0",
|
||||
"PRAGMA query_only",
|
||||
"PRAGMA locking_mode = EXCLUSIVE",
|
||||
"PRAGMA database_list",
|
||||
"SELECT * FROM pragma_database_list",
|
||||
] {
|
||||
match runner.run(sql) {
|
||||
Err(Error::Query(why)) => assert!(why.contains("not authorized"), "{sql}: {why}"),
|
||||
other => panic!("{sql}: {other:?}"),
|
||||
}
|
||||
}
|
||||
// Still read-only, still answering.
|
||||
assert_eq!(
|
||||
json("SELECT count(*) FROM messages")["rows"],
|
||||
serde_json::json!([["3"]])
|
||||
);
|
||||
// A failing row fails it all, with SQLite's message.
|
||||
match runner.run("SELECT message_data ->> '$.t' FROM messages") {
|
||||
Err(Error::Query(why)) => assert!(why.contains("malformed JSON"), "{why}"),
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
//! them. Every file is PEM; keys are written once, never over an existing
|
||||
//! file. See `docs/certificates.md`.
|
||||
|
||||
use bakashrot_pki::{
|
||||
CA_DAYS, CERTIFICATE_DAYS, Ca, IDENTITY_OID_IS_PLACEHOLDER, Identity, Revocations, Usage,
|
||||
summarize,
|
||||
};
|
||||
use bakashrot_pki::{CA_DAYS, CERTIFICATE_DAYS, Ca, Identity, Revocations, Usage, summarize};
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
@@ -98,15 +95,7 @@ fn main() -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Said whenever a certificate is made while the OID is the placeholder.
|
||||
const PLACEHOLDER_WARNING: &str = "warning: the identity extension's OID is still a placeholder \
|
||||
(docs/oid.md): fine for tests, not for certificates in use";
|
||||
|
||||
fn run(command: Command) -> Result<(), String> {
|
||||
if IDENTITY_OID_IS_PLACEHOLDER && matches!(command, Command::Ca { .. } | Command::Issue { .. })
|
||||
{
|
||||
eprintln!("{PLACEHOLDER_WARNING}");
|
||||
}
|
||||
match command {
|
||||
Command::Ca { name, days, out } => {
|
||||
let ca = Ca::create(&name, days).map_err(|e| e.to_string())?;
|
||||
|
||||
@@ -101,8 +101,8 @@ enum Command {
|
||||
/// standard input's.
|
||||
sql: String,
|
||||
},
|
||||
/// Lists the topics this client may use (every one if it may query) and
|
||||
/// the nodes with messages.
|
||||
/// Lists the topics this client may use and the nodes of those it may
|
||||
/// read; every one if its roles have list_topics / list_nodes, or query.
|
||||
List {
|
||||
/// What to list.
|
||||
#[arg(value_enum, default_value_t = What::All)]
|
||||
|
||||
@@ -18,7 +18,6 @@ listen = "127.0.0.1:0"
|
||||
ca = "ca.crt"
|
||||
certificate = "server.crt"
|
||||
key = "server.key"
|
||||
topics = ["logs", "secret"]
|
||||
synchronous = "normal"
|
||||
|
||||
[roles.home]
|
||||
@@ -214,7 +213,7 @@ fn pushes_and_latest() {
|
||||
server
|
||||
.tool("lounge", &["push", "logs", "{}"])
|
||||
.fails(1, "Refused by the server (NotAllowed)");
|
||||
push(&["nope", "{}"]).fails(1, "Refused by the server (UnknownName): ");
|
||||
push(&["nope", "{}"]).fails(1, "Refused by the server (NotAllowed): ");
|
||||
push(&["bad name!", "{}"]).fails(1, "Failed (InvalidArgument)");
|
||||
push(&["logs", "@missing.json"]).fails(1, "Can't read missing.json");
|
||||
let big = "x".repeat(bakashrot_proto::limits::MAX_MESSAGE_SIZE + 1);
|
||||
@@ -319,7 +318,13 @@ fn messages() {
|
||||
assert_eq!(messages("kitchen", &["secret", "kitchen"]).ok().ids(), [1]);
|
||||
messages("lounge", &["secret", "kitchen"]).fails(1, "(NotAllowed)");
|
||||
messages("kitchen", &["logs", "nobody"]).fails(1, "(UnknownName)");
|
||||
messages("kitchen", &["nothing", "kitchen"]).fails(1, "(UnknownName)");
|
||||
assert!(
|
||||
messages("kitchen", &["nothing", "kitchen"])
|
||||
.ok()
|
||||
.out
|
||||
.is_empty(),
|
||||
"a topic without messages"
|
||||
);
|
||||
assert!(
|
||||
messages("lounge", &["logs", "lounge"]).ok().out.is_empty(),
|
||||
"its own node, none yet"
|
||||
@@ -448,10 +453,7 @@ fn queries_and_lists() {
|
||||
.fails(1, "(QueryFailed)");
|
||||
|
||||
let all = server.tool("kitchen", &["list"]);
|
||||
assert_eq!(
|
||||
all.ok().out,
|
||||
"Topics (2):\n logs\n secret\nNodes (1):\n kitchen\n"
|
||||
);
|
||||
assert_eq!(all.ok().out, "Topics (1):\n logs\nNodes (1):\n kitchen\n");
|
||||
assert_eq!(
|
||||
server.tool("lounge", &["list", "topics"]).ok().out,
|
||||
"Topics (1):\n logs\n"
|
||||
@@ -534,7 +536,7 @@ fn settings() {
|
||||
&["list", "topics"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(up.ok().out, "Topics (2):\n logs\n secret\n");
|
||||
assert_eq!(up.ok().out, "Topics (0):\n");
|
||||
|
||||
let kitchen = fs::read_to_string(folder.join("kitchen.toml")).unwrap();
|
||||
fs::write(
|
||||
|
||||
@@ -36,9 +36,6 @@ fn a_ca_issues_and_revokes() {
|
||||
let folder = folder("cert-tool");
|
||||
let (ok, text) = cert(&folder, &["ca", "--name", "Test CA"]);
|
||||
assert!(ok, "{text}");
|
||||
if bakashrot_pki::IDENTITY_OID_IS_PLACEHOLDER {
|
||||
assert!(text.contains("OID is still a placeholder"), "{text}");
|
||||
}
|
||||
assert!(
|
||||
cert(
|
||||
&folder,
|
||||
|
||||
@@ -37,7 +37,6 @@ ca = "ca.crt"
|
||||
certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
database = "/var/lib/bakashrot/test.sqlite"
|
||||
topics = ["imagetest"]
|
||||
|
||||
[roles.tester]
|
||||
push_topics = ["imagetest"]
|
||||
|
||||
@@ -28,10 +28,9 @@ is a CRL file from the CA, pushed to the servers.
|
||||
Names and roles follow the name rules (1-64 of `A-Z a-z 0-9 _ . -`, not
|
||||
only digits), 64 roles at most. Roles mean nothing to the certificates:
|
||||
the server's config says what each may do.
|
||||
- **Its OID is a placeholder** (`IDENTITY_OID`, `1.3.6.1.4.1.32473.1.1`,
|
||||
under the PEN RFC 5612 reserves for documentation; `bakashrot-cert`
|
||||
warns while it is): it goes under NibblePoker's own PEN before
|
||||
certificates are issued for real. Why, how to request it, what to change:
|
||||
- **Its OID is `1.3.6.1.4.1.67681.1.1`** (`IDENTITY_OID`), under
|
||||
NibblePoker's own PEN (67681), since 0.3.0. Certificates made before
|
||||
(a placeholder OID) aren't read: issue them again. The branches:
|
||||
`oid.md`.
|
||||
- **The CN is the name too**, for people (`openssl x509 -text`, logs). Only
|
||||
the extension is trusted.
|
||||
@@ -132,4 +131,3 @@ Unix. `revoke` only takes certificates the CA issued.
|
||||
- **`AllowedServerNames`** in a client's config and for the peers a
|
||||
server dials: the server names it accepts (any of the CA's servers
|
||||
without it).
|
||||
- NibblePoker's PEN, replacing the placeholder OID (`oid.md`).
|
||||
|
||||
+20
-8
@@ -10,9 +10,9 @@ Decided in `../revamp.md`, "Decided".
|
||||
|
||||
| Section | What |
|
||||
|---|---|
|
||||
| `[server]` | where it listens, the certificate files, the database, its topics, how pushes are flushed, attachments, retention's pace |
|
||||
| `[server]` | where it listens, the certificate files, the database, how pushes are flushed, attachments, retention's pace |
|
||||
| `[retention]` | how long each topic's messages are kept |
|
||||
| `[replication]` | the servers it sends to and takes from, the topics replicated at all, retry and sync pace, batch size |
|
||||
| `[replication]` | the servers it sends to and takes from, retry and sync pace, batch size |
|
||||
| `[roles.<name>]` | what certificates with that role may do |
|
||||
|
||||
Unknown keys are refused, so a typo or a key of the old ini is caught.
|
||||
@@ -37,14 +37,28 @@ What a role gives:
|
||||
| `push_topics` | none | pushing to these topics, always as its own node |
|
||||
| `read_topics` | none | reading these topics' messages |
|
||||
| `query` | `false` | read-only SQL, which reads every topic |
|
||||
| `list_topics` | `false` | listing topics answers every one with messages, not only those it may push to or read |
|
||||
| `list_nodes` | `false` | listing nodes answers every one with messages, not only those of the topics it may read |
|
||||
| `send_topics` | none | replication: these topics sent to it |
|
||||
| `accept_topics` | none | replication: these topics taken from it |
|
||||
| `send_nodes` | `["*"]` | replication: only these nodes' messages sent |
|
||||
| `accept_nodes` | `["*"]` | replication: only these nodes' messages taken |
|
||||
|
||||
`list_topics` and `list_nodes` (2026-11-16) only give names, for a tool
|
||||
that browses a server: reading a topic is still `read_topics`. `query`
|
||||
gives both, it reads everything anyway.
|
||||
|
||||
No `AllowRead` / `AllowWrite`: a list that's empty allows nothing. No
|
||||
default topic: a push always names its topic (protocol 7 has none).
|
||||
|
||||
**The roles are the only lists of topics** (decided 2026-11-16): no
|
||||
`[server] topics`, no `[replication] replicated_topics`, both refused as
|
||||
unknown keys. A topic exists from its first message, pushed by a client
|
||||
whose `push_topics` name it or taken from a peer whose `accept_topics`
|
||||
do; it's then read, listed, sent on and aged like any other, each by the
|
||||
roles that name it. A pattern (`push_topics = ["sensors.*"]`) lets its
|
||||
clients make topics: names for a closed set.
|
||||
|
||||
## Peers
|
||||
|
||||
Who replicates with whom is each server's config, by address (not the
|
||||
@@ -62,10 +76,8 @@ dialed takes them. What's sent and taken is still the roles': the other
|
||||
server's certificate's roles here, their `send_*` for what's sent to it,
|
||||
their `accept_*` for what's taken from it.
|
||||
|
||||
`[replication] replicated_topics`, optional, filters every peer's
|
||||
replication whatever its roles say: an edge node that keeps some topics to
|
||||
itself. Without it, no filter; `[]` replicates nothing. Pushing and reading
|
||||
aren't filtered.
|
||||
An edge node that keeps some topics to itself leaves them out of its
|
||||
peers' `send_topics`.
|
||||
|
||||
## Names and values
|
||||
|
||||
@@ -95,7 +107,7 @@ server; each server has its own.
|
||||
| `PrivateKey`, `[BakaShrot] Node` | `ca`, `certificate`, `key`: the node is the certificate's name |
|
||||
| `[BakaShrot.Client.*]`: keys, `Node`, `Allow*` | `[roles.*]`, the node and roles from the certificate |
|
||||
| `[BakaShrot.Peer.*]`: `Host`, `Port`, `Node`, `PublicKey`, topic and node lists | `[replication] push_to` and `accept_from` (addresses), the lists in the peer's roles |
|
||||
| `ReplicatingTopics` | each peer role's `send_topics` / `accept_topics`; `replicated_topics` filters them all |
|
||||
| `ReplicatingTopics` | each peer role's `send_topics` / `accept_topics` |
|
||||
| topic and node ids, pins, ranges, `[BakaShrot.Nodes]` | names only: ids are the database's |
|
||||
| `DefaultTopic` | dropped: a push always names its topic |
|
||||
| `Host` + `Port` | `listen` |
|
||||
@@ -108,7 +120,7 @@ server; each server has its own.
|
||||
|
||||
`crates/bakashrot-config/tests/config.rs`: the example, the defaults,
|
||||
every setting, retention's order, permissions (several roles, none known,
|
||||
replication per role), `replicated_topics`, paths from the config's
|
||||
replication per role), the topic lists that are gone, paths from the config's
|
||||
folder, and the refusals, each with its line: TOML errors, unknown keys
|
||||
(the old ini's too), every value that's wrong, names twice (without case),
|
||||
unquoted dotted names.
|
||||
|
||||
@@ -50,6 +50,96 @@ network**, not exposed to the internet. So:
|
||||
between committing and answering) is stored twice if retried. A client
|
||||
that minds reads the latest message before retrying.
|
||||
|
||||
## Found by reading the code, not reproduced
|
||||
|
||||
From a read of the source on 2026-11-15: no test shows any of these yet.
|
||||
Reproduce one before fixing it, and move it up (or drop it) once known.
|
||||
|
||||
- **`sync_interval` over 5 min.** The server dialed closes the idle link
|
||||
(`IDLE_TIMEOUT`), so every check-in fails once ("closed the link",
|
||||
warned), then the link is dialed again after `retry_delay`. Nothing
|
||||
in the config caps `sync_interval`. Fix: cap it under the idle
|
||||
timeout, or have an idle link ask its `SyncState` more often.
|
||||
- **Resuming a big replicated attachment.** Before answering `Continue`,
|
||||
the receiver reads back and hashes every part it already has
|
||||
(`accept_from.rs`, `replicate_attachment`, `hash_parts`), while the
|
||||
sender waits 30 s for that answer (`push_to.rs`, `ANSWER_TIMEOUT`). On
|
||||
a slow disk, hundreds of parts may take longer: the link drops, and
|
||||
the same happens at every retry. Fix: a longer wait for that answer,
|
||||
or the hash's state kept with the attachment.
|
||||
- **Two peers sending the same attachment at once.** Both can be
|
||||
answered `Continue` for the same `from_part` (the check and the first
|
||||
part written aren't one step). Their parts then interleave in the
|
||||
writer's queue: each part is stored once, from whichever came first,
|
||||
and each sender has one refused (`InvalidRequest`). With few parts (4
|
||||
or fewer in flight, `PARTS_IN_FLIGHT`), all of them can be stored
|
||||
while both senders were refused: neither sends `FinishReplicated`,
|
||||
and the attachment stays `replicating` with `received = size`, asked
|
||||
for and refused at every check-in until a restart (`clean_up` starts
|
||||
it over). Needs two parts at least and a narrow timing: servers that
|
||||
take from two others having the same attachment. Fix: finish it
|
||||
whenever the last part is stored, or one receiver at a time per
|
||||
attachment.
|
||||
- **`SyncState` in one packet** (old item 9). Every head the peer may
|
||||
send goes in one frame of 16 MiB at most: with very many topic and
|
||||
node pairs (hundreds of thousands) it doesn't fit, the packet can't
|
||||
be sent and replication stops. Fix: heads in several packets, or only
|
||||
those that changed.
|
||||
- **Peers with several roles.** `SyncState` lists the union of its
|
||||
roles' `accept_topics` and the union of their `accept_nodes`
|
||||
(`Permissions::accepted`), while what's taken is each role on its
|
||||
own: the sender can offer a topic of one role with a node of another,
|
||||
refused (`NotAllowed`), and sent again, a whole batch, at every
|
||||
check-in. Fix: the pairs per role in `SyncState`, or the sender
|
||||
remembering what was refused.
|
||||
- **A peer can use up a topic and node's ids.** A replicated message
|
||||
may have any id up to the highest (2^43 - 1, `MAX_MESSAGE_ID`), and
|
||||
the stream's last id follows it (`batch.rs`, `replicate`). One such
|
||||
message from a server in `accept_from`, for any topic and node its
|
||||
roles accept, and every later push to that topic by that node is
|
||||
refused ("no message id left", `insert_pushed`); it replicates on to
|
||||
the other servers. Nothing lowers a last id again. Part of "Peers
|
||||
are trusted" above, but one message is enough and a bug can do it.
|
||||
Left as it is (the owner, 2026-11-16): no cheap check tells a bad id
|
||||
from a real one. Ids jump for good reasons (retention, a server that
|
||||
joins late), so "must follow the last id here" or a bound on the jump
|
||||
refuses real messages or stops nothing; refusing ids past its own
|
||||
for the nodes that push here breaks a node moving to another server
|
||||
and back. Fix: messages signed by their node, as above.
|
||||
- **A pair refused for good is sent again at every check-in**, a whole
|
||||
batch each time (`push_to.rs`, `send_messages`: a refusal only
|
||||
leaves it for the next check-in): the database's topic and node
|
||||
pairs all used, a message id past the last one. Fix: with "Peers
|
||||
with several roles" above.
|
||||
- **Patterns in `push_topics` let clients make topics.** The roles are
|
||||
the only lists of topics since 2026-11-16 (`config.md`): a client
|
||||
with `push_topics = ["*"]` makes as many topic and node pairs as it
|
||||
likes, up to the database's 2^20 - 1, after which no new pair is
|
||||
taken from anyone. Listing topics also only shows those with
|
||||
messages: a client can't ask what it may push to. Fine for the
|
||||
threat model; names in `push_topics` where the set is closed.
|
||||
- **Whether a node exists can still be probed.** Listing nodes is
|
||||
filtered by the roles since 2026-11-16 (`list_nodes`), but
|
||||
`GetMessages` answers `UnknownName` for a node without messages
|
||||
anywhere and none for one with messages in another topic
|
||||
(`reader.rs`, `messages`). Fix: none in both cases.
|
||||
- **A CRL file that isn't there.** The server takes it as nothing
|
||||
revoked (`load_revocations`, `bakashrot-server/src/lib.rs`), the
|
||||
`bakashrot` tool refuses to start when `client.toml`'s `crl` names a
|
||||
missing file. Either may be right (a server that starts before its
|
||||
first CRL; a client that must not skip the check): choose one and
|
||||
say it in the docs. A server whose CRL file was deleted by mistake
|
||||
revokes nothing, silently.
|
||||
- **No limits per client.** Any number of connections (each a task and
|
||||
its buffers), any amount pushed: an allowed client can fill the disk
|
||||
or the server's memory. Fine for the threat model; first thing to
|
||||
add if it changes (a cap on connections, a quota per node).
|
||||
- **Small ones:** the client's connect timeout is per socket
|
||||
operation, not for the whole connection; `bakashrot-cert ca` writes
|
||||
`ca.crt` before failing when only `ca.key` is there already; a
|
||||
server whose clock is before 1970 stamps `pushed_at` 0, which
|
||||
readers refuse when decoding.
|
||||
|
||||
## Ideas for later
|
||||
|
||||
From the old benchmarks and suggestions (`OldSource/Design/Suggestions.md`),
|
||||
|
||||
+7
-9
@@ -6,9 +6,8 @@ machine, 2026-11-15, Windows): the outputs shown are what came back.
|
||||
|
||||
Get a release (CI's artifacts, or `release.ps1` / `python release.py`):
|
||||
the programs, `bakashrot.dll` / `libbakashrot.so`, the wheel, the
|
||||
example configs. The certificates are throwaway for now: the identity
|
||||
OID is a placeholder until NibblePoker's PEN (`oid.md`), every tool run
|
||||
says so. Reissue them all once it changes.
|
||||
example configs. Certificates made before 0.3.0 had a placeholder
|
||||
identity OID (`oid.md`) and aren't read any more: issue them again.
|
||||
|
||||
| Machine | What runs there | Files it gets |
|
||||
|---|---|---|
|
||||
@@ -50,7 +49,6 @@ certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
crl = "ca.crl" # optional; a missing file is fine, it's watched
|
||||
database = "bakashrot.sqlite"
|
||||
topics = ["lab.temps", "lab.events"]
|
||||
|
||||
[retention]
|
||||
"*" = "7d"
|
||||
@@ -71,8 +69,8 @@ send_topics = ["lab.*"]
|
||||
accept_topics = ["lab.*"]
|
||||
```
|
||||
|
||||
- `topics` are names, not patterns (`"lab.*"` there is refused, with its
|
||||
line); the roles take patterns.
|
||||
- The roles are the only lists of topics, names or patterns: a topic
|
||||
exists from its first message.
|
||||
- Every setting, with its default: `server.example.toml` (`config.md`).
|
||||
- Open the port: `New-NetFirewallRule -DisplayName BakaShrot -Direction
|
||||
Inbound -Protocol TCP -LocalPort 7000 -Action Allow` on Windows, the
|
||||
@@ -139,11 +137,11 @@ Saved 6 bytes as got.txt
|
||||
{"columns":["topic","node","message_id","c"],"rows":[["lab.events","kitchen","1",null],["lab.temps","kitchen","1","21.5"]]}
|
||||
```
|
||||
|
||||
**Refusals.** A topic not in the config:
|
||||
**Refusals.** A topic none of its roles names:
|
||||
|
||||
```
|
||||
> bakashrot push other "{}"
|
||||
Refused by the server (UnknownName): unknown topic 'other'
|
||||
Refused by the server (NotAllowed): kitchen may not push to 'other'
|
||||
```
|
||||
|
||||
A certificate whose roles aren't in the config
|
||||
@@ -166,7 +164,7 @@ certificate is refused, at its next connection or request:
|
||||
Failed to connect to server-2.lab:7000 (AuthRejected): the server refused this client's certificate (CertificateRevoked)
|
||||
```
|
||||
|
||||
**Python.** `pip install bakashrot-0.2.0-py3-none-<platform>.whl` (from the
|
||||
**Python.** `pip install bakashrot-0.3.0-py3-none-<platform>.whl` (from the
|
||||
release's `python/`), then, next to lab-py's `client.toml` (it may push and
|
||||
read: `sensor` and `dashboard`):
|
||||
|
||||
|
||||
+34
-63
@@ -1,77 +1,48 @@
|
||||
# The identity extension's OID
|
||||
|
||||
**Open point:** the OID is a placeholder until NibblePoker has its own
|
||||
Private Enterprise Number (PEN) from IANA. The owner's to request
|
||||
(below), then a few lines to change here.
|
||||
`IDENTITY_OID = 1.3.6.1.4.1.67681.1.1` (`crates/bakashrot-pki/src/lib.rs`),
|
||||
since 0.3.0 (2026-11-16).
|
||||
|
||||
## Why it matters
|
||||
## The branches
|
||||
|
||||
NibblePoker's Private Enterprise Number (PEN) is **67681**, from IANA
|
||||
(in the registry, <https://www.iana.org/assignments/enterprise-numbers/>,
|
||||
checked 2026-11-16). One number for NibblePoker as a whole: every project
|
||||
gets its own branch under it, recorded here. A number once given is never
|
||||
reused.
|
||||
|
||||
| OID | What |
|
||||
|---|---|
|
||||
| `1.3.6.1.4.1.67681` | NibblePoker |
|
||||
| `1.3.6.1.4.1.67681.1` | BakaShrot |
|
||||
| `1.3.6.1.4.1.67681.1.1` | BakaShrot's identity extension |
|
||||
|
||||
## Why it never changes
|
||||
|
||||
Servers find a certificate's name and roles by its identity extension's
|
||||
OID (`bakashrot_pki::IDENTITY_OID`). Changing the OID makes every
|
||||
certificate issued before unreadable as a BakaShrot identity: all of them
|
||||
would have to be issued again. So it's settled before certificates are in
|
||||
use; what's inside the extension can still change (its `version` field)
|
||||
without touching the OID.
|
||||
OID. Changing the OID makes every certificate issued before unreadable as
|
||||
a BakaShrot identity: all of them would have to be issued again. What's
|
||||
inside the extension can still change (its `version` field) without
|
||||
touching the OID.
|
||||
|
||||
Within a deployment, only the CA's certificates are read, so another
|
||||
extension using the same OID somewhere else can't confuse a server. The OID
|
||||
mostly needs to be stable, and properly ours.
|
||||
|
||||
## Now: a placeholder
|
||||
## Before 0.3.0: a placeholder
|
||||
|
||||
- `IDENTITY_OID = 1.3.6.1.4.1.32473.1.1`: under PEN 32473, "Example
|
||||
Enterprise Number for Documentation Use" (RFC 5612). It works, but isn't
|
||||
meant for real use, and examples elsewhere use it too.
|
||||
- `IDENTITY_OID_IS_PLACEHOLDER = true`: `bakashrot-cert` warns whenever it
|
||||
makes a CA or issues a certificate.
|
||||
- Fine for development and tests; not for certificates in use.
|
||||
- `OldSource/`'s UUID arc (`2.25.2320...0981`) can't be used: `rcgen`
|
||||
writes OID parts of 64 bits at most, a UUID is 128.
|
||||
Up to 0.2.0 the OID was `1.3.6.1.4.1.32473.1.1`, under PEN 32473, "Example
|
||||
Enterprise Number for Documentation Use" (RFC 5612), and `bakashrot-cert`
|
||||
warned whenever it made a certificate. **Those certificates aren't read
|
||||
any more** ("no BakaShrot identity"): make the CA's again or keep it (a
|
||||
CA has no identity extension), issue every server's and node's again.
|
||||
|
||||
## Requesting a PEN
|
||||
`OldSource/`'s UUID arc (`2.25.2320...0981`) couldn't be used: `rcgen`
|
||||
writes OID parts of 64 bits at most, a UUID is 128.
|
||||
|
||||
From IANA's application page (checked 2026-11-13):
|
||||
## Changing the registration
|
||||
|
||||
1. **Check first** that NibblePoker doesn't have one: search the registry,
|
||||
<https://www.iana.org/assignments/enterprise-numbers/> (it had none on
|
||||
2026-11-13). An organization that has one hands out sub-numbers under
|
||||
it instead of asking for another.
|
||||
2. **Apply** at <https://pen.iana.org/pen/PenApplication.page>. It's free.
|
||||
It asks for:
|
||||
- the **assignee**, the organization (or person) the number is for:
|
||||
name ("NibblePoker"), address, country, phone (optional);
|
||||
- a **contact**, the person IANA and others write to with questions,
|
||||
who may also request changes later: name, address, country, phone and
|
||||
fax (optional), **email** (required).
|
||||
3. **Confirm** the request from the email IANA sends to that address.
|
||||
4. **Wait:** if nothing else is needed, the number comes within seven days
|
||||
of that confirmation. Questions: iana-pen@iana.org.
|
||||
|
||||
**What's public:** the registry lists, for every number, the organization,
|
||||
the contact's name and the contact's email address (written with `&` for
|
||||
`@`). Use an address meant to be published (a role address, not a
|
||||
personal one).
|
||||
|
||||
Ask for one number for NibblePoker as a whole, not one per project: every
|
||||
project gets its own branch under it.
|
||||
|
||||
## Once the number is there
|
||||
|
||||
With `<PEN>` the number IANA gave:
|
||||
|
||||
1. **Plan the branches**, and record them in the table below; a number
|
||||
once given is never reused:
|
||||
|
||||
| OID | What |
|
||||
|---|---|
|
||||
| `1.3.6.1.4.1.<PEN>` | NibblePoker |
|
||||
| `1.3.6.1.4.1.<PEN>.1` | BakaShrot |
|
||||
| `1.3.6.1.4.1.<PEN>.1.1` | BakaShrot's identity extension |
|
||||
|
||||
2. **In `crates/bakashrot-pki/src/lib.rs`:** `IDENTITY_OID` to
|
||||
`[1, 3, 6, 1, 4, 1, <PEN>, 1, 1]`, `IDENTITY_OID_IS_PLACEHOLDER` to
|
||||
`false`.
|
||||
3. **Update** this file (the table, "Now"), `certificates.md` and the open
|
||||
point in `../revamp.md`.
|
||||
4. **Issue again** any certificate made with the placeholder, and run
|
||||
`test.ps1` (the tests issue their own, nothing to change there).
|
||||
The registry lists the organization, the contact's name and the contact's
|
||||
email address. Changes (a new contact, an address) are asked for at
|
||||
<https://pen.iana.org/pen/PenApplication.page> or iana-pen@iana.org, by
|
||||
the contact.
|
||||
|
||||
+3
-2
@@ -69,8 +69,9 @@ format, its values are checked all the same.)
|
||||
|
||||
- **Topics and nodes are names**, everywhere: 1-64 of `A-Z a-z 0-9 _ . -`,
|
||||
not only digits, compared without case (`names`). A name that isn't one
|
||||
is malformed (the client libraries check before sending); one the server
|
||||
doesn't have is refused (`UnknownName`). Ids are each server's own, in
|
||||
is malformed (the client libraries check before sending); a node the
|
||||
server has no message of is refused (`UnknownName`), a topic is only
|
||||
ever allowed or not (the roles). Ids are each server's own, in
|
||||
its database, never on the wire.
|
||||
- **Patterns** (in a `SyncState`): names with `*` (any characters, none
|
||||
included) and `?` (one).
|
||||
|
||||
+17
-13
@@ -118,8 +118,8 @@ otherwise:
|
||||
one (topics and nodes, patterns included), its last id in each topic
|
||||
and node, and the attachments it lacks (256 at most).
|
||||
2. **The messages:** for each topic and node here that it takes and that
|
||||
its roles here may be sent (`send_topics`, `send_nodes`,
|
||||
`replicated_topics`), and where it's behind, the messages after its
|
||||
its roles here may be sent (`send_topics`, `send_nodes`), and where
|
||||
it's behind, the messages after its
|
||||
last id, `batch_size` (1000) at a time and about 1 MiB at most (a
|
||||
bigger one alone), each batch answered before the next. A refusal
|
||||
leaves that topic and node for the next check-in.
|
||||
@@ -132,7 +132,8 @@ otherwise:
|
||||
**Receiving** (`accept_from.rs`): replication requests are answered only
|
||||
if the connection comes from `accept_from` (a hostname looked up at its
|
||||
first request, `NotAllowed` otherwise), and only for what its roles'
|
||||
`accept_topics` / `accept_nodes` allow (`NotAllowed`). Messages keep
|
||||
`accept_topics` / `accept_nodes` allow (`NotAllowed`); a topic nobody
|
||||
pushed here is there from then on, like any other. Messages keep
|
||||
their ids and `pushed_at`; ones already here are kept as they are; one
|
||||
past this server's age is only counted. An attachment comes after its
|
||||
message (`replicating`, `NotReady` to readers), from the part this server
|
||||
@@ -167,13 +168,15 @@ the same ids with different messages, undetected.
|
||||
|---|---|
|
||||
| TLS, versions, welcome | 10 s (the server); the client's connect too |
|
||||
| Silence between requests | 5 min, then the server closes |
|
||||
| A packet sent (an answer, an attachment's part, to a peer too) | 30 s (the server), then it closes: a client that stopped reading doesn't hold a connection |
|
||||
| An answer | 30 s (the client) |
|
||||
| An attachment's next part | 30 s (the server), then it closes |
|
||||
|
||||
## Requests so far
|
||||
|
||||
- **`PushMessage`:** the topic must be one of the config's (`UnknownName`),
|
||||
the roles must allow pushing to it (`NotAllowed`), the message at most
|
||||
- **`PushMessage`:** the roles must allow pushing to the topic
|
||||
(`NotAllowed`; there's no other list of topics, `config.md`), the
|
||||
message at most
|
||||
`MAX_MESSAGE_SIZE` (`TooBig`); stored under the client's node, stamped
|
||||
with the server's time; answered `MessagePushed` once committed.
|
||||
- **With an attachment:** also at most the config's `max_attachment_size`
|
||||
@@ -187,19 +190,20 @@ the same ids with different messages, undetected.
|
||||
connection that closes, or sends anything else than the next part, is
|
||||
dropped. Not pushed, the upload goes (`storage.md`, "Attachments").
|
||||
- **`GetAttachment`:** the roles must allow reading the topic
|
||||
(`NotAllowed`), the topic must be one of the config's (`UnknownName`).
|
||||
A message without one, or none of that id: `NotFound`; one still on its
|
||||
(`NotAllowed`). A message without one, or none of that id (or of that
|
||||
topic): `NotFound`; one still on its
|
||||
way from a peer: `NotReady`; one this server doesn't keep: `TooBig`.
|
||||
Then `Attachment` (its size, its SHA-256) and the parts from
|
||||
`from_part`. A part that can't be read closes the connection.
|
||||
- **`GetMessages`:** the roles must allow reading the topic
|
||||
(`NotAllowed`), the topic must be one of the config's and the node one
|
||||
with messages in any topic, or the client's own (`UnknownName`); a known
|
||||
topic and node without messages answer none. At most `limit` messages and about 1 MB
|
||||
(`NotAllowed`), the node must be one with messages in any topic, or
|
||||
the client's own (`UnknownName`); a topic and node without messages
|
||||
answer none. At most `limit` messages and about 1 MB
|
||||
(`MESSAGES_BYTES`, a bigger message alone), `more` if others follow.
|
||||
- **`ListNames`:** topics are the config's, those the roles may push to or
|
||||
read (every one with `query`, which reads them all anyway); nodes are
|
||||
every one with messages. `truncated` past 65,536.
|
||||
- **`ListNames`:** topics are those with messages (pushed here or
|
||||
replicated), those the roles may push to or read (every one with
|
||||
`list_topics` or `query`); nodes are those with messages in the
|
||||
topics the roles may read (every one with `list_nodes` or `query`). `truncated` past 65,536.
|
||||
- **`Query`:** the roles must allow it (`NotAllowed`); read-only SQL,
|
||||
refused with SQLite's message (`QueryFailed`, with a hint to add
|
||||
`is_json = 1` on "malformed JSON"), over 10,000 rows or 16 MB
|
||||
|
||||
+6
-2
@@ -109,7 +109,7 @@ read while the writer writes. Answers are the protocol's own types:
|
||||
|
||||
A topic and node with no messages read as none, unless the node has none
|
||||
in any topic: `Error::UnknownName`, as the old server refused unknown
|
||||
nodes. Whether a topic is known is the server's (the config's topics).
|
||||
nodes. A topic is never unknown: it's allowed or not, by the roles.
|
||||
|
||||
## Attachments
|
||||
|
||||
@@ -140,7 +140,11 @@ afterwards, `purge_attachments(max_parts)` a batch at a time.
|
||||
|
||||
Clients' `Query` runs on `Database::query_runner()`, read-only three ways:
|
||||
the connection is `query_only`, the statement must be one SQLite says only
|
||||
reads, and one statement only (more is refused, not ignored). The result is
|
||||
reads, and one statement only (more is refused, not ignored). PRAGMAs are
|
||||
refused as they're prepared ("not authorized", SQLite's authorizer), the
|
||||
`pragma_*` table functions too: some take effect at that point, and
|
||||
`PRAGMA query_only = 0`, though refused, turned `query_only` off for the
|
||||
connection's next queries (found 2026-11-15). The result is
|
||||
`{"columns":[...],"rows":[[...]]}`, every value a string or null (blobs in
|
||||
hex), 10,000 rows and 16 MB at most (`TooBig`). A failing row fails it all,
|
||||
with SQLite's message: never a partial result. "malformed JSON" (a JSON
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
# 1. Certificates
|
||||
|
||||
[Index](readme.md) · Next: [Server](2-server.md)
|
||||
|
||||
More options: `bakashrot-cert.exe <command> --help`.
|
||||
|
||||
|
||||
## The root certificate
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe ca --name bakashrot-test
|
||||
```
|
||||
|
||||
Resulting files:
|
||||
* `ca.crt` - Must be copied to each server and client.
|
||||
* `ca.key` - Stays on this machine, it can make any certificate.
|
||||
|
||||
|
||||
## A server certificate
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe issue --server --name server-lan1
|
||||
Wrote .\server-lan1.crt
|
||||
Wrote .\server-lan1.key
|
||||
```
|
||||
|
||||
Depending on how you set up replications, you may have to add a role with `--role <ROLE_NAME>`. \
|
||||
See [???]().
|
||||
|
||||
|
||||
## Node certificates
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe issue --name node-sensor --role sensor
|
||||
Wrote .\node-sensor.crt
|
||||
Wrote .\node-sensor.key
|
||||
|
||||
bakashrot-cert.exe issue --name node-viewer --role viewer
|
||||
Wrote .\node-viewer.crt
|
||||
Wrote .\node-viewer.key
|
||||
```
|
||||
|
||||
* The name is the node its messages are pushed as.
|
||||
* Roles mean nothing until the server's config says what they may do ([Server](2-server.md)).
|
||||
* Several roles: `--role sensor --role viewer`.
|
||||
|
||||
|
||||
## Checking one
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe show node-sensor.crt
|
||||
node-sensor.crt
|
||||
name: node-sensor
|
||||
roles: sensor
|
||||
usage: client
|
||||
issuer: bakashrot-test
|
||||
valid: Nov 15 11:35:45 2026 +00:00 to Nov 15 11:35:45 2027 +00:00
|
||||
serial: 588a92f0c5b39bc557f463f0ef50c278a2f9df50
|
||||
```
|
||||
|
||||
|
||||
## Revoking one
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe revoke node-sensor.crt
|
||||
```
|
||||
|
||||
* Writes `ca.crl` (every certificate revoked so far).
|
||||
* Copy it next to the server's `server.toml` and add `crl = "ca.crl"` under `[server]`.
|
||||
* The server reloads it within 5 s; that certificate is refused from its next request.
|
||||
@@ -0,0 +1,145 @@
|
||||
# 2. Server
|
||||
|
||||
[Index](readme.md) · Previous: [Certificates](1-certificates.md) · Next: [Client](3-client.md)
|
||||
|
||||
## Pre-requisites
|
||||
* The certificate authority's `.crt` file.
|
||||
* The server's `.crt` file.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Configuring it
|
||||
The server's config is typically kept in `server.toml`, next the `.crt` files. \
|
||||
Create a blank one and all the following sections.
|
||||
|
||||
### Server's base config
|
||||
```toml
|
||||
# All paths are relative to CWD unless they're absolute.
|
||||
[server]
|
||||
listen = "0.0.0.0:7000" # Used when binding.
|
||||
|
||||
ca = "ca.crt"
|
||||
certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
|
||||
# The watched CA's CRL.
|
||||
# The CRL checks will be disabled if not given, the program will exit if given and non-existent.
|
||||
#crl = "ca.crl"
|
||||
|
||||
database = "bakashrot.sqlite"
|
||||
|
||||
# "full": every push flushed to disk before it's answered, it survives a
|
||||
# power loss. "normal": about twice the pushes, a power loss loses the last
|
||||
# second or so. ("off" isn't allowed.)
|
||||
synchronous = "full"
|
||||
|
||||
max_attachment_size = "1G" # bytes, or K M G T (1024-based); 0: none
|
||||
retention_interval = "1m" # how often old messages are deleted
|
||||
```
|
||||
|
||||
|
||||
### Replication
|
||||
```toml
|
||||
# Who this server replicates with, by address.
|
||||
# A link carries messages one way: the server that dials sends, the one dialed takes them.
|
||||
[replication]
|
||||
push_to = [] # Servers we'll actively connect to.
|
||||
# Example: ["10.0.0.2:7000", "server-2.lan:7000"]
|
||||
|
||||
accept_from = [] # Connecting servers must have these origins, otherwise we abort.µ
|
||||
# Example: ["10.0.0.2", "server-2.lan"], or ["*"]
|
||||
|
||||
retry_delay = "10s"
|
||||
sync_interval = "5s"
|
||||
batch_size = 1000 # messages per packet, 1-10000
|
||||
```
|
||||
|
||||
|
||||
### Roles section
|
||||
```toml
|
||||
[roles.sensor]
|
||||
push_topics = ["sensors.*"] # always as its own node (its name)
|
||||
read_topics = ["*"]
|
||||
query = true # read-only SQL, reads every topic
|
||||
|
||||
# Listing: by default, only the topics it may push to or read,
|
||||
# and only the nodes of the topics it may read.
|
||||
list_topics = false # true: lists every topic (query does too)
|
||||
list_nodes = false # true: lists every node (query does too)
|
||||
|
||||
# Only relevant when replicating.
|
||||
send_nodes = ["*"] # Replicates all known topics (Default)
|
||||
accept_nodes = ["*"] # Accepts al foreign topics (Default)
|
||||
```
|
||||
|
||||
#### Remarks:
|
||||
* Any node/certificate without any known role is refused.
|
||||
|
||||
#### Examples:
|
||||
> **Sensor:**
|
||||
> ```toml
|
||||
> [roles.sensor]
|
||||
> push_topics = ["sensors.*"]
|
||||
> read_topics = []
|
||||
> ```
|
||||
|
||||
> **Log Processor:**
|
||||
> ```toml
|
||||
> [roles.sensor]
|
||||
> push_topics = ["alerts.sensors.*"]
|
||||
> read_topics = ["sensors.*"]
|
||||
> ```
|
||||
|
||||
> **Explorer:** (sees every name, reads nothing)
|
||||
> ```toml
|
||||
> [roles.explorer]
|
||||
> list_topics = true
|
||||
> list_nodes = true
|
||||
> ```
|
||||
|
||||
> **Admin:** (everything a client can do, on every topic)
|
||||
> ```toml
|
||||
> [roles.admin]
|
||||
> push_topics = ["*"]
|
||||
> read_topics = ["*"]
|
||||
> query = true
|
||||
> list_topics = true
|
||||
> list_nodes = true
|
||||
> ```
|
||||
> Its certificate: `bakashrot-cert.exe issue --name node-admin --role admin`
|
||||
|
||||
|
||||
### Retention
|
||||
```toml
|
||||
# How long each topic's messages are kept, from when they were first pushed.
|
||||
# Any topic not present here will be kept forever.
|
||||
[retention]
|
||||
logs = "30d"
|
||||
"sensors.*" = "12h"
|
||||
"*" = "forever" # Implied
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Opening the port
|
||||
|
||||
Admin PowerShell:
|
||||
```powershell
|
||||
New-NetFirewallRule -DisplayName BakaShrot -Direction Inbound -Protocol TCP -LocalPort 7000 -Action Allow
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Starting it
|
||||
|
||||
```shell
|
||||
bakashrot-server.exe server.toml
|
||||
2026-11-15T11:35:51.404202Z INFO server-lan1 listening on 0.0.0.0:7000
|
||||
```
|
||||
|
||||
* Creates `bakashrot.sqlite` on first start.
|
||||
* Stop with Ctrl+C: what was accepted is saved.
|
||||
* More logs: `set BAKASHROT_LOG=debug` before starting it.
|
||||
@@ -0,0 +1,23 @@
|
||||
# 3. Client
|
||||
|
||||
[Index](readme.md) · Previous: [Server](2-server.md) · Next: [Pushing](4-pushing.md)
|
||||
|
||||
`client.toml`, next to `ca.crt`, `node-sensor.crt` and `node-sensor.key`:
|
||||
```toml
|
||||
server = "192.168.1.10:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "node-sensor.crt"
|
||||
key = "node-sensor.key"
|
||||
```
|
||||
|
||||
`viewer.toml`, the same with the viewer's certificate:
|
||||
```toml
|
||||
server = "192.168.1.10:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "node-viewer.crt"
|
||||
key = "node-viewer.key"
|
||||
```
|
||||
|
||||
* `server`: the server's IP or hostname, and its `listen` port.
|
||||
* `bakashrot.exe` reads `client.toml` from the current folder, `-c viewer.toml` for another one.
|
||||
* Optional: `crl = "ca.crl"`, to refuse a revoked server.
|
||||
@@ -0,0 +1,31 @@
|
||||
# 4. Pushing
|
||||
|
||||
[Index](readme.md) · Previous: [Client](3-client.md) · Next: [Reading](5-reading.md)
|
||||
|
||||
As `node-sensor` (`client.toml`).
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot push sensors "{\"celsius\":21.5}"
|
||||
Pushed as message #1
|
||||
|
||||
E:\BakaShrot>bakashrot push sensors @reading.json -a photo.jpg
|
||||
Pushed as message #2, with an attachment of 245 bytes
|
||||
```
|
||||
|
||||
* Always pushed as the certificate's node (`node-sensor`).
|
||||
* `@file` reads the message from a file, `-` from stdin.
|
||||
* `-a`: one attachment per message.
|
||||
|
||||
|
||||
## Refused
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot push other "{}"
|
||||
Refused by the server (NotAllowed): node-sensor may not push to 'other'
|
||||
|
||||
E:\BakaShrot>bakashrot messages sensors node-sensor
|
||||
Refused by the server (NotAllowed): node-sensor may not read 'sensors'
|
||||
```
|
||||
|
||||
* `other` isn't in the `sensor` role's `push_topics`.
|
||||
* The `sensor` role has no `read_topics`: reading is the viewer's ([Reading](5-reading.md)).
|
||||
@@ -0,0 +1,61 @@
|
||||
# 5. Reading
|
||||
|
||||
[Index](readme.md) · Previous: [Pushing](4-pushing.md)
|
||||
|
||||
As `node-viewer` (`-c viewer.toml`).
|
||||
|
||||
|
||||
## Topics and nodes
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml list
|
||||
Topics (1):
|
||||
sensors
|
||||
Nodes (1):
|
||||
node-sensor
|
||||
```
|
||||
|
||||
|
||||
## A node's messages in a topic
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml messages sensors node-sensor
|
||||
1 {"celsius":21.5}
|
||||
2 {"celsius":22}
|
||||
```
|
||||
|
||||
* One per line: id, tab, data.
|
||||
* The node is a name, not a pattern: `*` fails with `'*' isn't a node name`.
|
||||
* `-f` keeps waiting for new ones, `-t` adds the time, `--after <id>` skips the first ones.
|
||||
|
||||
|
||||
## The latest one, with its attachment
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml latest sensors node-sensor
|
||||
Message sensors:node-sensor#2, pushed 2026-11-15T11:35:53.484Z
|
||||
Attachment: 245 bytes
|
||||
{"celsius":22}
|
||||
|
||||
E:\BakaShrot>bakashrot -c viewer.toml attachment sensors node-sensor 2 photo.jpg
|
||||
Saved 245 bytes as photo.jpg
|
||||
```
|
||||
|
||||
|
||||
## SQL
|
||||
|
||||
Read-only, every topic, needs `query = true` in the role:
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml query "SELECT node, message_id, message_data ->> '$.celsius' AS c FROM messages"
|
||||
{"columns":["node","message_id","c"],"rows":[["node-sensor","1","21.5"],["node-sensor","2","22"]]}
|
||||
```
|
||||
|
||||
|
||||
## Refused
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml push sensors "{}"
|
||||
Refused by the server (NotAllowed): node-viewer may not push to 'sensors'
|
||||
```
|
||||
|
||||
* The `viewer` role has no `push_topics`.
|
||||
@@ -0,0 +1,26 @@
|
||||
# BakaShrot - Guides
|
||||
|
||||
One server, one client that pushes (`node-sensor`), one that reads (`node-viewer`).
|
||||
Commands are for `cmd`, run from the release's folder (`E:\BakaShrot`).
|
||||
|
||||
| Step | Guide | Result |
|
||||
|------|-----------------------------------|--------------------------------------------------------------|
|
||||
| 1 | [Certificates](1-certificates.md) | A CA, the server's and the nodes' certificates; revoking one |
|
||||
| 2 | [Server](2-server.md) | `server.toml`, the port opened, the server running |
|
||||
| 3 | [Client](3-client.md) | `client.toml` for each node |
|
||||
| 4 | [Pushing](4-pushing.md) | Messages and attachments stored |
|
||||
| 5 | [Reading](5-reading.md) | Messages listed, read, queried |
|
||||
|
||||
Who gets which files:
|
||||
|
||||
| Machine | Files |
|
||||
|---------|---------------------------------------------------------------------------------------|
|
||||
| admin | `bakashrot-cert.exe`, `ca.crt`, `ca.key` (never copied) |
|
||||
| server | `bakashrot-server.exe`, `ca.crt`, `server-lan1.crt`, `server-lan1.key`, `server.toml` |
|
||||
| sensor | `bakashrot.exe`, `ca.crt`, `node-sensor.crt`, `node-sensor.key`, `client.toml` |
|
||||
| viewer | `bakashrot.exe`, `ca.crt`, `node-viewer.crt`, `node-viewer.key`, `viewer.toml` |
|
||||
|
||||
More:
|
||||
* `bakashrot <command> --help`, `bakashrot-cert <command> --help`.
|
||||
* Two replicating servers, Python, Docker: `docs/lab.md`.
|
||||
* Every setting: `docs/config.md`.
|
||||
@@ -53,7 +53,7 @@ docs/ designs across crates: protocol.md, certificates.md, oid
|
||||
crates/
|
||||
bakashrot-proto/ packets, frames, names, limits, error codes, shared by everything
|
||||
bakashrot-pki/ certificates: issuing, identities, CRLs, the TLS setup
|
||||
bakashrot-config/ the server's config (TOML): topics, retention, replication, roles
|
||||
bakashrot-config/ the server's config (TOML): retention, replication, roles
|
||||
bakashrot-storage/ SQLite, schema v9: the writer, reads, attachments, queries
|
||||
bakashrot-server/ the server: TLS, identities, requests, the writer thread (and its program)
|
||||
bakashrot-client/ the client library, Rust API, blocking
|
||||
|
||||
@@ -275,7 +275,6 @@ ca = "ca.crt"
|
||||
certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
database = "test.sqlite"
|
||||
topics = ["releasetest"]
|
||||
|
||||
[roles.tester]
|
||||
push_topics = ["releasetest"]
|
||||
|
||||
@@ -107,9 +107,11 @@ Also decided (2026-11-13):
|
||||
critical ones it doesn't know): `SEQUENCE { version INTEGER (1), name
|
||||
UTF8String, roles SEQUENCE OF UTF8String }`. The name is the node;
|
||||
roles are free strings with the name rules, their meaning in the
|
||||
server's config. Only the server reads it. Its OID is a placeholder
|
||||
for now, see "Open questions" (the UUID arc of `OldSource/` can't be
|
||||
used: `rcgen` writes OID parts of 64 bits at most);
|
||||
server's config. Only the server reads it. Its OID is
|
||||
`1.3.6.1.4.1.67681.1.1`, under NibblePoker's PEN (2026-11-16,
|
||||
`docs/oid.md`; a placeholder until then; the UUID arc of
|
||||
`OldSource/` can't be used: `rcgen` writes OID parts of 64 bits at
|
||||
most);
|
||||
- the name again as the subject's CN, for people (`openssl x509 -text`,
|
||||
logs); the server only trusts the extension;
|
||||
- extended key usage `clientAuth` for clients, `serverAuth` and
|
||||
@@ -158,8 +160,23 @@ Also decided (2026-11-13):
|
||||
"Replication by address" below);
|
||||
- **no default topic** (dropped from the protocol too, 2026-11-13): a
|
||||
push always names its topic;
|
||||
- `[replication] replicated_topics`, optional: the only topics
|
||||
replicated at all, whatever the roles say, to filter on edge nodes.
|
||||
- **the roles are the only lists of topics** (2026-11-16): `[server]
|
||||
topics` and `[replication] replicated_topics` are gone (refused as
|
||||
unknown keys), they repeated the roles. A push is taken if its
|
||||
roles' `push_topics` name the topic, a replicated message if the
|
||||
peer's `accept_topics` do; a topic exists from its first message,
|
||||
and is read, listed (`ListNames`: the topics with messages) and
|
||||
sent on by the roles that name it. So a topic that only came from a
|
||||
peer is read like any other, and a push to a topic nobody names is
|
||||
`NotAllowed` (`UnknownName` is only for nodes now). Before: `topics`
|
||||
since 2026-11-13, `replicated_topics` to filter on edge nodes (now
|
||||
their peers' `send_topics`);
|
||||
- **`list_topics` and `list_nodes`** (2026-11-16), two booleans of a
|
||||
role, for a tool that browses a server: listing answers every topic,
|
||||
every node with messages. Without them (or `query`, which gives
|
||||
both): the topics it may push to or read, the nodes of the topics
|
||||
it may read (every node until then). Names only, reading is still
|
||||
`read_topics`.
|
||||
- **Schema v9, not compatible with v8** (2026-11-13): old databases aren't
|
||||
opened, their data isn't carried over (the real-life tests start empty).
|
||||
`docs/storage.md`:
|
||||
@@ -247,7 +264,9 @@ Also decided (2026-11-13):
|
||||
programs, the client library and its bindings, the example configs,
|
||||
the docs, the licenses, and a smoke test;
|
||||
- **the Python wheel has the library in it**, for a simple install;
|
||||
- **version 0.2.0.**
|
||||
- **version 0.2.0**; **0.3.0** on 2026-11-16 (the identity OID under
|
||||
NibblePoker's PEN, the roles as the only lists of topics,
|
||||
`list_topics` / `list_nodes`).
|
||||
- **The PureBasic version removed** (2026-11-15): `OldSource/` deleted,
|
||||
kept in git history (up to `68966a8`). What of its notes and designs
|
||||
still holds went to `docs/known-issues.md`; the rest was already
|
||||
@@ -290,14 +309,6 @@ come back as text either way; only what SQL computes would gain
|
||||
|
||||
- **A handle-based DLL API** (several connections per process, old open item
|
||||
10): later maybe, the owner's call (one connection per process for now).
|
||||
- **The identity extension's OID, a placeholder for now:** it goes under a
|
||||
Private Enterprise Number of NibblePoker's, from IANA (free, within a
|
||||
week; the owner's to request). Until then `bakashrot_pki::IDENTITY_OID`
|
||||
is under RFC 5612's documentation PEN (32473),
|
||||
`IDENTITY_OID_IS_PLACEHOLDER` is `true` and `bakashrot-cert` warns when
|
||||
it makes a certificate. Certificates issued with it stop being read once
|
||||
it changes: get the number before any is in use. How to request it and
|
||||
what to change then: `docs/oid.md`.
|
||||
|
||||
## Kept: the behaviour to carry over
|
||||
|
||||
|
||||
Reference in New Issue
Block a user