# Waltermart dashboard: security notes

Hardening against the NetSolar Development and Hardening Manual v1.8. The run report (scorecard, verification
record, action list) is the PDF next to this file. This page holds what lives outside the code: server steps,
the nginx snippet, monitoring and the recurring checks.

Assurance tier (proposed): **Baseline**. Public read-only screens, no logins, no personal data, no database.
What needs protecting: the solarops HMAC secret, the OpenWeather key and the cache-clear token on each server.

## 1. Rotate the keys exposed on 2026-10-27 (RB-01 step 9)

The solarops HMAC secret and the OpenWeather key were pasted into a chat on 2026-10-27. Treat both as compromised
until they are replaced. Removing them from the chat is not enough.

1. OpenWeather: openweathermap.org > My API keys > Generate a new key > copy it. Do not delete the old one yet.
2. On each server that runs the dashboard (SolarOps-VM and MonitoringWM), put the new value in `.env` as
   `OPENWEATHER_KEY=` (and remove `openWeatherKey` from `config/config.json`), then
   `docker compose up -d --force-recreate`. Check that the weather tile shows on /kiosk, then delete the old key in OpenWeather.
3. solarops HMAC secret: generate a new value on the solarops host (`openssl rand -hex 32`) and set it as
   `API_HMAC_SECRET` in `/root/solaredge-api.env`. Every client that signs requests (this dashboard on both VMs, the
   Deno/AWS callers, the irradiance puller, the SolarOps web app, team scripts) needs the same new value. Switch them
   in one window: update the solarops env, recreate its container, then set `SOLAROPS_HMAC_SECRET` in each client
   and recreate them. Expect 401s from any client you missed: `docker logs waltermart-kiosk 2>&1 | grep 401`.
4. Remove the unused `MSSQL_*` lines from the dashboard's `.env` on SolarOps-VM (the app has not used them since
   the solarops switch). If that MSSQL password is shared with anything else, rotate it too.
5. Delete the legacy per-site SolarEdge `apiKey` / `siteApiSecret` entries from any `config/config.json` (the app
   no longer reads them). If those SolarEdge keys are still valid elsewhere, keep them only where they are used.
6. Lock the env file: `chmod 600 .env` in `/var/www/html/waltermart_dashboard_v2`. Keep `config/config.json`
   readable (644): it is copied into the image and read by the app as user `node`; 600 stops the app (EACCES).
   Keep secrets out of config.json (use `.env`) so 644 is safe.

Never paste the new values anywhere. To prove a key exists, print names only: `grep -o '^[A-Z_]*=' .env`.

## 2. nginx on SolarOps-VM (RB-06, RB-25, RB-27)

The app sends its own security headers (CSP, X-Frame-Options, nosniff, Referrer-Policy, Permissions-Policy).
nginx adds what only the edge can do. Back up first, then edit, test and reload:

```sh
cp /etc/nginx/sites-available/solarops /root/solarops.nginx.bak-$(date +%F)
nginx -t && systemctl reload nginx        # after each edit; restore the .bak if -t fails
```

In `/etc/nginx/nginx.conf`, inside `http { }`:

```nginx
server_tokens off;                                           # hide the nginx version
limit_req_zone $binary_remote_addr zone=wm_api:10m rate=10r/s; # per-visitor cap for the dashboard API
```

In the 443 `server { }` block of `sites-available/solarops`:

```nginx
add_header Strict-Transport-Security "max-age=31536000" always;   # HTTPS only for a year (whole host)
```

In the existing `location /waltermart-kiosk/ { }` block, keep the current `proxy_pass` and `sub_filter` lines and add:

```nginx
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # real client IP for the app's rate limit
proxy_set_header X-Forwarded-Proto $scheme;
limit_req zone=wm_api burst=40 nodelay;
limit_req_status 429;
client_max_body_size 16k;                                      # the app accepts no uploads
```

Note: an `add_header` inside a `location` replaces the server-level ones for that location. If the location
already has `add_header` lines, repeat the HSTS line there.

Unknown host names (RB-06 step 4): add a catch-all so requests with a forged `Host` get no site:

```nginx
server {
    listen 443 ssl default_server;
    listen 80 default_server;
    server_name _;
    ssl_certificate     /etc/ssl/<existing cert>.crt;   # any valid cert; the connection is dropped anyway
    ssl_certificate_key /etc/ssl/<existing key>.key;
    return 444;
}
```

Only add `default_server` if no other block already has it (`grep -rn default_server /etc/nginx/`).

Check from any PC afterwards (I re-run these on the next run):

```sh
curl -sI https://solarops.nsr.com.ph/waltermart-kiosk/summary | grep -iE 'server:|strict-transport|content-security'
curl -sk -o /dev/null -w '%{http_code}\n' -H 'Host: evil.example' https://solarops.nsr.com.ph/   # expect 000 (dropped)
```

Expected: `Server: nginx` with no version, HSTS present, CSP present.

## 3. Network exposure on both VMs (RB-25)

- With this release, compose publishes port 3000 on `127.0.0.1` only. **MonitoringWM:** if the screens there open
  `http://<ip>:3000`, add `BIND_ADDR=0.0.0.0` to its `.env` before deploying, and allow port 3000 only from the
  screens' network: `ufw allow from <screens-subnet> to any port 3000 proto tcp`.
- List what listens and what the firewall allows; keep 22, 80 and 443 only (plus 3000 from the screens if needed):
  `ss -tlnp` and `ufw status verbose` (or `iptables -S`). Send me both outputs (no secrets in them).
- SSH: key-only login, `PermitRootLogin prohibit-password` or `no`, `PasswordAuthentication no` in `/etc/ssh/sshd_config`.

## 4. Deploy this release (both VMs)

```sh
cd /var/www/html/waltermart_dashboard_v2 && git pull && docker compose up -d --build && docker ps --filter name=waltermart-kiosk
```

`docker ps` should show `(healthy)` within a minute. Rollback: `git checkout <previous commit> && docker compose up -d --build`.
If a screen looks broken, set `CSP_MODE=report-only` in `.env`, run `docker compose up -d --force-recreate`, and
send me the `[csp]` lines from `docker logs waltermart-kiosk`.

## 5. GitHub settings (RB-12)

1. Settings > Rules > Rulesets > New branch ruleset "Protect main": Active, target the default branch; tick
   Restrict deletions, Block force pushes, Require a pull request (1 approval, dismiss stale approvals),
   Require status checks: `tests`, `dependency-audit`, `secret-scan`, `sast`, `container` (after the workflow has run once).
2. Settings > Advanced Security: Dependency graph, Dependabot alerts and security updates, Secret scanning, Push protection.
3. Tell me the reviewer's GitHub username so I can add `.github/CODEOWNERS`.

## 6. Monitoring (RB-15)

| Alert | Threshold | Severity | Owner |
|---|---|---|---|
| Site down: `https://solarops.nsr.com.ph/waltermart-kiosk/healthz` not 200 | 2 checks in a row (5 min) | High | (you) |
| Container unhealthy or restarting | any | High | (you) |
| `[fatal]` or a burst of `502` lines in `docker logs waltermart-kiosk` | 10 in 10 min | Medium | (you) |
| `[admin] cache clear refused` | any | Medium (token guessing) | (you) |
| `[csp]` lines | any after a release | Low | developer |
| solarops `HTTP 401` | any | High (secret mismatch or rotation) | (you) |

Uptime check: UptimeRobot (free) or Better Stack, HTTP(s) monitor on the `/healthz` URL above every 5 minutes, alerts
to a monitored mailbox or Teams channel. Logs are capped by compose (5 x 10 MB) and stay on the VM.

After every deploy: `/summary`, `/kiosk`, `/tour` load and show data, `/healthz` is 200, and `docker ps` shows healthy.

## 7. Recurring (RB-28)

- Weekly: merge Dependabot PRs once the `security` checks are green.
- Monthly: `npm audit --omit=dev`, `npm outdated`; review the alert table above.
- Express 4 and EJS 3 are on their last major line: plan the Express 5 upgrade (breaking changes in routing).
  Node 24 LTS is supported until April 2028.
- Every 6 months: review the hadolint exception in the Dockerfile (DL3018, due 2027-05-06) and this page.
