Audit Logs
CONFOR maintains comprehensive audit logs of all significant system activities, enabling compliance tracking, security monitoring, and change history analysis.Overview
Audit logs in CONFOR capture:- User actions: Login, logout, CRUD operations
- Data changes: Before/after values for updates
- System events: Permission changes, exports, deletions
- Security events: Failed login attempts, password resets
AuditLog (using monthly partitioning for performance)
Audit Log Structure
Each audit log entry contains:| Field | Type | Description |
|---|---|---|
id | UUID | Unique log entry identifier |
organizationId | UUID | Organization scope (null for system-wide) |
userId | UUID | User who performed the action |
sessionId | UUID | Session identifier for tracking |
action | enum | Type of action (see below) |
entityType | string | Affected entity (e.g., “User”, “Role”, “ForestPatrimonyLevel2”) |
entityId | UUID | ID of affected entity |
entityName | string | Display name of affected entity |
oldValues | JSON | Previous state (for updates) |
newValues | JSON | New state (for creates/updates) |
changedFields | string[] | List of fields that changed |
ipAddress | string | IP address of request |
userAgent | string | Browser/client user agent |
requestId | UUID | Unique request identifier |
durationMs | integer | Operation duration in milliseconds |
statusCode | integer | HTTP status code |
errorMessage | string | Error details (if action failed) |
metadata | JSON | Additional context-specific data |
createdAt | timestamp | When the action occurred |
Audit Actions
From theAuditAction enum:
| Action | Description | Example |
|---|---|---|
CREATE | New entity created | User invited, role created |
UPDATE | Entity modified | User role changed, area updated |
DELETE | Entity removed | User deleted, role removed |
LOGIN | Successful login | User authenticated |
LOGOUT | User logged out | Session ended |
LOGIN_FAILED | Failed login attempt | Wrong password, locked account |
PASSWORD_RESET | Password changed/reset | User or admin password reset |
PERMISSION_CHANGE | Permissions modified | Role permissions updated |
EXPORT | Data exported | CSV/Excel export triggered |
VIEW | Sensitive data viewed | Report accessed, user details viewed |
Viewing Audit Logs
Navigate to Audit Page
From the dashboard, go to Auditoría in the main navigation.
You need
audit:READ permission to view audit logs.Review Log Entries
The audit log table displays:
- Acción: Type of action performed
- Entidad: Entity type affected
- Fecha: Timestamp of the action
- Acciones: Options to delete individual entries
createdAt in descending order (most recent first).Common Audit Scenarios
User Management Actions
When managing users, the following actions are logged: User Creation:Role and Permission Changes
Role Creation:Forest Patrimony Changes
Level 2 Unit Created:Login and Security Events
Successful Login:Data Export Actions
User Export:Deleting Audit Logs
Delete Individual Entry
Delete All Logs
Most compliance frameworks require audit logs to be immutable and retained for a minimum period (e.g., 1 year). Consider disabling the delete functionality in production environments.
Monthly Partitioning
CONFOR uses PostgreSQL table partitioning for audit logs: Purpose: Improve query performance and enable efficient archival. Structure:- Parent table:
audit_logs - Child tables:
audit_logs_YYYYMM(e.g.,audit_logs_202603)
Audit Log Queries
API Endpoints
Example: Fetch Recent Logs
Example: Query by User
Example: Query by Date Range
Example: Failed Login Analysis
Compliance and Security
Data Retention
Recommendation: Retain audit logs for at least 12 months to comply with common frameworks:- ISO 27001: Audit logs must be retained for analysis
- SOC 2: Log retention for security monitoring
- FSC Chain of Custody: Track forest product transactions (relevant for CONFOR)
- Archive old partitions to cold storage (e.g., S3)
- Compress archived partitions
- Drop partitions older than retention period
Access Control
Permissions:audit:READ- View audit logsaudit:DELETE- Delete audit logs (should be restricted)audit:ADMIN- Full audit log management
- Grant
audit:READto compliance/security teams - Restrict
audit:DELETEto system administrators only - Log access to audit logs themselves (meta-auditing)
Immutability
For high-security environments:- Disable delete functionality: Remove delete buttons from UI
- Database-level protection: Revoke DELETE permissions on
audit_logstable - Write-once storage: Export logs to immutable storage (WORM drives, append-only S3)
Troubleshooting
Logs Not Appearing
Check partition creation: Ensure partitions exist for the current month.Performance Issues
Symptom: Slow audit log queries. Solutions:-
Ensure indexes exist:
- Partition old data to archive tables
-
Increase PostgreSQL
work_memfor large queries
Disk Space Growth
Symptom: Audit logs consuming excessive disk space. Solutions:-
Archive old partitions:
-
Compress JSON fields: Use PostgreSQL
jsonbcompression -
Trim
metadatafields: Remove verbose/unnecessary data from logs
Best Practices
Don't Log Sensitive Data
Don't Log Sensitive Data
Avoid logging:
- Passwords (even hashed)
- API keys or tokens
- Credit card numbers
- Personal identification numbers
[REDACTED] in audit logs.Include Contextual Metadata
Include Contextual Metadata
Always log:
- User ID and session ID
- IP address and user agent
- Request ID for correlation
- Organization ID for multi-tenancy
Regular Audit Reviews
Regular Audit Reviews
Schedule periodic reviews:
- Weekly: Failed login attempts
- Monthly: Permission changes
- Quarterly: Data export patterns
- Annually: Full compliance audit
Alert on Suspicious Activity
Alert on Suspicious Activity
Set up automated alerts for:
- Multiple failed logins from same IP
- Mass data exports
- Admin permission grants
- After-hours access to sensitive data
Maintain Audit Trail Integrity
Maintain Audit Trail Integrity
- Never modify audit logs after creation
- Use database constraints to prevent updates
- Regularly backup audit log partitions
- Hash log entries for tamper detection (advanced)
Related Guides
- Managing Users - Actions that generate audit logs
- Configuring Roles - Permission changes are audited
- Forest Hierarchy - Patrimony changes are logged
- Importing Shapefiles - Import jobs are audited