Skip to content

fix(node): validate the profile on a bootstrap dry run - #188

Merged
tas50 merged 1 commit into
mainfrom
fix/bootstrap-dry-run-validates-profile
Sep 8, 2026
Merged

tas50 merged 1 commit into
mainfrom
fix/bootstrap-dry-run-validates-profile

Conversation

@tas50

@tas50 tas50 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

The defect

resolveClient is the only thing that calls Profile.Validate(), and --dry-run skips it. The server URL is then concatenated unconditionally into the client.rb the script writes:

ServerURL: strings.TrimRight(profile.ServerURL, "/") + "/organizations/" + profile.Org,

With a profile that names no Cinc Server — a Supermarket-only one, say, which is perfectly valid on disk and which cinc config create will happily write — the dry run prints a script pointing nowhere and exits 0:

cat <<'CINC_EOF' | sudo tee '/etc/cinc/client.rb' >/dev/null
chef_server_url '/organizations/'
node_name 'web01.example.test'
client_key '/etc/cinc/client.pem'
CINC_EOF

A dry run exists to show what a real run would do. Printing a script that could never work, and reporting success, is the one thing it must not do — especially since the natural next step is to copy that script and run it by hand.

The fix

Validate the resolved profile before building the command, on both paths. A real run reaches the same check a moment later in resolveClient, so this only changes the dry-run path.

Tests

TestNodeBootstrapDryRunRejectsProfileWithoutServer uses a Supermarket-only profile and asserts the command errors and prints no script. Verified red before the fix by stashing it — on main it emits the /organizations/ script above and returns nil.

go test ./..., go vet ./..., and gofmt -l . are clean.

Note

Same function as the --format ordering fix in the sibling PR. Independent changes, so separate PRs as requested, but whichever lands second will want a trivial rebase.

resolveClient is the only thing that calls Profile.Validate, and a dry
run skips it. The server URL is then concatenated unconditionally into
the client.rb the script writes, so a profile naming no Cinc Server, such
as a Supermarket-only one, produced a script pointing nowhere and exited
zero:

  chef_server_url '/organizations/'

Dry run exists to show what a real run would do, so it has to apply the
same requirement rather than print something that could never work.
Validate the resolved profile before building the command, on both paths.

Signed-off-by: Tim Smith <tim@mondoo.com>
@tas50
tas50 force-pushed the fix/bootstrap-dry-run-validates-profile branch from 62eadd1 to 76c60c4 Compare September 8, 2026 15:16
@tas50
tas50 merged commit bc23485 into main Sep 8, 2026
5 checks passed
@tas50
tas50 deleted the fix/bootstrap-dry-run-validates-profile branch September 8, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant