fix(k3s-cluster): bootstrap user SSH key on first connection (closes #30)#39
Merged
Conversation
) Right after a flash-nodes run the Armbian image only has the default root/1234 credentials and the user's SSH key isn't in authorized_keys yet, so the k3s install steps fail immediately with "ssh: unable to authenticate ... no supported methods remain". Add a one-shot password-auth bootstrap that runs before the k3s install when both ssh_key and ssh_password are set for a node: data.tls_public_key derives the public key from var.X.ssh_key null_resource.bootstrap_ * connects via password, appends the public key to ~/.ssh/authorized_keys (grep -qxF guard makes it idempotent) k3s_control_plane / k3s_workers depend on the bootstrap If only ssh_key is set (key was pre-authorized out of band — today's contract), nothing changes. If only ssh_password is set, nothing changes either. The new behavior only kicks in when the user opts in by supplying both. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When both
ssh_keyandssh_passwordare supplied for a node, add a one-shot password-auth bootstrap that pushes the public key (derived fromssh_keyviatls_public_key) into~/.ssh/authorized_keysbefore any other step runs. The k3s install resources depend on the bootstrap, so by the time they connect the key is already authorized.Idempotent —
grep -qxFchecks before appending.Why
Right after
flash-nodesfinishes, Armbian only has the defaultroot/1234creds. The user's private key isn't authorized yet, so the k3s install steps fail immediately withssh: unable to authenticate ... no supported methods remain. Workaround was a manualsshpass ssh-copy-idloop. This makes the module self-bootstrapping when the user opts in by supplying both auth methods.Compatibility
No new variables — the existing optional
ssh_passwordfield doubles as the bootstrap signal. Bootstrap resource triggers onhost+ the derivedpubkey, so it only re-runs when those change.Test plan
terraform fmt -checkcleanterraform init+terraform validatecleanssh-copy-id— pass bothssh_key = file("~/.secrets/turingpi-cluster")andssh_password = "1234"; module should bootstrap then install k3s end-to-end.🤖 Generated with Claude Code