Add SSHV (VPS console), tips persistence & scheduler improvements, HTTPS health server, admin-mode UX and deployment updates - #75
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis pull request introduces infrastructure modernization and security hardening: removing Docker support, adding TLS-based health checks, implementing a new SSHV console subsystem for admin operations, enhancing admin UI with view toggles, consolidating git ignore patterns, hardening systemd service configuration with sandboxing, and establishing security policies alongside MIT licensing. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Telegram Client
participant Server as index.js
participant SessionStore as SSHV Session Store
participant ChildProcess as child_process
participant Disk as File System
Client->>Server: Open SSHV console (open_sshv)
Server->>SessionStore: Create new session with TTL
SessionStore->>Disk: Persist session to sshv-sessions.json
Client->>Server: Send command (run_sshv_cmd)
Server->>SessionStore: Load session, validate TTL
alt Command is 'cd'
Server->>SessionStore: Update session cwd
else Command is editor mode
Server->>Client: Render editor keyboard
Client->>Server: Editor input (edit_save/edit_cancel)
Server->>Disk: Write/discard changes
else Regular command
Server->>ChildProcess: Execute via spawn
ChildProcess->>ChildProcess: Run with cwd
ChildProcess-->>Server: Return stdout/stderr
end
Server->>SessionStore: Update session state
SessionStore->>Disk: Persist session to sshv-sessions.json
Server->>Client: Render console output
Client->>Server: Exit console (exit_sshv)
Server->>SessionStore: Destroy session
SessionStore->>Disk: Remove session data
sequenceDiagram
participant HealthCheck as Health Check Process
participant ConfigReader as Config Reader
participant TLS as TLS System
participant Server as HTTP/HTTPS Server
participant Endpoint as /health Endpoint
HealthCheck->>ConfigReader: Read PORT, HTTPS_KEY_PATH, HTTPS_CERT_PATH
ConfigReader-->>HealthCheck: Environment values
HealthCheck->>TLS: Check if TLS certs/key available
alt TLS certs valid
TLS-->>HealthCheck: Use HTTPS
HealthCheck->>Server: Connect to https://localhost:PORT/health
else TLS certs invalid/missing
TLS-->>HealthCheck: Fall back to HTTP
HealthCheck->>Server: Connect to http://localhost:PORT/health
end
Server->>Endpoint: Route request
Endpoint-->>Server: Return health status
Server-->>HealthCheck: Health response
HealthCheck->>HealthCheck: Determine overall health
Estimated Code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Nitpicks 🔍
|
| mkdir -p "$PROJECT_DIR/data" | ||
| mkdir -p "$PROJECT_DIR/data/backups" | ||
| touch "$MAIN_LOG" "$ERROR_LOG" "$ADMIN_EVENTS_LOG" "$SSHV_SESSIONS_FILE" # create if missing; safe on existing files | ||
|
|
There was a problem hiding this comment.
Suggestion: The data directory and JSON/log files are created as root-owned by this script, but the systemd unit is configured to run the Node process as an unprivileged user; this will cause permission denied errors when the app tries to write admin events and SSHV session state. Ensuring the data directory is owned by the service user when it exists fixes this mismatch. [logic error]
Severity Level: Major ⚠️
- ❌ SSHV sessions cannot persist to data/sshv-sessions.json.
- ❌ Admin events log file not writable; audit trail lost.
- ⚠️ Data directory permissions may block other JSON persist helpers.| # Ensure data directory and its files are writable by the service user when it exists | |
| if id -u "$APP_NAME" >/dev/null 2>&1; then | |
| chown -R "$APP_NAME":"$APP_NAME" "$PROJECT_DIR/data" | |
| fi |
Steps of Reproduction ✅
1. Create a dedicated system user for the service so `id -u runewager` succeeds; this
causes `ensure_systemd_service()` in `prod-run.sh` (lines 187–201) to generate a unit with
`User=runewager`/`Group=runewager`.
2. As root, run `/workspace/Runewager/prod-run.sh`. It creates `$PROJECT_DIR/data` and
`$PROJECT_DIR/data/backups`, then touches `$PROJECT_DIR/data/admin-events.log` and
`$PROJECT_DIR/data/sshv-sessions.json` as root at `prod-run.sh:113–116`, leaving the
directory and files owned by root with default 0755/0644-style permissions.
3. The same script restarts the service via systemd at `prod-run.sh:385–412`, so
`index.js` now runs as the unprivileged `runewager` user while the `data/` directory and
its files remain root-owned and not writable by `runewager`.
4. Trigger an admin feature that persists state: (a) use the `/sshv` admin console so its
session code calls `saveJson(sshvSessionsFile, entries)` at `index.js:969` with
`sshvSessionsFile` defined at `index.js:206`, which goes through `writeFileAtomic()` at
`index.js:2264–10`, or (b) execute any admin action that calls `adminLog()` at
`index.js:2141–24` to append to `admin-events.log`. In both cases the Node process,
running as `runewager`, attempts to write under `$PROJECT_DIR/data` but lacks write
permission due to root ownership, causing `fs.writeFileSync`/`fs.appendFileSync` to
receive EACCES and preventing SSHV session and admin event data from being persisted.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** prod-run.sh
**Line:** 117:117
**Comment:**
*Logic Error: The data directory and JSON/log files are created as root-owned by this script, but the systemd unit is configured to run the Node process as an unprivileged user; this will cause permission denied errors when the app tries to write admin events and SSHV session state. Ensuring the data directory is owned by the service user when it exists fixes this mismatch.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
User description
Motivation
Description
LICENSE(MIT) andSECURITY.md; removedDockerfileand updatedREADME.mdto reflect systemd deployment.WEBAPP_HMAC_KEYguidance;.gitignoreupdated to include*.env, data and logs layout changes.index.jschanges: replaced internalhttpusage with HTTPS-aware health checks, added TLS cert path validation, implementedvalidateSafePathfor safe data I/O, and switched WebApp init-data verification to useWEBAPP_HMAC_KEYinstead of a constant./sshv): session store, editor mode, command execution with safety checks (blocked patterns, dangerous command confirmation), session persistence todata/sshv-sessions.json, lifecycle/GC, buttons and callbacks for run/lock/refresh/exit, and UI rendering in chat.tipsStorepersistence todata/helpful_messages.json, import/overwrite via JSON payloads in/tipaddand/tipedit, prevented consecutive duplicate posts usinglastSentTipId, permission check before posting, and save/load helpers (saveHelpfulMessages/loadHelpfulMessages).HTTPS_KEY_PATH/HTTPS_CERT_PATHare provided and valid;startHealthServerwill fall back to HTTP and exposes/healthand/metricson loopback only.loadJson,writeFileAtomic, and related persistence now leverage safe path validation; admin events are appended todata/admin-events.log.prod-run.sh) andrunewager.serviceupdates: ensure runtime directories/files exist (data/*, admin-events, sshv sessions), health URL resolver and checks (HTTP/HTTPS), improved logrotate config includes admin events file, creation of systemd service with secure user/group and tightened service sandbox options, health wait-and-report logic, and enhanced final status output.Testing
CI=trueto ensure the bot runtime file loads safely without starting services; this succeeded (no runtime throw).prod-run.shin a non-production/dry environment to validate directory creation, env handling and health URL resolution; automated health probe logic (HTTP/HTTPS) was exercised and returned expected status in the test environment.Codex Task
CodeAnt-AI Description
Add admin VPS console, persistent helpful messages, HTTPS health server, and refined admin UI
What Changed
Impact
✅ Shorter admin debugging time✅ Fewer duplicate tips✅ More accurate health checks💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
New Features
Improvements
Documentation