Skip to content

feat(api): operator commands for the single-machine installer (part of #377) - #380

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/377-operator
Nov 20, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/377-operator

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Part 3 of #377 (ADR 0021): the operator commands the single-machine installer runs.

What changed

Three commands on the control plane's command line (operator.ts), next to account create and account reset-password (ADR 0020):

  • node main.js organization create --name <name> --slug <slug> --owner <address>: creates an organization owned by an active account, and says Organization created: <id>. Audited as organization.created with the system as actor and the owner in the payload.
  • node main.js server join-token --organization <id>: issues a join token for that organization, audited as fleet.join_token.issued by the system, and writes the token alone on standard output. It refuses a terminal before any token exists, and never falls back to standard error, so the installer pipes it straight into the agent's 0600 token file without it ever being printed.
  • node main.js server ca-fingerprint: says the installation CA's fingerprint, which the agent pins. Not in the ADR's list; it reads public information, and keeps the token command's output to the token alone.

These read no password; the account commands still need one. The list stays closed and the arguments stay strict (fixed flag order, bounded values, no control characters, a lowercase UUID).

Why

ADR 0021: one installer run gives a server ready to deploy. The installer creates the first organization for the account it created, then enrolls the local agent with a token, without asking the person to paste anything.

How it was tested

  • Unit tests: parsing of the three commands; malformed or hostile arguments refused with the usage only; which commands read a password; organization created for the account the address names; join token written alone, refused on a terminal before issuing, never sent to standard error when standard output fails; fingerprint written; account commands still refuse without a password.
  • Integration test against PostgreSQL with the restricted runtime role: the organization, its owner membership and the join token rows are written, both audited with the system as actor; the token's hash matches; a missing owner creates nothing.
  • Whole API integration suite locally: 389 of 392; the three failures are the known PostgreSQL 18 ON DELETE RESTRICT code difference of the local database (23001 instead of 23503), unrelated. CI runs PostgreSQL 17.
  • api:lint, api:typecheck, API unit tests (583): green.

Security considerations

Like the account commands, these run only on the server, by someone who holds the database and the key-encryption key; no route reaches them. The join token is a secret: it never reaches a terminal or standard error, and an unused token expires in 15 minutes.

Summary by CodeRabbit

  • New Features
    • Added operator commands to create an organization for an active account, issue a server join token, and display the installation’s CA fingerprint.
    • Join tokens are written only to non-terminal output, and these operations are recorded as system-audited events.
  • Documentation
    • Updated command usage and security documentation to describe the new commands and join-token output restriction.

OperatorOrganizationCommands creates an organization owned by an active account, audited with the system as actor (ADR 0021).

Signed-off-by: samuel mbabhazi <[email protected]>
organization create, server join-token and server ca-fingerprint. The join token goes only to a standard output that is not a terminal, never to standard error, and no password is read for these commands.

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7cc7a32 and cee27ab.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The operator CLI adds organization creation, server join-token issuance, and CA-fingerprint commands. It validates command arguments, requires passwords only for account commands, audits organization and token operations as the system actor, and limits join-token output to non-terminal standard output.

Changes: Installer operator commands

Layer / File(s) Summary
Command parsing and password handling
apps/api/src/operator.ts, apps/api/src/main.ts, apps/api/src/operator-installer.spec.ts
The parser accepts the new command forms and validates their arguments. The CLI reads a password only for account commands. Parser tests cover valid forms, invalid input, and password requirements.
Active owner lookup and organization creation
apps/api/src/modules/identity/application/operator-account-commands.ts, apps/api/src/modules/organizations/application/operator-organization-commands.ts, apps/api/src/modules/organizations/organizations.module.ts
The account command resolves an active owner by normalized email. The organization command creates an organization in a store transaction and publishes an organization.created event with SYSTEM_ACTOR. The organizations module registers the command provider.
Command execution, output, and validation
apps/api/src/operator.ts, apps/api/src/operator-installer.spec.ts, apps/api/src/modules/organizations/operator-organization.integration.spec.ts, docs/SPEC.md
The command runner creates organizations, issues join tokens, and reports the CA fingerprint. Tests cover execution, audit data, and output constraints. The specification documents the added commands.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant OperatorCLI
  participant parseOperatorCommand
  participant runOperatorCommand
  participant OperatorAccountCommands
  participant OperatorOrganizationCommands
  participant OrganizationStore
  participant DomainEventBus
  OperatorCLI->>parseOperatorCommand: Parse organization create arguments
  parseOperatorCommand-->>OperatorCLI: Return organization command
  OperatorCLI->>runOperatorCommand: Execute organization command
  runOperatorCommand->>OperatorAccountCommands: Resolve active owner account
  OperatorAccountCommands-->>runOperatorCommand: Return account ID
  runOperatorCommand->>OperatorOrganizationCommands: Create organization for owner
  OperatorOrganizationCommands->>OrganizationStore: Create organization in transaction
  OperatorOrganizationCommands->>DomainEventBus: Publish organization.created with SYSTEM_ACTOR
  runOperatorCommand-->>OperatorCLI: Write organization ID
Loading

Possibly related issues

  • shipkeepdev/shipkeep#377 — This PR implements the issue’s organization create and server join-token commands with system-actor auditing; the other listed work remains outside this PR.

Possibly related PRs

Merge Risk: Minimal · previous review 7cc7a

This adds operator commands for creating an organization, issuing a join token and reporting the CA fingerprint, with strict argument checks and guarded token output. No actionable merge-blocking issue was found.

Security architecture risk: Minimal · up to 7cc7a

The new commands rely on the existing trusted-server-operator model. Organization ownership and audit writes are transactional, and join tokens retain their existing expiry and single-use controls. The inspected change does not establish a material security regression; installer file permissions remain outside the verified scope.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A trusted host operator can select organizations across the installation when issuing tokens. Each individual token enrolls a node into the organization stored with that token; enrollment does not take its organization identity from the presented CSR or a separate caller-selected tenant argument.

Trust Boundaries and Controls

  • observed — The new CLI calls token issuance directly with system authority, unlike the HTTP application path that requires reauthentication and node.manage permission. This is an intentional host-trust boundary: both existing account commands and the new organization command document callers as already holding database and key-encryption-key access.
  • observed — The token branch refuses terminal output before issuance and never uses the confirmation helper's fallback stream. Unexpected command failures produce a generic diagnostic rather than printing the underlying error or token value.

Resilience and Maintainability Implications

  • observed — The newly accessible issuance path reuses existing enrollment controls: malformed, expired and used tokens are rejected; token consumption conditionally updates only an unused row. Node, certificate, consumption and audit writes share the enrollment transaction, so a losing concurrent enrollment or audit failure rolls back its writes.
  • observed — Owner eligibility is a pretransaction lookup rather than a locked, commit-time status check. The membership foreign key enforces account existence, not active status. Existing login and session authentication independently reject inactive accounts, so membership creation does not itself override account disablement.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(api): operator commands for the single-machine installer (part of #377)" matches the main change. The PR adds the operator CLI commands for organization creation, join-token issuance, …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(api): operator commands for the single-machine installer (part of #377)" matches the main change. The PR adds the operator CLI commands for organization creation, join-token issuance, and CA fingerprint reporting. The title names the API scope and the installer context. It does not list every command, which is acceptable. The reference to #377 is a minor noise item, but the title stays specific and accurate.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ce5613b and 7cc7a32.

Files selected for processing: 8

  • apps/api/src/main.ts
  • apps/api/src/modules/identity/application/operator-account-commands.ts
  • apps/api/src/modules/organizations/application/operator-organization-commands.ts
  • apps/api/src/modules/organizations/operator-organization.integration.spec.ts
  • apps/api/src/modules/organizations/organizations.module.ts
  • apps/api/src/operator-installer.spec.ts
  • apps/api/src/operator.ts
  • docs/SPEC.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@samuelmbabhazi
samuelmbabhazi merged commit 6a1e7e0 into main Nov 20, 2026
22 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/377-operator branch November 20, 2026 10:55
samuelmbabhazi added a commit that referenced this pull request Nov 22, 2026
…machine check remains (#415)

Part of #413.

## What changed

Step 1 of the first stable version (#377, the single-machine
installation of ADR 0021) said it waited for nothing. In fact its code
and docs were merged on 2026-11-20 in #378, #379, #380, #381 and #382,
as the last comment on #377 says. Only the ADR's last acceptance
criterion remains: a real machine with a public name and certificate.

- Step 1 now says that, and points to step 5.
- Step 5 lists #377 with the other real-machine checks.

## How it was tested

Prettier check. Documentation only.

## Security considerations

None: documentation only.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Clarified that step 1 covers single-machine installation and requires
step 5 to complete real-machine acceptance.
* Added issue `#377` to step 5 and identified it as a prerequisite for
step 1 acceptance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: samuel mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant