feat: add protected SMB disk-root sharing

This commit is contained in:
Meghdad committed 2026-10-16 15:37:29 +03:30
1 parent b9cb187f0d
commit 1ca321e312
18 files changed
+480 -21

No files matched your search

+4
View File
@@ -84,3 +84,7 @@ The binary was deployed with the previous version kept for rollback. Tests cover
A separate experimental SMB executable, private JSON configuration, source-confined protocol implementation, independent supervisor, templates and guides were added to the repository. Existing web implementation/configuration and installed paths remain unchanged. Local protocol/race/fuzz checks, native macOS SMB operations and actual Finder browsing/copy/rename/metadata sample checks passed; both static MIPS builds compile. See the detailed [SMB validation record](smb-validation.md).
Router access for this change was read-only inspection of kernel, RAM, BusyBox, SMB command/listener availability and exFAT mount behavior. No SMB binary was deployed or executed there. Target kernel/resource/exFAT/Finder/coexistence/boot/rollback validation requires a separately approved session.
## 11. Authorized SMB installation and protected disk-root view (2026-10-16)
At the user’s request, SMB was installed independently with authenticated read/write access to a protected disk-root view. Service/certificate directories and firmware account metadata remain inaccessible through SMB. Dedicated LAN-only firewall rules, USB-aware supervision and separate startup/firewall hooks were configured; the web process and HTTPS behavior stayed intact. Native Mac file-operation checks, a bounded checksum transfer, actual Finder copy/Quick Look and independent SMB restart passed. Timestamp restoration is limited by exFAT ownership. See the [detailed validation record](smb-validation.md) for observations and outstanding reboot, USB failure and load checks.
+1 -1
View File
@@ -24,6 +24,6 @@ exFAT metadata is represented by ordinary disk sidecars where supported by the c
## Maintenance and distribution
Keep upstream source provenance, retained tests and Apache license together; review both upstream fixes and local policy changes when upgrading. Protocol source is embedded under `internal/smbwire`, not fetched at deployment. `go.mod`/`go.sum` remain compatible with the existing web dependencies. Distributors must include the project MIT license, NAIS license where distributing web assets, SMB Apache-2.0 license and Go-module license notices. No binaries have been published by this change.
Keep upstream source provenance, retained tests and Apache license together; review both upstream fixes and local policy changes when upgrading. Protocol source is embedded under `internal/smbwire`, not fetched at deployment. `go.mod`/`go.sum` pin the existing web dependencies plus Go’s BSD-licensed `golang.org/x/sys` for protected-view descriptor operations; the web implementation does not import the new SMB backend. Distributors must include the project MIT license, NAIS license where distributing web assets, SMB Apache-2.0 license and Go-module license notices. No binaries have been published by this change.
Never ship real JSON config or NT hashes. Include only `.smb.example.json`, `.env.example`, source, licenses and documentation in public source archives. Generated `dist/` executables are local validation artifacts and must be packaged separately with their notices if a binary release is later authorized. Inspect archive contents; Git ignore rules alone are insufficient.
+47 -4
View File
@@ -1,6 +1,6 @@
# SMB validation record
Recorded 2026-10-16. SMB remains experimental. No SMB executable, configuration or test data was copied to the router, and no router process, firewall, mount, startup hook or routing configuration was changed.
Recorded 2026-10-16. SMB remains experimental. Initial implementation validation was local only; a subsequent user-authorized target deployment is recorded below.
## Actual local checks
@@ -40,9 +40,9 @@ SSH inspection confirmed Linux 3.4.113, MIPS, BusyBox 1.24.2 and 126,280 KiB tot
These read-only observations confirm constraints, not SMB execution compatibility. Private addresses, mount identifiers, credentials and raw router dumps are deliberately absent from this record.
## Outstanding checks requiring an approved device session
## Initial target checklist (see subsequent deployment results)
Do not infer these results from compilation or desktop checks:
This checklist was written before deployment. Completed smoke checks are recorded below; the remaining failure, load and reboot checks are listed at the end. Do not infer target results from compilation or desktop checks:
- Execute the new MIPS binary on Linux 3.4.113 and verify kernel/syscall compatibility, dropped UID/GID and supplementary groups, random source and startup behavior.
- Verify exact USB mount identity, configured selected-root and protected-path checks, exFAT naming/case behavior, disk-full and remount-read-only error reporting, non-root write permissions and metadata sidecar persistence.
@@ -53,4 +53,47 @@ Do not infer these results from compilation or desktop checks:
- Exercise approved USB unavailable/reinsert, supervisor crash/restart, configuration error, binary rollback, independent web/SMB stop/update, host-firewall reload and controlled reboot cases. Do not unplug valuable storage during writes; use backed-up scratch media/data and a deliberate plan.
- Check that allowed private clients connect while guest/WAN/untrusted sources are denied, with no gateway SMB forwarding and no change to web exposure or unrelated rules.
Use [deployment and rollback](smb.md#install-status-update-and-remove). Upload to new names, retain known-good private backups, validate, stop only the verified SMB supervisor, rename into place, restart and verify. Revert the binary/config/script independently if a check fails. No target load, reboot, kernel compatibility, USB loss recovery or production-readiness claim is made by this change.
Use [deployment and rollback](smb.md#install-status-update-and-remove). Upload to new names, retain known-good private backups, validate, stop only the verified SMB supervisor, rename into place, restart and verify. Revert the binary/config/script independently if a check fails. Target observations are recorded separately below; smoke checks do not establish unobserved load, reboot, USB-loss or production-readiness guarantees.
## Authorized target deployment and protected root view (2026-10-16)
The user requested read/write access to the USB disk root. Explicit protected
root sharing was added, with separate opt-ins for disk root and public overlap.
Mandatory service directories plus configured firmware metadata are hidden and
inaccessible. Descriptor-pinned parent traversal, no-follow file opens, link
refusal and protected-ancestor rename/delete checks prevent path-only exclusions
from being bypassed. Protocol/race tests cover access, Unicode case variants,
symlink/hardlink aliases, ancestor renames and ordinary cross-directory moves.
Native macOS localhost testing also passed for the protected root profile.
After authorization, the static MIPS binary was staged to a new USB filename;
local/remote SHA-256 matched and target configuration validation passed. It now
runs independently with a separate supervisor/account, UID/GID 65533, no
supplementary groups and a dedicated IPv4 LAN-only firewall chain. Web PID and
configuration were preserved; an HTTPS HEAD check succeeded. Startup/firewall
hooks were extended without executing unrelated startup commands, and the
private configuration/hooks were saved using firmware persistence. The
SMB-only stop/restart command verified process identity and cleanup; native
client access worked after an independent restart.
Observed on the actual device: wrong password refused; native Mac mount;
protected paths absent/unreadable; scratch mkdir, upload, move/rename,
checksum-verified download and deletion. The bounded transfer was 256 KiB,
not a sustained load test. Actual Finder copied a text file to a unique
scratch folder, Quick Look displayed expected content, and the file checksum
matched. Scratch files, sidecars and Mac mounts were cleaned up.
**Observed limitation:** the exFAT mount is owned by another UID and refuses
arbitrary timestamp restoration by the non-root service. Finder copy/open
completed, but the original modification time was not preserved. No silent
metadata-success workaround or privilege increase was introduced. After the
small checks the process used about 6 MiB RSS with a measured high-water mark
near 7 MiB; after restart and a repeat transfer it used about 4.4 MiB. These
snapshots are not a memory ceiling or a routing/load benchmark.
Reboot, USB removal/reinsertion, disk-full/remount-read-only failure, large-file
transfer, native interruption/recovery, complete Mac metadata/application
compatibility and sustained combined resource/load checks remain unperformed.
Private device addresses, disk identifiers, account hashes, passwords, hook
backups and detailed operational instructions remain only in ignored local
outputs and protected router configuration, not in public source examples.
+13 -4
View File
@@ -15,12 +15,20 @@ Use separate sibling directories on USB, for example:
/etc/storage/routershelf-smb.json administrator-owned credentials/config
```
Replace `DISK_ID` with your actual mount. Create the selected private directory deliberately while the disk is mounted. The service never creates a missing root or serves the whole mount. Never share `/`, the USB mount itself, a service directory, certificate cache, backup directory, or administrator home. Select one root containing the folders you want available; every descendant, including hidden files, is available to the authenticated account. Symlinks cannot escape that root. On filesystems supporting hard links, an administrator must also exclude hard links to sensitive files.
Replace `DISK_ID` with your actual mount. Create the selected private directory deliberately while the disk is mounted. The service never creates a missing root. It refuses the whole mount by default; an explicitly protected disk-root view is described below. Never share `/`, a service directory, certificate cache, backup directory, or administrator home. Keep the default private sibling unless disk-root access is deliberately required. Select one root containing the folders you want available; every descendant, including hidden files, is available to the authenticated account. Symlinks cannot escape that root. On filesystems supporting hard links, an administrator must also exclude hard links to sensitive files.
`public_roots` must list every web root on this storage, especially a customized `RS_ROOT`. The standard `public-storage` sibling is checked automatically. Default private service directories, this executable and the config are excluded; add customized certificate/cache/binary/backup paths to `protected_paths`. These exclusions cannot be overridden by allowing public overlap. Overlap is refused unless `allow_public_overlap` is explicitly true. Separate processes cannot discover arbitrary web installations: listing the actual public roots is the administrator's responsibility. If you deliberately share a web root, **every SMB upload/rename into it may immediately publish the file without web authentication**. Use a private staging directory and move reviewed files into publication deliberately. The web service retains its own existing path filtering and GET/HEAD policy; SMB credentials do not protect web copies.
exFAT has mount-wide ownership/mode behavior, limited Unix metadata and no POSIX ACL isolation. A separate non-root service UID reduces process privilege but does not isolate secrets on a broadly writable exFAT mount. Put credentials on a permission-enforcing administrator-owned filesystem such as `/etc/storage`; do not rely on `chmod` on exFAT. Restrict other disk accounts and local writers separately. Use only one RouterShelf SMB instance per writable root; independent instances and FTP/SFTP/local programs do not share its locks.
## Optional protected disk-root view
To manage ordinary folders across an entire disk, explicitly set `root` equal to `storage_mount`, `allow_storage_root: true`, and `allow_public_overlap: true`. This also includes public web folders, so writes there may immediately publish content. The default template keeps this mode disabled.
In this mode, private service directories and every configured `protected_paths` subtree are hidden and inaccessible over SMB. The running executable is excluded automatically. Add firmware metadata, customized service/cache paths and backups to that list. Excluded ancestors cannot be moved or deleted to bypass the policy. The protected view refuses symlinks and hard-linked regular files, including aliases to private data; ordinary private-subdirectory shares retain their previous confinement behavior. Parent directories are pinned using `os.Root` and file operations use descriptors rather than a path-only filter.
This is an SMB access boundary, not isolation from other router accounts that can write the exFAT disk. Keep credentials on protected storage outside the disk and restrict other broad disk access separately.
## Build and configure
On the development computer, with Go 1.26+:
@@ -64,13 +72,14 @@ The only environment setting is `RS_SMB_CONFIG`, the absolute JSON config path.
| --- | --- |
| `listen` | `127.0.0.1:1445`; a specific private/loopback IPv4 and numeric port; no wildcard, DNS, public IPv4 or IPv6 |
| `storage_mount` | Required existing absolute USB mount; exact Linux mount presence checked before listening and every two seconds |
| `root` | Required existing directory strictly under that mount; selected explicitly; never created automatically |
| `root` | Required existing selected directory under the mount; the mount itself requires explicit protected disk-root mode; never created automatically |
| `allow_storage_root` | `false`; explicit opt-in to a protected disk-root view; public overlap must also be acknowledged |
| `share` | `Storage`; direct Finder share name; no separators/spaces or reserved `IPC$` |
| `user` | Required single account name; no OS account/password database needed |
| `nt_hash` | Required 32 hex digits; placeholders and empty-password hash refused |
| `read_only` | `true`; refuses data, directory, metadata, rename and delete mutations |
| `allow` | Required explicit private/loopback IPv4 CIDRs; applied before authentication; no unrestricted prefixes |
| `protected_paths` | Additional sensitive paths that must not overlap the share; default service directories and running executable are also excluded |
| `protected_paths` | Additional sensitive paths; overlap refused normally, or hidden/blocked in explicit disk-root mode; default service directories and running executable always excluded |
| `public_roots` | Additional actual public roots; standard `storage_mount/public-storage` always checked |
| `allow_public_overlap` | `false`; deliberate opt-in to overlapping publication |
| `uid`, `gid` | 65533; positive non-root IDs, applied before file service starts |
@@ -97,7 +106,7 @@ SMB2.0.2/2.1 (SMB3.0 fallback) uses NTLMv2 and mandatory packet signing. **Signi
The service changes no firewall rules. If existing firewall policy blocks LAN SMB, an administrator must allow only the chosen IPv4/interface/client subnet and service port, with an explicit drop for other sources to that port. Use a separately owned SMB chain/hook, preserve SSH and unrelated rules, and test denied guest/WAN sources. Do not flush tables or permit SMB through the existing public web chain. If firmware already listens on 445, leave it alone and select a high port for this initial service. Firewall/persistence changes need separate deployment approval and firmware-specific review.
The exFAT profile advertises case-insensitive, case-preserving names. There are no persistent named streams or ACLs. Per-file read-only/locked mode changes are refused rather than acknowledged on a mount that may ignore them; use the share’s `read_only` policy. Finder can create `._filename` AppleDouble sidecars and `.DS_Store` files on disk; retain these with their files if metadata matters. Some applications may require streams, ACLs, resource forks or Apple extensions that this profile cannot provide. Unsupported requests return errors; no metadata is acknowledged into volatile streams. Finder tags, resource-fork round trips, packages and application-specific saves still require native testing. Do not clean sidecars automatically. Files visible through SMB include dotfiles; the web service still filters them.
The exFAT profile advertises case-insensitive, case-preserving names. There are no persistent named streams or ACLs. Per-file read-only/locked mode changes are refused rather than acknowledged on a mount that may ignore them; use the share’s `read_only` policy. Finder can create `._filename` AppleDouble sidecars and `.DS_Store` files on disk; retain these with their files if metadata matters. On exFAT mounts owned by another UID, the non-root service may be unable to restore arbitrary original timestamps even when data writes succeed. Permission failures are returned; copied files can retain their new write time. Finder copy and Quick Look passed on the initial target despite this limitation. Some applications may require streams, ACLs, resource forks or Apple extensions that this profile cannot provide. Unsupported requests return errors; no metadata is acknowledged into volatile streams. Finder tags, resource-fork round trips, packages and application-specific saves still require native testing. Do not clean sidecars automatically. Files visible through SMB include dotfiles; the web service still filters them.
Writes use bounded 64 KiB chunks, not whole-file memory. Four connections, 64 total handles, eight compound commands and 1,024 entries per scanned directory bound work. Larger directories return a resource error, rather than an incomplete successful listing; divide large collections into folders. Authentication has a 30-second per-frame deadline and authenticated reads a five-minute idle deadline; reconnect idle clients as needed. The Go memory target is 20 MiB, **not a hard quota**. Protocol state, filesystem caches, firmware and the web process need additional RAM; target resource measurements remain required before enabling both under load.