Skip to content

Commit b7ec36f

Browse files
Update documentation based on feedback
1 parent 0443447 commit b7ec36f

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

docs/reference/polykey-core/audit.md

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The `Audit` class is the main component of the audit system. It provides methods
2020

2121
Audit events have the following structure:
2222

23-
- `id`: A unique identifier for the event
23+
- `id`: A unique identifier for the event (AuditEventId)
2424
- `path`: An array of strings representing the event category/path
2525
- `data`: The event data, which can contain any relevant information about the event
2626

@@ -36,24 +36,41 @@ Audit events can be retrieved from a node using the `nodesAuditEventsGet` RPC me
3636

3737
Example usage through the node connection:
3838

39-
39+
```typescript
40+
// Retrieve audit events from a connected node
41+
const response = await nodeConnection.getClient().methods.nodesAuditEventsGet({
42+
seek: 0, // Start from the beginning or specific audit event ID
43+
seekEnd: Date.now(), // End at current time or specific audit event ID
44+
limit: 100, // Limit the number of results
45+
order: 'asc' // Order results (asc or desc)
46+
});
47+
48+
// Process the audit events
49+
for await (const auditEvent of response) {
50+
console.log(`Event ID: ${auditEvent.id}`);
51+
console.log(`Event Path: ${auditEvent.path.join('/')}`);
52+
console.log(`Event Data:`, auditEvent.data);
53+
}
54+
```
4055

4156
### Event Types
4257

4358
The audit system can record various types of events, including but not limited to:
4459

45-
- Node connection events
46-
- Authentication events
47-
- Vault operations
48-
- Secret access events
49-
- Permission changes
60+
- Node connection events (e.g., `['node', 'connection', 'forward']`)
61+
- Authentication events (e.g., `['auth', 'success']`, `['auth', 'failure']`)
62+
- Vault operations (e.g., `['vault', 'create']`, `['vault', 'delete']`)
63+
- Secret access events (e.g., `['secret', 'read']`, `['secret', 'write']`)
64+
- Permission changes (e.g., `['permission', 'grant']`, `['permission', 'revoke']`)
5065

51-
Each event type has a specific path structure and data format.
66+
Each event type has a specific path structure and data format. The path is an array of strings that categorizes the event, while the data contains relevant information specific to that event type.
5267

5368
## Security Considerations
5469

5570
Audit events are stored locally on the node and are only accessible to authorized users with appropriate permissions. When retrieving audit events from another node, proper authentication and authorization are required.
5671

72+
The audit system is designed to be secure and tamper-resistant, ensuring that audit events cannot be modified or deleted without proper authorization.
73+
5774
## Integration with Other Components
5875

5976
The audit system is integrated with various components of the Polykey system:
@@ -62,11 +79,35 @@ The audit system is integrated with various components of the Polykey system:
6279
- The agent service exposes audit functionality through RPC methods
6380
- Node connections can access audit events from connected nodes
6481

82+
Example of how the audit system is integrated with the PolykeyAgent:
83+
84+
```typescript
85+
// In PolykeyAgent.ts
86+
const agentService = agentServerManifest({
87+
audit: this.audit,
88+
acl: this.acl,
89+
db: this.db,
90+
keyRing: this.keyRing,
91+
// ... other components
92+
});
93+
```
94+
95+
## Implementation Details
96+
97+
The audit system is implemented using the following key files:
98+
99+
- `src/audit/Audit.ts`: The main Audit class implementation
100+
- `src/audit/types.ts`: Type definitions for audit events
101+
- `src/audit/utils.ts`: Utility functions for audit operations
102+
- `src/nodes/agent/handlers/NodesAuditEventsGet.ts`: Handler for retrieving audit events
103+
- `src/nodes/agent/callers/nodesAuditEventsGet.ts`: Caller for the audit events RPC method
104+
65105
## Future Enhancements
66106

67107
Future versions of the audit system may include:
68108

69-
- Additional event types
70-
- Enhanced filtering capabilities
71-
- Export functionality for audit logs
72-
- Integration with external logging systems
109+
- Additional event types for more comprehensive auditing
110+
- Enhanced filtering capabilities based on event paths and data
111+
- Export functionality for audit logs to common formats (CSV, JSON)
112+
- Integration with external logging systems (Syslog, ELK stack)
113+
- Real-time audit event notifications

0 commit comments

Comments
 (0)