Skip to content

fix(dashmate): restrict a gateway TLS private key an older version left readable - #5654

Merged
shumkov merged 2 commits into
v5.1-devfrom
fix/dashmate/gateway-tls-key-mode
Nov 18, 2026
Merged

shumkov merged 2 commits into
v5.1-devfrom
fix/dashmate/gateway-tls-key-mode

Conversation

@shumkov

@shumkov shumkov commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Older dashmate versions created the gateway's TLS private key (<home>/<config>/platform/gateway/ssl/private.key) at the process umask, so upgraded nodes can carry a group- and world-readable key. Two historical config migrations copy the key to a new directory and kept that mode.

Split out of #4283, where it was reviewed.

What was done?

  • The two migrations that copy the key restrict the copy to 0600.
  • Starting a node drops the group and other bits of an existing key, keeping an owner's stricter mode such as 0400. If the key cannot be restricted, for example because root owns it after a sudo run, starting only warns: an upgrade must not keep a masternode from starting.
  • dashmate doctor reports a key that other users can read. Windows reports a writable file as 0666 whatever its ACL allows, so the mode is collected only on POSIX hosts.

This covers POSIX hosts, where the umask problem exists. On Windows, file access lives in NTFS ACLs, which chmod does not change; restricting those is separate work.

Follow-up

#5506: a descriptor opened while the key was readable can still read a renewed key, because a renewal rewrites the same inode. Fixing that needs the gateway to mount the ssl directory instead of the key file.

How Has This Been Tested?

  • Tests:

    • new startNodeTaskFactory.spec.js: restricts a world-readable key, keeps a restricted or stricter key, creates no key, warns and starts when chmod fails;
    • migrateConfigFileFactory.spec.js: both copying migrations restrict the key;
    • collectSamplesTaskFactory.spec.js and analyseConfigFactory.spec.js: the doctor sample and its verdict, including Windows;
    • saveCertificateTask.spec.js: an exposed key is restricted before it is rewritten.

    The tests were written failing first in fix(dashmate): keep the node up when an image pull fails, and stop reporting success when it did not #4283.

  • The whole dashmate unit suite on this branch: 965 passing.

  • Not run: a live gateway. That the container can still read the tightened key rests on the compose wiring, where ENVOY_UID is the operator's own uid.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 156409e

  • Bots — thepastaclaw requested changes — dismiss the review or push a fix
  • Self-review — post /self-reviewed
  • Build failed
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…ft readable

Older dashmate versions created the gateway's private.key at the
process umask, so upgraded nodes can carry a group- and world-readable
key. Two historical config migrations copy the key to a new directory
and kept that mode.

The migrations now restrict the copied key to 0600, starting a node
drops the group and other bits of an existing key, keeping an owner's
stricter mode, and `dashmate doctor` reports a key other users can
read. Starting only warns when the key cannot be restricted, for
example when root owns it, so an upgrade cannot keep a masternode from
starting. Windows reports a writable file as 0666 whatever its ACL
allows, so doctor collects the mode only on POSIX hosts.

A descriptor opened while the key was readable can still read a
renewed key, because a renewal rewrites the same inode; that needs a
change to how the gateway mounts the key, tracked in #5506.

Moved out of #4283, where it was written test-first and reviewed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shumkov shumkov added this to the v5.1.0 milestone Oct 29, 2026
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 03945d3 and 156409e.

Files selected for processing: 9
  • packages/dashmate/configs/getConfigFileMigrationsFactory.js
  • packages/dashmate/src/doctor/analyse/analyseConfigFactory.js
  • packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js
  • packages/dashmate/src/listr/tasks/startNodeTaskFactory.js
  • packages/dashmate/test/unit/config/configFile/migrateConfigFileFactory.spec.js
  • packages/dashmate/test/unit/doctor/analyse/analyseConfigFactory.spec.js
  • packages/dashmate/test/unit/listr/tasks/doctor/collectSamplesTaskFactory.spec.js
  • packages/dashmate/test/unit/listr/tasks/startNodeTaskFactory.spec.js
  • packages/dashmate/test/unit/ssl/saveCertificateTask.spec.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 29, 2026
@shumkov

shumkov commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw

thepastaclaw commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 1 blocking finding(s) (commit 156409e) · triage: critical

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

