|
| 1 | +# OpenSPP Attachment Antivirus Scan |
| 2 | + |
| 3 | +System-wide antivirus scanning for file attachments in OpenSPP. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This module provides automatic malware scanning for all file attachments uploaded to the |
| 8 | +system using ClamAV antivirus engine. It integrates with the `queue_job` module for |
| 9 | +asynchronous scanning to avoid blocking file uploads. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- **Automatic Scanning**: All binary attachments are automatically queued for malware |
| 14 | + scanning upon upload |
| 15 | +- **Configurable Backends**: Support for ClamAV via Unix socket or network connection |
| 16 | +- **Quarantine**: Infected files are automatically quarantined and access is blocked |
| 17 | +- **Security Notifications**: Security administrators are notified when malware is |
| 18 | + detected |
| 19 | +- **Manual Rescans**: Administrators can manually trigger rescans of attachments |
| 20 | +- **File Size Limits**: Configurable maximum file size to avoid scanning large files |
| 21 | +- **Scan Timeouts**: Configurable timeout to prevent long-running scans |
| 22 | + |
| 23 | +## Dependencies |
| 24 | + |
| 25 | +- `base`: Odoo base module |
| 26 | +- `queue_job`: For asynchronous job processing |
| 27 | +- `spp_security`: OpenSPP security module for security groups |
| 28 | +- `pyclamd`: Python library for ClamAV integration (external) |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +1. Install ClamAV on your server: |
| 33 | + |
| 34 | + ```bash |
| 35 | + # Ubuntu/Debian |
| 36 | + sudo apt-get install clamav clamav-daemon |
| 37 | + |
| 38 | + # Start the daemon |
| 39 | + sudo systemctl start clamav-daemon |
| 40 | + sudo systemctl enable clamav-daemon |
| 41 | + ``` |
| 42 | + |
| 43 | +2. Install the Python library: |
| 44 | + |
| 45 | + ```bash |
| 46 | + pip install pyclamd |
| 47 | + ``` |
| 48 | + |
| 49 | +3. Install the module in Odoo: |
| 50 | + - Update the apps list |
| 51 | + - Search for "OpenSPP Attachment Antivirus Scan" |
| 52 | + - Click Install |
| 53 | + |
| 54 | +## Configuration |
| 55 | + |
| 56 | +### Scanner Backend Setup |
| 57 | + |
| 58 | +1. Go to **Settings > Technical > Antivirus Scanners** |
| 59 | +2. Edit the "Default ClamAV Scanner" record |
| 60 | +3. Configure the connection settings: |
| 61 | + - **Backend Type**: Choose "ClamAV Unix Socket" or "ClamAV Network" |
| 62 | + - **Socket Path**: Path to ClamAV socket (default: `/var/run/clamav/clamd.sock`) |
| 63 | + - Or **Host/Port**: Network connection details |
| 64 | + - **Max File Size**: Maximum file size to scan in MB (default: 100) |
| 65 | + - **Scan Timeout**: Maximum time for scan in seconds (default: 60) |
| 66 | +4. Enable the backend by toggling the "Active" button |
| 67 | +5. Click "Test Connection" to verify the configuration |
| 68 | + |
| 69 | +### Security Groups |
| 70 | + |
| 71 | +- **Antivirus Administrator** (`group_av_admin`): Can manage scanner backends and view |
| 72 | + detailed scan results |
| 73 | + |
| 74 | +## Usage |
| 75 | + |
| 76 | +### Automatic Scanning |
| 77 | + |
| 78 | +When a user uploads a file: |
| 79 | + |
| 80 | +1. The attachment is created immediately |
| 81 | +2. A scan job is queued in the background |
| 82 | +3. The scan status shows "Pending Scan" |
| 83 | +4. Once scanned, the status updates to: |
| 84 | + - **Clean**: No malware detected |
| 85 | + - **Infected**: Malware detected (file is quarantined) |
| 86 | + - **Error**: Scan failed |
| 87 | + - **Skipped**: File too large or no scanner configured |
| 88 | + |
| 89 | +### Viewing Scan Status |
| 90 | + |
| 91 | +Scan status is visible on the attachment form and list views: |
| 92 | + |
| 93 | +- Navigate to any attachment (e.g., in Documents or via Technical > Attachments) |
| 94 | +- Check the "Antivirus Scan" section for scan status and details |
| 95 | + |
| 96 | +### Manual Rescans |
| 97 | + |
| 98 | +As an AV Administrator: |
| 99 | + |
| 100 | +1. Open an attachment |
| 101 | +2. Click the "Rescan" button |
| 102 | +3. The file is queued for scanning |
| 103 | + |
| 104 | +### Infected Files |
| 105 | + |
| 106 | +When malware is detected: |
| 107 | + |
| 108 | +1. The file is marked as "Infected" |
| 109 | +2. The threat name is recorded |
| 110 | +3. The file is quarantined (access to file data is blocked) |
| 111 | +4. Security administrators receive an activity notification |
| 112 | +5. The file cannot be downloaded until reviewed |
| 113 | + |
| 114 | +## Technical Details |
| 115 | + |
| 116 | +### Models |
| 117 | + |
| 118 | +#### `spp.av.scanner.backend` |
| 119 | + |
| 120 | +Stores configuration for antivirus scanner backends. |
| 121 | + |
| 122 | +**Key Fields**: |
| 123 | + |
| 124 | +- `backend_type`: Type of scanner (ClamAV socket or network) |
| 125 | +- `is_active`: Whether this backend is active |
| 126 | +- `clamd_socket_path`: Path to ClamAV Unix socket |
| 127 | +- `clamd_host`, `clamd_port`: Network connection details |
| 128 | +- `max_file_size_mb`: Maximum file size to scan |
| 129 | +- `scan_timeout_seconds`: Scan timeout |
| 130 | + |
| 131 | +**Key Methods**: |
| 132 | + |
| 133 | +- `scan_binary(binary_data, filename)`: Scan binary data for malware |
| 134 | +- `test_connection()`: Test connection to scanner |
| 135 | +- `get_active_scanner()`: Get the active scanner backend |
| 136 | + |
| 137 | +#### `ir.attachment` (inherited) |
| 138 | + |
| 139 | +Extended with antivirus scan fields and logic. |
| 140 | + |
| 141 | +**New Fields**: |
| 142 | + |
| 143 | +- `scan_status`: Status of malware scan |
| 144 | +- `scan_date`: When the file was scanned |
| 145 | +- `scan_result`: Detailed scan result (JSON) |
| 146 | +- `threat_name`: Name of detected threat |
| 147 | +- `is_quarantined`: Whether file is quarantined |
| 148 | + |
| 149 | +**Key Methods**: |
| 150 | + |
| 151 | +- `_scan_for_malware()`: Async job to scan attachment |
| 152 | +- `_quarantine()`: Quarantine infected file |
| 153 | +- `_notify_security_admins()`: Notify admins of infection |
| 154 | +- `action_rescan()`: Manually trigger rescan |
| 155 | + |
| 156 | +### Queue Jobs |
| 157 | + |
| 158 | +The module uses `queue_job` for asynchronous scanning: |
| 159 | + |
| 160 | +- Scans are queued when attachments are created or updated |
| 161 | +- Priority 20 for automatic scans, priority 10 for manual rescans |
| 162 | +- Jobs are named "Scan attachment {id} for malware" |
| 163 | + |
| 164 | +### Security |
| 165 | + |
| 166 | +- AV Administrators can manage scanner backends |
| 167 | +- All users can view scan status on their attachments |
| 168 | +- Quarantined files block access to binary data via `read()` override |
| 169 | + |
| 170 | +## Logging |
| 171 | + |
| 172 | +The module uses structured logging: |
| 173 | + |
| 174 | +- Info level: Scan results, connection tests |
| 175 | +- Warning level: Malware detections, configuration issues |
| 176 | +- Error level: Scan failures, connection errors |
| 177 | + |
| 178 | +No PII (personally identifiable information) is logged. |
| 179 | + |
| 180 | +## Performance Considerations |
| 181 | + |
| 182 | +- File scanning is asynchronous via queue_job |
| 183 | +- Large files can be skipped via `max_file_size_mb` setting |
| 184 | +- Scan timeouts prevent long-running operations |
| 185 | +- Failed scans don't block file uploads |
| 186 | + |
| 187 | +## Limitations |
| 188 | + |
| 189 | +- Currently only supports ClamAV |
| 190 | +- Requires ClamAV daemon to be running |
| 191 | +- Files are scanned after upload (not during) |
| 192 | +- Very large files may be skipped |
| 193 | + |
| 194 | +## Future Enhancements |
| 195 | + |
| 196 | +- Support for additional antivirus engines |
| 197 | +- Real-time scanning before upload completion |
| 198 | +- Scan result caching |
| 199 | +- Scheduled rescans of all attachments |
| 200 | +- Quarantine management interface |
| 201 | +- Detailed scan statistics and reports |
| 202 | + |
| 203 | +## License |
| 204 | + |
| 205 | +LGPL-3 |
| 206 | + |
| 207 | +## Author |
| 208 | + |
| 209 | +OpenSPP.org |
| 210 | + |
| 211 | +## Maintainers |
| 212 | + |
| 213 | +- jeremi |
| 214 | +- gonzalesedwin1123 |
| 215 | +- reichie020212 |
0 commit comments