Skip to content

Commit c2dbb31

Browse files
authored
feat: Implement Logstash audit exporter (#162)
* feat: Implement Logstash audit exporter Add LogstashExporter implementation that sends audit events to Logstash via TCP using JSON Lines protocol. Key features: - TCP connection with automatic reconnection on failure - JSON Lines protocol (newline-delimited JSON) - Batch support for efficient event transmission - Connection timeout handling (10 seconds) - Comprehensive test coverage Implementation details: - Create src/server/audit/logstash.rs with LogstashExporter struct - Wire up LogstashExporter in AuditManager - Implement AuditExporter trait methods: export, export_batch, flush, close - Add 9 unit tests covering all functionality including edge cases Resolves #137 * fix: Address security issues in Logstash audit exporter * docs: Update architecture documentation for Logstash exporter Mark LogstashExporter as implemented (no longer "planned") and add documentation with usage example.
1 parent ba80149 commit c2dbb31

5 files changed

Lines changed: 811 additions & 8 deletions

File tree

ARCHITECTURE.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ let exporter = FileExporter::new(Path::new("/var/log/audit.log"))?
307307
- Graceful shutdown and flush methods
308308
- TLS support for secure audit data transmission
309309

310+
- **LogstashExporter**: Logstash exporter for ELK stack integration
311+
- TCP connection with JSON Lines protocol (newline-delimited JSON)
312+
- Optional TLS encryption for secure transmission
313+
- Automatic reconnection on connection failure
314+
- Batch support for efficient event transmission
315+
- Connection timeout handling (default: 10 seconds)
316+
- Configurable host and port
317+
310318
**OtelExporter Usage**:
311319
```rust
312320
use bssh::server::audit::otel::OtelExporter;
@@ -328,8 +336,27 @@ exporter.export(event).await?;
328336
exporter.close().await?;
329337
```
330338

331-
**Future Exporters** (planned):
332-
- Logstash exporter for centralized logging
339+
**LogstashExporter Usage**:
340+
```rust
341+
use bssh::server::audit::logstash::LogstashExporter;
342+
use bssh::server::audit::exporter::AuditExporter;
343+
use bssh::server::audit::event::{AuditEvent, EventType};
344+
345+
// Create exporter (unencrypted by default)
346+
let exporter = LogstashExporter::new("logstash.example.com", 5044)?
347+
.with_tls(true); // Enable TLS for production
348+
349+
// Export an audit event
350+
let event = AuditEvent::new(
351+
EventType::AuthSuccess,
352+
"alice".to_string(),
353+
"session-123".to_string(),
354+
);
355+
exporter.export(event).await?;
356+
357+
// Graceful shutdown
358+
exporter.close().await?;
359+
```
333360

334361
### Server CLI Binary
335362
**Binary**: `bssh-server`

Cargo.lock

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ opentelemetry = "0.21"
7373
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio", "logs"] }
7474
opentelemetry-otlp = { version = "0.14", features = ["grpc-tonic", "logs"] }
7575
url = "2.5"
76+
tokio-rustls = "0.26"
77+
rustls-native-certs = "0.8"
7678

7779
[target.'cfg(target_os = "macos")'.dependencies]
7880
security-framework = "3.5.1"

0 commit comments

Comments
 (0)