The POSIX permission hardening is effective, and the dashmate tests pass. However, the same change does not secure legacy keys on supported Windows hosts: Node's chmod implementation does not replace NTFS ACLs, while doctor intentionally skips Windows permission checks, leaving broad ACL access undetected. The dashmate lint check and helper-image build were still pending in the supplied CI snapshot.

🔴 1 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The diff changes gateway TLS private-key handling in start, migration, certificate-renewal, and diagnostic paths, directly affecting protection of cryptographic key material.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/dashmate/src/listr/tasks/startNodeTaskFactory.js`:
- [BLOCKING] packages/dashmate/src/listr/tasks/startNodeTaskFactory.js:100-105: Windows startup hardening does not restrict ACL-readable private keys
  On Windows, `fs.chmodSync(privateKeyFilePath, ... )` changes the file's read-only attribute but does not remove inherited or explicit NTFS ACL entries granting other local users read access. Therefore, a legacy `private.key` that is readable through a broad ACL remains exposed after `dashmate start`; the equivalent `chmodSync` calls in both migration paths have the same limitation. The new doctor collection also skips Windows entirely at `collectSamplesTaskFactory.js:156`, so it cannot report this condition. Because Windows is a supported dashmate platform, another local user may still copy the gateway TLS key and impersonate the gateway or perform a TLS MITM without warning. Apply a Windows ACL restriction for the intended account and verify effective access, or explicitly exclude Windows from the security guarantee and provide an appropriate diagnostic.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Open gateway key descriptors can outlive permission tightening — A gateway process that already opened the old readable inode can retain access when renewal rewrites that inode, even after the new mode is applied. This behavior predates the reviewed range and is already tracked by #5506.
    • Follow-up: Continue #5506 by mounting the gateway SSL directory instead of the individual key file, then test renewal with an already-open descriptor.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 29, 2026
chmod does not change the NTFS ACLs that decide who can read a file on
Windows, so restricting the key on start protects POSIX hosts only.
Comment change only; no behaviour change, so no new test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@shumkov
shumkov dismissed thepastaclaw’s stale review October 30, 2026 13:18

The Windows ACL finding is answered in its thread. This pull request fixes the POSIX mode that older dashmate versions left on the key, and is scoped to POSIX hosts, as the startup comment (156409e) and the description now state. On Windows the chmod calls are no-ops; restricting NTFS ACLs is separate work.

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 30, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The reviewed commit only clarifies that the existing chmod hardening applies to POSIX hosts; it does not address Windows ACLs. Because dashmate publishes a Windows target and its installation documentation recommends Windows packages for mainnet masternodes, legacy gateway keys can still be readable by other local users there, leaving the security fix incomplete. Dashmate lint and unit tests for this head were still queued in the supplied CI snapshot.

🔴 1 blocking

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The diff changes gateway TLS private-key permission handling across migrations, node startup, certificate renewal, and diagnostics, directly affecting secret/key protection on a security-critical surface.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/dashmate/src/listr/tasks/startNodeTaskFactory.js`:
- [BLOCKING] packages/dashmate/src/listr/tasks/startNodeTaskFactory.js:92: Windows startup hardening does not restrict ACL-readable private keys
  (existing thread: https://github.com/dashpay/platform/pull/5654#discussion_r4412615182)
  The comment accurately states that `chmod` does not change Windows ACLs, but the startup path still provides no restriction for a legacy key with inherited or explicit NTFS read access granted to other local users. The two migration copies likewise call only `chmod`, and `collectSamplesTaskFactory` skips Windows because its mode is not meaningful there, so `dashmate doctor` cannot detect this exposure. Dashmate publishes `win32-x64`, and the installation guide recommends Windows packages for mainnet masternodes; therefore this remains a security gap on a supported target. Implement Windows ACL restriction and effective-access diagnostics, or add a tracked Windows-specific follow-up and explicitly narrow the supported security guarantee. The referenced #5506 follow-up covers renewed-key inode mounts, not Windows ACLs.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 30, 2026
@shumkov
shumkov merged commit 3ed3c9b into v5.1-dev Nov 18, 2026
32 of 34 checks passed
@shumkov
shumkov deleted the fix/dashmate/gateway-tls-key-mode branch November 18, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants