Skip to content

Commit 6a51659

Browse files
Feature/add auth (#65)
* Add auth * Add auto refresh * fix autorefresh bar * Add misc fixed and improvements * Update Changelog
1 parent f9d5b06 commit 6a51659

33 files changed

+2455
-141
lines changed

CHANGELOG.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,114 @@
22

33
All notable changes to portracker will be documented in this file.
44

5+
## [Unreleased]
6+
7+
### Security
8+
9+
- **Authentication**: Optional authentication to secure dashboard access using `ENABLE_AUTH=true`
10+
- **[sub]** Disabled by default for backward compatibility
11+
- **[sub]** Recovery mode accessible via `RECOVERY_MODE=true` if you lose your password
12+
- **[sub]** When recovery mode is enabled, a time-limited recovery code (valid 15 minutes) appears in the logs to use on the login page with any username
13+
14+
### Dashboard
15+
16+
- **Auto-Refresh**: Added a toggle to auto-refresh ports and services every 30 seconds
17+
518
## [1.1.1] - 2025-01-17
619

7-
### Features
20+
### Server Integrations
21+
822
- **TrueNAS Enhanced Features**: Add your TrueNAS API key directly from the UI to unlock VM and LXC container monitoring with step-by-step setup instructions
923

1024
### Fixes
25+
1126
- **TrueNAS API Key Revocation**: Fixed automatic key revocation issue by prioritizing secure WebSocket connections
1227
- **Virtual Machines & Containers**: VMs and LXC containers now display correctly with icons and badges to distinguish between them
1328
- **Debug Logging**: DEBUG environment variable now properly enables debug output
1429

1530
## [1.1.0] - 2025-08-23
1631

17-
### Frontend & Backend
32+
### Dashboard
33+
1834
- **System Port Name Fix**: Fixed the issue where system ports were incorrectly displayed as "unknown".
1935
- **Consistent Status Indicators**: Improved status indicators for system ports to ensure consistency.
2036

2137
## [1.0.8] - 2025-08-20
2238

23-
### Frontend
24-
- **Batch rename migration fix**: Fix migration issue affecting batch rename operations so renamed services persist correctly.
39+
### Dashboard
2540

26-
### Dev
41+
- **Batch rename migration fix**: Fix migration issue affecting batch rename operations so renamed services persist correctly.
2742
- **Misc.**: minor migration-related fix for batch rename flow.
2843

2944
## [1.0.7] - 2025-08-19
3045

31-
### Frontend
46+
### Dashboard
47+
3248
- **Service renaming**: Allow renaming services from the UI.
3349
- **Batch actions**: Add selection and batch operations for services and ports (ignore, add note, etc.).
3450
- **Internal / Port display fixes**: Fix display issues so internal and published ports are shown correctly; fix select-box overlap.
3551

3652
### Backend
53+
3754
- **Port protocol reporting**: Ensure ports include protocol information so reported mappings are accurate.
3855

3956
## [1.0.6] - 2025-08-15
4057

41-
### Frontend
58+
### Dashboard
59+
4260
- **Container Details Drawer**: New slide-out panel to show detailed information for Docker containers including stats, labels, mounts, and environment variables
4361
- **Internal Port Display**: UI now correctly shows and differentiates internal-only ports from published ports with health status monitoring
4462
- **Global Search**: Search bar now includes an option to search across all servers simultaneously
4563
- **What's New**: Automatic notification system to stay updated with new features when releasing new versions
4664

47-
### Backend
65+
### Data
66+
4867
- **Collector Caching**: Added caching mechanism to all data collectors to reduce duplicate requests and improve data refresh speed
4968

5069
## [1.0.5] - 2025-08-09
5170

52-
### Backend
71+
### Server Integrations
72+
5373
- **Dockerode Integration**: Switched to use the dockerode library for more reliable Docker API interactions instead of shell commands
5474
- **Centralized Logging**: All collectors now use a single Logger class for consistent and structured logging throughout the application
5575

5676
## [1.0.4] - 2025-08-09
5777

58-
### Frontend
78+
### Dashboard
79+
5980
- **Enhanced Service Detection**: Improved identification and categorization of running services with Single Page Application (SPA) detection support
6081
- **Port Status Indicators**: Added clear visual distinction between different types of ports (published vs internal) with detailed status information
6182

62-
### Backend
83+
### Server Integrations
84+
6385
- **Removed network_mode: host Requirement**: Eliminated the need for Docker host networking mode by implementing direct /proc filesystem parsing for better security
6486
- **Advanced Port Detection**: Enhanced system for more accurate container and system port identification using multiple detection methods
6587
- **Improved Container Introspection**: Better error handling and fallback strategies across different platforms for reliable port collection
6688

6789
## [1.0.3] - 2025-08-07
6890

69-
### Infrastructure
91+
### Data
92+
7093
- **Simplified Docker Dependencies**: Streamlined system requirements - no longer requires mounting additional system sockets for container information and support for docker proxy.
7194
- **Enhanced Data Accuracy**: Improved container information display with more accurate timestamps and metadata parsing
7295

7396
## [1.0.2] - 2025-07-11
7497

75-
### Security & Improvements
98+
### Security
99+
76100
- **Security Hardening**: Key security aspects addressed
77101
- **Data Collection**: Improved data collection accuracy
78102

79103
## [1.0.1] - 2025-07-10
80104

81105
### Initial Improvements
106+
82107
- Various fixes and improvements after initial release
83108

84109
## [1.0.0] - 2025-07-07
85110

86-
### Initial Release
111+
### Dashboard
112+
87113
- **Multi-platform Port Tracking**: Initial release of portracker with support for monitoring ports across multiple servers
88114
- **Docker Integration**: Native Docker container port monitoring
89115
- **Web Interface**: Clean, responsive web interface for port management

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,40 @@ Configure `portracker` using environment variables.
174174
| `PORT`\* | The port the web application will run on. | `4999` |
175175
| `DATABASE_PATH`\* | Path inside the container to the SQLite database file. | `/data/portracker.db` |
176176
| `TRUENAS_API_KEY` | Optional API key for enhanced TrueNAS data collection. | ` ` |
177+
| `ENABLE_AUTH` | Set to `true` to enable authentication (v1.2.0+). | `false` |
178+
| `SESSION_SECRET` | Secret key for session encryption (recommended when auth enabled). | _random_ |
177179
| `CACHE_TIMEOUT_MS` | Duration in milliseconds to cache scan results. | `60000` |
178180
| `DISABLE_CACHE` | Set to `true` to disable all caching. | `false` |
179181
| `INCLUDE_UDP` | Set to `true` to include UDP ports in scans. | `false` |
180182
| `DEBUG` | Set to `true` for verbose application logging. | `false` |
181183

182184
<sub>\*_Required_</sub>
183185

186+
### Authentication Setup (v1.2.0+)
187+
188+
Portracker includes optional authentication to secure dashboard access:
189+
190+
1. **Enable Authentication**: Set `ENABLE_AUTH=true` in your environment variables
191+
2. **First-Time Setup**: On first access, you'll see a setup wizard to create the admin account
192+
3. **Login**: Use your admin credentials to access the dashboard
193+
4. **Production Recommendation**: Set a custom `SESSION_SECRET` for secure session management
194+
195+
**Example with Authentication:**
196+
197+
```yaml
198+
services:
199+
portracker:
200+
image: mostafawahied/portracker:latest
201+
environment:
202+
- ENABLE_AUTH=true
203+
- SESSION_SECRET=your-random-secret-here-change-this
204+
```
205+
206+
**Important Notes:**
207+
- Authentication is **disabled by default** for backward compatibility
208+
- When enabled, the dashboard requires login but API endpoints for peer communication remain accessible
209+
- API key authentication for peer-to-peer communication is planned for v1.3.0
210+
184211
## Technical Stack
185212
186213
- **Backend**: Node.js, Express, WebSocket, better-sqlite3
@@ -191,9 +218,10 @@ Configure `portracker` using environment variables.
191218
192219
Future development is focused on improving the application based on community feedback. Key areas include:
193220
194-
- Adding user authentication.
195-
- Expanding the library of platform-specific collectors for other host systems.
196-
- Addressing bugs and incorporating requested changes from the community.
221+
- ~~Adding user authentication~~ ✅ **Added in v1.2.0** (optional authentication with setup wizard)
222+
- Adding API key authentication for peer-to-peer communication (planned for v1.3.0)
223+
- Expanding the library of platform-specific collectors for other host systems
224+
- Addressing bugs and incorporating requested changes from the community
197225
198226
## Star History
199227

backend/db.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ if (!tableExists) {
9797
);
9898
`);
9999
createCustomServiceNamesTable.run();
100+
101+
const createUsersTable = db.prepare(`
102+
CREATE TABLE IF NOT EXISTS users (
103+
id TEXT PRIMARY KEY,
104+
username TEXT UNIQUE NOT NULL,
105+
password_hash TEXT NOT NULL,
106+
created_at INTEGER NOT NULL,
107+
last_login INTEGER
108+
);
109+
`);
110+
createUsersTable.run();
100111
} else {
101112
try {
102113
const notesColumns = db.prepare("PRAGMA table_info(notes)").all();
@@ -484,6 +495,26 @@ if (!tableExists) {
484495
logger.info('Schema migration: custom_service_names table updated with protocol support');
485496
}
486497

498+
const usersTableExists = db
499+
.prepare(
500+
"SELECT name FROM sqlite_master WHERE type='table' AND name='users'"
501+
)
502+
.get();
503+
504+
if (!usersTableExists) {
505+
logger.info('Schema migration: Creating "users" table for authentication');
506+
db.exec(`
507+
CREATE TABLE users (
508+
id TEXT PRIMARY KEY,
509+
username TEXT UNIQUE NOT NULL,
510+
password_hash TEXT NOT NULL,
511+
created_at INTEGER NOT NULL,
512+
last_login INTEGER
513+
);
514+
`);
515+
logger.info('Schema migration: users table created successfully');
516+
}
517+
487518
} catch (migrationError) {
488519
logger.error(
489520
"FATAL: Database schema migration failed:",

0 commit comments

Comments
 (0)