bssh 2.1.2

Parallel SSH command execution tool for cluster management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# Audit Logging Guide

[Back to Documentation Index](./README.md)

This guide covers setting up and using audit logging in bssh-server for security monitoring,
compliance, and troubleshooting.

## Table of Contents

- [Overview]#overview
- [Configuration]#configuration
- [Audit Events]#audit-events
- [Exporters]#exporters
- [Log Analysis]#log-analysis
- [Integration Examples]#integration-examples
- [Best Practices]#best-practices

## Overview

bssh-server provides comprehensive audit logging that captures security-relevant events including:

- Authentication attempts (success and failure)
- Session lifecycle (start, end, duration)
- Command execution
- File operations (read, write, delete, rename)
- Security events (IP blocks, suspicious activity)

Audit logs can be exported to multiple destinations simultaneously for flexibility in log management.

## Configuration

### Basic Configuration

Enable audit logging with file output:

```yaml
audit:
  enabled: true
  exporters:
    - type: file
      path: /var/log/bssh/audit.log
```

### Multiple Exporters

Send logs to multiple destinations:

```yaml
audit:
  enabled: true
  exporters:
    # Local file for backup/compliance
    - type: file
      path: /var/log/bssh/audit.log

    # OpenTelemetry for observability platform
    - type: otel
      endpoint: http://otel-collector:4317

    # Logstash for ELK stack
    - type: logstash
      host: logstash.example.com
      port: 5044
```

## Audit Events

### Event Types

| Event Type | Description | Logged Fields |
|------------|-------------|---------------|
| `AuthSuccess` | Successful authentication | user, method, client_ip |
| `AuthFailure` | Failed authentication attempt | user, method, client_ip, reason |
| `AuthRateLimited` | Authentication rate limited | client_ip, attempts |
| `SessionStart` | Session started | session_id, user, client_ip |
| `SessionEnd` | Session ended | session_id, user, duration |
| `CommandExecuted` | Command executed | session_id, user, command |
| `CommandBlocked` | Command blocked by policy | session_id, user, command, reason |
| `FileOpenRead` | File opened for reading | path, user |
| `FileOpenWrite` | File opened for writing | path, user |
| `FileRead` | File read operation | path, bytes |
| `FileWrite` | File write operation | path, bytes |
| `FileClose` | File closed | path |
| `FileUploaded` | File upload completed | path, bytes, user |
| `FileDownloaded` | File download completed | path, bytes, user |
| `FileDeleted` | File deleted | path, user |
| `FileRenamed` | File renamed | path, dest_path, user |
| `DirectoryCreated` | Directory created | path, user |
| `DirectoryDeleted` | Directory deleted | path, user |
| `DirectoryListed` | Directory listed | path, user |
| `TransferDenied` | Transfer blocked by filter | path, rule, user |
| `TransferAllowed` | Transfer explicitly allowed | path, rule, user |
| `IpBlocked` | IP address blocked | client_ip, reason |
| `IpUnblocked` | IP address unblocked | client_ip |
| `SuspiciousActivity` | Suspicious activity detected | client_ip, details |

### Event Structure

Each audit event contains:

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "timestamp": "2026-01-24T12:00:00.000Z",
  "event_type": "AuthSuccess",
  "session_id": "session-123",
  "user": "johndoe",
  "client_ip": "192.168.1.100",
  "protocol": "ssh",
  "result": "success",
  "details": {
    "method": "publickey",
    "key_type": "ssh-ed25519"
  }
}
```

## Exporters

### File Exporter

Writes events to a file in JSON Lines format (one JSON object per line).

```yaml
audit:
  exporters:
    - type: file
      path: /var/log/bssh/audit.log
```

**Output Format:**
```json
{"id":"...","timestamp":"2026-01-24T12:00:00Z","event_type":"SessionStart",...}
{"id":"...","timestamp":"2026-01-24T12:00:01Z","event_type":"CommandExecuted",...}
```

**File Rotation:**

Use logrotate for log rotation:

```bash
# /etc/logrotate.d/bssh
/var/log/bssh/*.log {
    daily
    rotate 90
    compress
    delaycompress
    missingok
    notifempty
    create 0600 root root
    postrotate
        # Signal bssh-server to reopen log files if needed
        systemctl reload bssh-server 2>/dev/null || true
    endscript
}
```

### OpenTelemetry Exporter

Sends events to an OpenTelemetry Collector via OTLP/gRPC.

```yaml
audit:
  exporters:
    - type: otel
      endpoint: http://otel-collector:4317
```

**OpenTelemetry Collector Configuration:**

```yaml
# otel-collector-config.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  batch:
    timeout: 1s
    send_batch_size: 100

exporters:
  # Export to Jaeger
  jaeger:
    endpoint: jaeger:14250
    tls:
      insecure: true

  # Export to Elasticsearch
  elasticsearch:
    endpoints: ["https://elasticsearch:9200"]
    logs_index: bssh-audit

  # Export to file
  file:
    path: /var/log/otel/bssh-audit.json

service:
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [elasticsearch, file]
```

### Logstash Exporter

Sends events directly to Logstash over TCP.

```yaml
audit:
  exporters:
    - type: logstash
      host: logstash.example.com
      port: 5044
```

**Logstash Configuration:**

```ruby
# logstash.conf
input {
  tcp {
    port => 5044
    codec => json_lines
  }
}

filter {
  # Parse timestamp
  date {
    match => ["timestamp", "ISO8601"]
  }

  # Add geo-IP for client addresses
  if [client_ip] {
    geoip {
      source => "client_ip"
    }
  }

  # Tag security events
  if [event_type] in ["AuthFailure", "IpBlocked", "SuspiciousActivity"] {
    mutate {
      add_tag => ["security_event"]
    }
  }
}

output {
  elasticsearch {
    hosts => ["elasticsearch:9200"]
    index => "bssh-audit-%{+YYYY.MM.dd}"
  }
}
```

## Log Analysis

### Common Queries

**Failed Authentication Attempts:**
```bash
# From JSON Lines file
grep '"event_type":"AuthFailure"' /var/log/bssh/audit.log | \
  jq -r '[.timestamp, .user, .client_ip] | @tsv'
```

**Sessions by User:**
```bash
grep '"event_type":"SessionStart"' /var/log/bssh/audit.log | \
  jq -r '.user' | sort | uniq -c | sort -rn
```

**File Transfers:**
```bash
grep -E '"event_type":"(FileUploaded|FileDownloaded)"' /var/log/bssh/audit.log | \
  jq -r '[.timestamp, .event_type, .user, .path, .bytes] | @tsv'
```

**Blocked IPs:**
```bash
grep '"event_type":"IpBlocked"' /var/log/bssh/audit.log | \
  jq -r '[.timestamp, .client_ip, .details.reason] | @tsv'
```

### Elasticsearch Queries

**Authentication Failures in Last Hour:**
```json
{
  "query": {
    "bool": {
      "must": [
        {"term": {"event_type": "AuthFailure"}},
        {"range": {"timestamp": {"gte": "now-1h"}}}
      ]
    }
  },
  "aggs": {
    "by_ip": {
      "terms": {"field": "client_ip"}
    }
  }
}
```

**Top Users by Session Count:**
```json
{
  "query": {
    "term": {"event_type": "SessionStart"}
  },
  "aggs": {
    "by_user": {
      "terms": {"field": "user", "size": 10}
    }
  }
}
```

## Integration Examples

### Grafana Dashboard

Create alerts for security events:

```yaml
# Grafana alert rule
groups:
  - name: bssh-security
    rules:
      - alert: HighAuthFailureRate
        expr: |
          sum(rate(bssh_auth_failures_total[5m])) > 10
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: High authentication failure rate

      - alert: IPBlocked
        expr: |
          increase(bssh_ip_blocked_total[1m]) > 0
        for: 0m
        labels:
          severity: info
        annotations:
          summary: IP address blocked due to failed auth attempts
```

### SIEM Integration

**Splunk:**

Configure HTTP Event Collector (HEC) via OpenTelemetry Collector:

```yaml
exporters:
  splunk_hec:
    token: "<your-hec-token>"
    endpoint: "https://splunk:8088/services/collector"
    source: "bssh-server"
    sourcetype: "bssh:audit"
```

**Datadog:**

```yaml
exporters:
  datadog:
    api:
      key: "<your-api-key>"
    logs:
      enabled: true
```

### Security Automation

**Automatic IP Blocking with fail2ban:**

```ini
# /etc/fail2ban/filter.d/bssh.conf
[Definition]
failregex = "event_type":"AuthFailure".*"client_ip":"<HOST>"
ignoreregex =

# /etc/fail2ban/jail.d/bssh.conf
[bssh]
enabled = true
filter = bssh
logpath = /var/log/bssh/audit.log
maxretry = 5
bantime = 3600
findtime = 600
```

## Best Practices

### 1. Enable Audit Logging in Production

Always enable audit logging for production deployments:

```yaml
audit:
  enabled: true
```

### 2. Use Multiple Exporters

Send logs to multiple destinations for redundancy:

```yaml
audit:
  exporters:
    - type: file
      path: /var/log/bssh/audit.log
    - type: otel
      endpoint: http://otel-collector:4317
```

### 3. Protect Audit Logs

Secure audit log files:

```bash
chmod 600 /var/log/bssh/audit.log
chown root:root /var/log/bssh/audit.log
```

### 4. Retain Logs Appropriately

Configure retention based on compliance requirements:
- SOC 2: Minimum 1 year
- HIPAA: Minimum 6 years
- PCI DSS: Minimum 1 year
- GDPR: As long as necessary, minimize data

### 5. Monitor Security Events

Set up alerts for:
- High authentication failure rates
- IP blocks
- Unusual session patterns
- Suspicious file access

### 6. Regular Log Review

Schedule regular review of audit logs:
- Daily: Security events (AuthFailure, IpBlocked)
- Weekly: Session patterns, user activity
- Monthly: Overall trends, compliance reports

### 7. Avoid Logging Sensitive Data

Be aware that command execution events may contain sensitive data. Consider:
- Filtering commands before logging
- Encrypting audit logs at rest
- Restricting access to audit logs

## Troubleshooting

### Logs Not Being Written

1. Check if audit is enabled:
   ```yaml
   audit:
     enabled: true
   ```

2. Verify file permissions:
   ```bash
   ls -la /var/log/bssh/
   ```

3. Check disk space:
   ```bash
   df -h /var/log
   ```

### OpenTelemetry Connection Failed

1. Verify endpoint is reachable:
   ```bash
   nc -zv otel-collector 4317
   ```

2. Check collector logs:
   ```bash
   docker logs otel-collector
   ```

### High Log Volume

1. Consider sampling for high-traffic deployments
2. Adjust log rotation settings
3. Filter verbose events (FileRead/FileWrite)

## See Also

- [Server Configuration]./architecture/server-configuration.md
- [Security Guide]./security.md
- [Container Deployment]./container-deployment.md