node security: let a node owner self-delete their cert/login
A single Delete removes the certificate (even if expired) and the password login for a node you own, not just revoke. The removal is synchronous via the reflector control-PTY (-w): the call waits for the reflector's OK/ERR reply so the cert is really gone when it returns — no more two-click race. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b209d07189
commit
e1b21277d8
3 files changed
+36
-7
No files matched your search
+3
-1
@@ -303,7 +303,9 @@ function reflector_ca(string $sub, string $cs): true|string {
|
||||
$sub = strtoupper($sub);
|
||||
if (!in_array($sub, ['SIGN', 'RM'], true)) return 'bad CA subcommand';
|
||||
if (!node_callsign_path_safe($cs) || preg_match('/\s/', $cs)) return 'bad callsign';
|
||||
$cmd = 'sudo -u svxlink /usr/local/sbin/svxreflector-pty CA ' . escapeshellarg($sub) . ' ' . escapeshellarg($cs);
|
||||
// -w: wait for the reflector's reply so we return only once the command has
|
||||
// actually been processed (cert files signed/removed), instead of racing it.
|
||||
$cmd = 'sudo -u svxlink /usr/local/sbin/svxreflector-pty -w CA ' . escapeshellarg($sub) . ' ' . escapeshellarg($cs);
|
||||
exec($cmd . ' 2>&1', $out, $rc);
|
||||
return $rc === 0 ? true : (implode("\n", $out) ?: 'PTY write failed');
|
||||
}
|
||||
|
||||
+14
-6
@@ -236,14 +236,20 @@ switch ($action) {
|
||||
if ($r !== true) json_out(['ok' => false, 'error' => 'revoke_failed', 'detail' => $r], 502);
|
||||
json_out(['ok' => true, 'node' => $cs]);
|
||||
|
||||
// ---- Delete certificate — PERMANENT full removal (lvl2-3 site admins only,
|
||||
// NOT callsign-admins). Removes the signed cert + any pending CSR, resets the
|
||||
// renewal counters and clears node-admin membership so nothing can re-issue. ----
|
||||
// ---- Delete certificate — PERMANENT full removal. Allowed for a site admin
|
||||
// (lvl >= 2) OR the node's own owner (callsign match, node-admin membership,
|
||||
// verified cert email) so a user can clean up a cert they no longer use.
|
||||
// Removes the signed cert + any pending CSR, resets the renewal counters and
|
||||
// clears node-admin membership so nothing can re-issue. ----
|
||||
case 'delete_cert':
|
||||
$cs = require_node($in);
|
||||
if (acct_admin_level($uuid) < 2) json_out(['ok' => false, 'error' => 'admin2_required'], 403);
|
||||
if (acct_admin_level($uuid) < 2 && !$view_owns($cs))
|
||||
json_out(['ok' => false, 'error' => 'not_your_cert'], 403);
|
||||
$ce = node_cert_email($cs);
|
||||
if (is_file(pki_certs_dir() . "/{$cs}.crt")) {
|
||||
// reflector_ca() now blocks until the reflector confirms removal on
|
||||
// the PTY ("OK"), so the cert files are already gone when it returns
|
||||
// — no need to poll the filesystem.
|
||||
$r = reflector_ca('RM', $cs);
|
||||
if ($r !== true) json_out(['ok' => false, 'error' => 'delete_failed', 'detail' => $r], 502);
|
||||
}
|
||||
@@ -311,10 +317,12 @@ switch ($action) {
|
||||
}
|
||||
json_out(['ok' => true, 'node' => $cs, 'linked_via' => $linked_via, 'account' => $account]);
|
||||
|
||||
// ---- Remove a password node (site admin only) ----
|
||||
// ---- Remove a password node — site admin OR the node's own owner, so a
|
||||
// user can delete a reflector login they no longer use. ----
|
||||
case 'del':
|
||||
if (!$is_admin) json_out(['ok' => false, 'error' => 'forbidden'], 403);
|
||||
$cs = require_node($in);
|
||||
if (!$is_admin && !$view_owns($cs))
|
||||
json_out(['ok' => false, 'error' => 'not_your_node'], 403);
|
||||
[$rc, $out] = users_ctl('del', $cs);
|
||||
if ($rc !== 0) json_out(['ok' => false, 'error' => 'del_failed', 'detail' => $out], 502);
|
||||
// Keep the admin list if the node still exists via a cert.
|
||||
|
||||
@@ -393,6 +393,25 @@ function loadNodeAuth() {
|
||||
});
|
||||
actCell.appendChild(btn);
|
||||
}
|
||||
|
||||
// Delete — permanently remove EVERYTHING for this node you no longer use:
|
||||
// the certificate (including an expired one), any pending request, the
|
||||
// renewal history, node admins and the password login — in one go.
|
||||
var delBtn = document.createElement('button');
|
||||
delBtn.type = 'button'; delBtn.className = 'btn btn-sm btn-outline-danger py-0 ms-1';
|
||||
delBtn.style.fontSize = '.75rem'; delBtn.textContent = 'Delete';
|
||||
delBtn.addEventListener('click', function () {
|
||||
if (!confirm('Permanently delete ' + n.node + '?\nThis removes its certificate (even if expired), renewal history, node admins and password login. This cannot be undone.')) return;
|
||||
delBtn.disabled = true;
|
||||
var chain = Promise.resolve({ ok: true });
|
||||
if (n.password) chain = chain.then(function (r) { return (r && r.ok) ? nauthApi({ action: 'del', node: n.node }) : r; });
|
||||
if (n.cert) chain = chain.then(function (r) { return (r && r.ok) ? nauthApi({ action: 'delete_cert', node: n.node }) : r; });
|
||||
chain.then(function (r) {
|
||||
if (r && r.ok) { nodeSecLoaded = false; loadNodeAuth(); }
|
||||
else { delBtn.disabled = false; alert((r && (r.detail || r.error)) || 'Failed'); }
|
||||
});
|
||||
});
|
||||
actCell.appendChild(delBtn);
|
||||
});
|
||||
|
||||
// Pending certificate requests — a node reconnecting after its cert was
|
||||
|
||||
Reference in new issue
Block a user