Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89a58c609c |
@@ -1,4 +1,5 @@
|
|||||||
//! Additive bounded passive metadata; the strict original Inventory stays intact.
|
//! Additive bounded passive metadata; the strict original Inventory stays intact.
|
||||||
|
mod opnsense;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -64,6 +65,9 @@ pub fn validate_for_scope(
|
|||||||
now: DateTime<Utc>,
|
now: DateTime<Utc>,
|
||||||
scope: &str,
|
scope: &str,
|
||||||
) -> Result<Value, &'static str> {
|
) -> Result<Value, &'static str> {
|
||||||
|
if scope == "opnsense.base" {
|
||||||
|
return opnsense::validate(bytes);
|
||||||
|
}
|
||||||
if scope == "agent.update" {
|
if scope == "agent.update" {
|
||||||
if bytes.len() > 65536 {
|
if bytes.len() > 65536 {
|
||||||
return Err("AGENT_UPDATE_INVENTORY_SIZE");
|
return Err("AGENT_UPDATE_INVENTORY_SIZE");
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
//! Allowlisted wire document. No appliance configuration or VPN secrets on the wire.
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct Snapshot {
|
||||||
|
os: String,
|
||||||
|
hostname: String,
|
||||||
|
architecture: String,
|
||||||
|
root_total_bytes: u64,
|
||||||
|
root_available_bytes: u64,
|
||||||
|
cpu_model: String,
|
||||||
|
logical_processors: u32,
|
||||||
|
memory_total_bytes: u64,
|
||||||
|
firewall: Rows,
|
||||||
|
vpn_configured: Rows,
|
||||||
|
wireguard: Rows,
|
||||||
|
openvpn: Rows,
|
||||||
|
ipsec: Rows,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct Rows {
|
||||||
|
status: String,
|
||||||
|
entries: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rows {
|
||||||
|
fn valid(&self) -> bool {
|
||||||
|
matches!(self.status.as_str(), "ok" | "partial" | "unavailable")
|
||||||
|
&& (self.status != "unavailable" || self.entries.is_empty())
|
||||||
|
&& self.entries.len() <= 128
|
||||||
|
&& self.entries.iter().all(|s| clean(s, 512))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn clean(s: &str, limit: usize) -> bool {
|
||||||
|
!s.trim().is_empty() && s.len() <= limit && !s.chars().any(char::is_control)
|
||||||
|
}
|
||||||
|
pub(super) fn validate(bytes: &[u8]) -> Result<Value, &'static str> {
|
||||||
|
let err = "INVALID_OPNSENSE_INVENTORY";
|
||||||
|
if bytes.len() > 384 * 1024 { return Err(err); }
|
||||||
|
let s: Snapshot = serde_json::from_slice(bytes).map_err(|_| err)?;
|
||||||
|
if !s.os.starts_with("OPNsense ") || !clean(&s.os, 128)
|
||||||
|
|| !clean(&s.hostname, 255) || s.architecture != "amd64"
|
||||||
|
|| s.root_total_bytes == 0 || s.root_available_bytes > s.root_total_bytes
|
||||||
|
|| !clean(&s.cpu_model, 256) || s.logical_processors == 0 || s.memory_total_bytes == 0
|
||||||
|
|| ![&s.firewall,&s.vpn_configured,&s.wireguard,&s.openvpn,&s.ipsec].iter().all(|r| r.valid())
|
||||||
|
{ return Err(err); }
|
||||||
|
serde_json::from_slice(bytes).map_err(|_| err)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use serde_json::json;
|
||||||
|
#[test]
|
||||||
|
fn no_config_blob_and_no_false_empty_on_error() {
|
||||||
|
let rows = json!({"status":"ok","entries":[]});
|
||||||
|
let mut doc = json!({"os":"OPNsense 26.7","hostname":"test","architecture":"amd64",
|
||||||
|
"root_total_bytes":20,"root_available_bytes":10,"cpu_model":"Test","logical_processors":2,
|
||||||
|
"memory_total_bytes":10,"firewall":rows,"vpn_configured":rows,"wireguard":rows,"ipsec":rows,"openvpn":rows});
|
||||||
|
assert!(validate(doc.to_string().as_bytes()).is_ok());
|
||||||
|
doc["wireguard"]["private_key"] = json!("not-permitted");
|
||||||
|
assert!(validate(doc.to_string().as_bytes()).is_err());
|
||||||
|
doc["wireguard"] = json!({"status":"unavailable","entries":["peer"]});
|
||||||
|
assert!(validate(doc.to_string().as_bytes()).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -160,7 +160,7 @@ pub async fn ingest(
|
|||||||
ensure!(
|
ensure!(
|
||||||
matches!(
|
matches!(
|
||||||
s.scope.as_str(),
|
s.scope.as_str(),
|
||||||
"linux.base" | "windows.base" | "agent.update"
|
"linux.base" | "windows.base" | "opnsense.base" | "agent.update"
|
||||||
) && s.schema_version == 1
|
) && s.schema_version == 1
|
||||||
&& s.chunk_count == 1
|
&& s.chunk_count == 1
|
||||||
&& s.chunk_index == 0
|
&& s.chunk_index == 0
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ SELECT c.*,o.observed_at,o.received_at,o.data,o.source_id FROM classified c
|
|||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT observed_at,received_at,data,source_id FROM observations
|
SELECT observed_at,received_at,data,source_id FROM observations
|
||||||
WHERE tenant_id=c.tenant_id AND agent_id=c.agent_id AND received_at<=$2
|
WHERE tenant_id=c.tenant_id AND agent_id=c.agent_id AND received_at<=$2
|
||||||
AND source_id IN ('linux.base','windows.base')
|
AND source_id IN ('linux.base','windows.base','opnsense.base')
|
||||||
ORDER BY observed_at DESC,received_at DESC,sequence DESC LIMIT 1
|
ORDER BY observed_at DESC,received_at DESC,sequence DESC LIMIT 1
|
||||||
) o ON true
|
) o ON true
|
||||||
WHERE ($6::text IS NULL OR (c.lifecycle='current')=($6='current'))
|
WHERE ($6::text IS NULL OR (c.lifecycle='current')=($6='current'))
|
||||||
|
|||||||
@@ -517,7 +517,8 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
|||||||
let ram_total = usage["ram_total_bytes"]
|
let ram_total = usage["ram_total_bytes"]
|
||||||
.as_u64()
|
.as_u64()
|
||||||
.or_else(|| linux_memory["total_bytes"].as_u64())
|
.or_else(|| linux_memory["total_bytes"].as_u64())
|
||||||
.or_else(|| windows["memory_total_bytes"].as_u64());
|
.or_else(|| windows["memory_total_bytes"].as_u64())
|
||||||
|
.or_else(|| data["memory_total_bytes"].as_u64());
|
||||||
let device_type = inventory_device_type(&data);
|
let device_type = inventory_device_type(&data);
|
||||||
let last = row.get::<Option<DateTime<Utc>>, _>("last_contact_at");
|
let last = row.get::<Option<DateTime<Utc>>, _>("last_contact_at");
|
||||||
let revoked = row.get::<Option<DateTime<Utc>>, _>("revoked_at");
|
let revoked = row.get::<Option<DateTime<Utc>>, _>("revoked_at");
|
||||||
@@ -536,8 +537,8 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
|||||||
"hostname":data["hostname"].as_str(),"purpose":row.get::<Option<String>,_>("purpose"),
|
"hostname":data["hostname"].as_str(),"purpose":row.get::<Option<String>,_>("purpose"),
|
||||||
"device_type":device_type,"os":os_label(&data),
|
"device_type":device_type,"os":os_label(&data),
|
||||||
"disk_free_bytes":data["root_available_bytes"].as_u64(),"disk_total_bytes":data["root_total_bytes"].as_u64(),
|
"disk_free_bytes":data["root_available_bytes"].as_u64(),"disk_total_bytes":data["root_total_bytes"].as_u64(),
|
||||||
"cpu_model":cpu["model"].as_str().or_else(||windows["cpu_model"].as_str()),
|
"cpu_model":cpu["model"].as_str().or_else(||windows["cpu_model"].as_str()).or_else(||data["cpu_model"].as_str()),
|
||||||
"cpu_logical_count":cpu["logical_processors"].as_u64().or_else(||windows["logical_processors_visible"].as_u64()),
|
"cpu_logical_count":cpu["logical_processors"].as_u64().or_else(||windows["logical_processors_visible"].as_u64()).or_else(||data["logical_processors"].as_u64()),
|
||||||
"cpu_usage_percent":cpu_usage,
|
"cpu_usage_percent":cpu_usage,
|
||||||
"cpu_usage_observed_at":cpu_observed_at,
|
"cpu_usage_observed_at":cpu_observed_at,
|
||||||
"ram_total_bytes":ram_total,
|
"ram_total_bytes":ram_total,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { allowed } from './safety';
|
|||||||
import { CatalogCheckNotice } from './catalog-check';
|
import { CatalogCheckNotice } from './catalog-check';
|
||||||
import { devicePlatform } from './script-catalog';
|
import { devicePlatform } from './script-catalog';
|
||||||
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
|
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
|
||||||
|
import { OPNsenseDetails } from './opnsense';
|
||||||
import { DeviceCustomerTransfer } from './device-customer-transfer';
|
import { DeviceCustomerTransfer } from './device-customer-transfer';
|
||||||
import { HypervisorAssignment, HypervisorLabel } from './device-hypervisor';
|
import { HypervisorAssignment, HypervisorLabel } from './device-hypervisor';
|
||||||
import { ErrorBox, errorText, useResource } from './resource';
|
import { ErrorBox, errorText, useResource } from './resource';
|
||||||
@@ -300,6 +301,7 @@ function DeviceDetail({
|
|||||||
success={purposeSaved}
|
success={purposeSaved}
|
||||||
onSaved={() => { setPurposeSaved(true); detail.reload(); }}
|
onSaved={() => { setPurposeSaved(true); detail.reload(); }}
|
||||||
/>
|
/>
|
||||||
|
<OPNsenseDetails device={d} />
|
||||||
<DeviceInventoryPanels device={d} />
|
<DeviceInventoryPanels device={d} />
|
||||||
{volumes.length > 0 && (
|
{volumes.length > 0 && (
|
||||||
<section>
|
<section>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { RecordValue } from './api';
|
||||||
|
|
||||||
|
export function OPNsenseDetails({ device }: { device: RecordValue }) {
|
||||||
|
if (device.source_id !== 'opnsense.base') return null;
|
||||||
|
const inventory = device.inventory as RecordValue | null;
|
||||||
|
function list(key: string, title: string) {
|
||||||
|
const report = inventory?.[key] as RecordValue | undefined;
|
||||||
|
const available = report?.status === 'ok' || report?.status === 'partial';
|
||||||
|
const rows = Array.isArray(report?.entries) ? report.entries.filter((x): x is string => typeof x === 'string') : [];
|
||||||
|
return <div key={key}><h3>{title}</h3>{!available ? <p>Nicht ermittelbar</p> : <>
|
||||||
|
{report?.status === 'partial' && <p>Auszug – unvollständige Liste</p>}
|
||||||
|
{rows.length ? <ol>{rows.map((line, i) => <li key={i}><code>{line}</code></li>)}</ol> : <p>Keine Einträge gemeldet.</p>}
|
||||||
|
</>}</div>;
|
||||||
|
}
|
||||||
|
return <>
|
||||||
|
<section><h2>VPN-Verbindungen</h2>
|
||||||
|
{list('vpn_configured', 'Konfigurierte VPNs')}
|
||||||
|
{list('wireguard', 'WireGuard · letzter Handshake je Peer')}
|
||||||
|
{list('openvpn', 'OpenVPN · Laufzeitstatus')}
|
||||||
|
{list('ipsec', 'IPsec · aktive Sicherheitsassoziationen')}
|
||||||
|
</section>
|
||||||
|
<section><h2>Firewallregeln</h2>{list('firewall', 'Aktive PF-Filterregeln · Hauptregelsatz in Auswertungsreihenfolge')}</section>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user