Create the server token at install and document the security boundary
This commit is contained in:
@@ -359,6 +359,7 @@ class Setup:
|
||||
auth.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
self._write_atomic(auth, (json.dumps({"password": password,
|
||||
"secret": secrets.token_urlsafe(48)}) + "\n").encode(), 0o600)
|
||||
server_token = self.ensure_server_token(auth.parent / "server-token")
|
||||
target = prefix / "lib/web"
|
||||
shutil.copytree(Path(__file__).resolve().parents[1] / "web", target, dirs_exist_ok=True,
|
||||
ignore=shutil.ignore_patterns("test", "node_modules", ".DS_Store"))
|
||||
@@ -366,8 +367,24 @@ class Setup:
|
||||
updates.mkdir(parents=True, exist_ok=True)
|
||||
return {"node": node, "script": str(target / "serve.mjs"),
|
||||
"auth_file": str(auth), "host": args.web_host, "port": args.web_port,
|
||||
"server_token_file": str(server_token),
|
||||
"root": self.install_app_web(prefix, args, web_build), "updates": str(updates)}
|
||||
|
||||
def ensure_server_token(self, path):
|
||||
"""The proxy/CLI ↔ server shared secret (docs/notes/security-boundary.md).
|
||||
|
||||
Created once (0600, beside the web auth file) and kept across reinstalls."""
|
||||
if path.is_symlink() or (path.exists() and not path.is_file()):
|
||||
raise ValueError(f"Refusing a server token that is not a regular file: {path}")
|
||||
if path.exists():
|
||||
if path.stat().st_mode & 0o077 or path.stat().st_uid != os.getuid():
|
||||
raise ValueError(f"Server token must be owned by you and private (chmod 600): {path}")
|
||||
if len(path.read_text().strip()) >= 32:
|
||||
return path
|
||||
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
self._write_atomic(path, (secrets.token_urlsafe(48) + "\n").encode(), 0o600)
|
||||
return path
|
||||
|
||||
def choose_password(self):
|
||||
"""The web sign-in password for a new computer, chosen by the operator.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user