-
Notifications
You must be signed in to change notification settings - Fork 0
fix(k3s): authorize galactica on kyber and surface client sync failures #1738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SSH public keys for all machines. | ||
| # Single source of truth shared by per-host secrets.nix files and any | ||
| # activation script that needs to authorize cross-host access. | ||
| { | ||
| galactica = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEKze2jlpV7SyTKA2ezqbumpCiDn+5Sj4z5SxrqfzesX shunkakinoki@gmail.com"; | ||
| kyber = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO0IZtP3KSzY6GVSZ+R+VQYYfu3sEOVaQGDblQxAtwNM ubuntu@kyber"; | ||
| matic = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEeknNbHasmT+43PgO9oy0mutoe+V2R2ZNRa5SPOLmLN skakinoki@matic"; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,4 +44,16 @@ When run bash -c "grep 'chmod 600' '$SCRIPT'" | |||||
| The output should include 'chmod 600' | ||||||
| End | ||||||
| End | ||||||
|
|
||||||
| Describe 'failure visibility' | ||||||
| It 'does not silently discard scp stderr' | ||||||
| When run bash -c "grep 'scp ' '$SCRIPT'" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This regression test only greps the first line of the multi-line Prompt for AI agents
Suggested change
|
||||||
| The output should not include '2>/dev/null' | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression test is too narrow to catch a recurrence: this assertion only looks at lines containing Consider checking the whole script instead, e.g.: It 'does not silently discard scp stderr'
When run bash -c "! grep -n '2>/dev/null' '$SCRIPT'"
The status should be success
Endor a multi-line grep that spans the scp invocation ( |
||||||
| End | ||||||
|
|
||||||
| It 'logs scp failures to stderr' | ||||||
| When run bash -c "grep 'failed to fetch kubeconfig' '$SCRIPT'" | ||||||
| The output should include 'failed to fetch kubeconfig' | ||||||
| End | ||||||
| End | ||||||
| End | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329 | ||
| # shellcheck disable=SC2329,SC2016 | ||
|
|
||
| Describe 'config/k3s/activate.sh' | ||
| SCRIPT="$PWD/config/k3s/activate.sh" | ||
|
|
@@ -49,4 +49,100 @@ When run bash -c "grep -A 1 '! -f' '$SCRIPT'" | |
| The output should include 'exit 0' | ||
| End | ||
| End | ||
|
|
||
| Describe 'authorized_keys management' | ||
| It 'declares a placeholder for galactica authorized key' | ||
| When run bash -c "grep 'GALACTICA_AUTHORIZED_KEY' '$SCRIPT'" | ||
| The output should include '@galacticaAuthorizedKey@' | ||
| End | ||
|
|
||
| It 'defines an idempotent ensure_authorized_key helper' | ||
| When run bash -c "grep 'ensure_authorized_key' '$SCRIPT'" | ||
| The output should include 'ensure_authorized_key' | ||
| End | ||
|
|
||
| It 'guards against unsubstituted placeholder' | ||
| When run bash -c "grep -E '\\\"@\\\"\\*\\\"@\\\"' '$SCRIPT'" | ||
| The output should include '@' | ||
| End | ||
|
|
||
| It 'uses fixed-string match against authorized_keys' | ||
| When run bash -c "grep 'grep -qxF' '$SCRIPT'" | ||
| The output should include 'grep -qxF' | ||
| End | ||
|
|
||
| ensure_authorized_key_function() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Behavioral checks run a duplicated helper in the spec instead of the real Prompt for AI agents |
||
| cat <<'BASH' | ||
| ensure_authorized_key() { | ||
| local key="$1" | ||
| local ssh_dir="$HOME/.ssh" | ||
| local auth_file="$ssh_dir/authorized_keys" | ||
| if [ -z "$key" ] || [[ "$key" == "@"*"@" ]]; then | ||
| return 0 | ||
| fi | ||
| mkdir -p "$ssh_dir" | ||
| chmod 700 "$ssh_dir" | ||
| touch "$auth_file" | ||
| chmod 600 "$auth_file" | ||
| if grep -qxF "$key" "$auth_file"; then | ||
| return 0 | ||
| fi | ||
| if [ -s "$auth_file" ] && [ "$(tail -c1 "$auth_file" | wc -l)" -eq 0 ]; then | ||
| printf '\n' >>"$auth_file" | ||
| fi | ||
| printf '%s\n' "$key" >>"$auth_file" | ||
| } | ||
| BASH | ||
| } | ||
|
|
||
| It 'appends the key when authorized_keys does not exist' | ||
| When run bash -c ' | ||
| tmp=$(mktemp -d) | ||
| HOME="$tmp" | ||
| '"$(ensure_authorized_key_function)"' | ||
| ensure_authorized_key "ssh-ed25519 AAAATEST test@example" | ||
| grep -qxF "ssh-ed25519 AAAATEST test@example" "$tmp/.ssh/authorized_keys" | ||
| ' | ||
| The status should be success | ||
| End | ||
|
|
||
| It 'is idempotent on repeated runs' | ||
| When run bash -c ' | ||
| tmp=$(mktemp -d) | ||
| HOME="$tmp" | ||
| '"$(ensure_authorized_key_function)"' | ||
| ensure_authorized_key "ssh-ed25519 AAAATEST test@example" | ||
| ensure_authorized_key "ssh-ed25519 AAAATEST test@example" | ||
| ensure_authorized_key "ssh-ed25519 AAAATEST test@example" | ||
| count=$(grep -cxF "ssh-ed25519 AAAATEST test@example" "$tmp/.ssh/authorized_keys") | ||
| test "$count" = "1" | ||
| ' | ||
| The status should be success | ||
| End | ||
|
|
||
| It 'preserves existing keys when appending' | ||
| When run bash -c ' | ||
| tmp=$(mktemp -d) | ||
| HOME="$tmp" | ||
| mkdir -p "$tmp/.ssh" | ||
| printf "ssh-ed25519 AAAAEXISTING old@example\n" >"$tmp/.ssh/authorized_keys" | ||
| '"$(ensure_authorized_key_function)"' | ||
| ensure_authorized_key "ssh-ed25519 AAAANEW new@example" | ||
| grep -qxF "ssh-ed25519 AAAAEXISTING old@example" "$tmp/.ssh/authorized_keys" && | ||
| grep -qxF "ssh-ed25519 AAAANEW new@example" "$tmp/.ssh/authorized_keys" | ||
| ' | ||
| The status should be success | ||
| End | ||
|
|
||
| It 'no-ops when given an unsubstituted placeholder' | ||
| When run bash -c ' | ||
| tmp=$(mktemp -d) | ||
| HOME="$tmp" | ||
| '"$(ensure_authorized_key_function)"' | ||
| ensure_authorized_key "@galacticaAuthorizedKey@" | ||
| test ! -e "$tmp/.ssh/authorized_keys" | ||
| ' | ||
| The status should be success | ||
| End | ||
| End | ||
| End | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test 'does not silently discard scp stderr' is currently ineffective. Because
grep 'scp 'only returns the first line of the multi-linescpcommand, it does not see the redirection (which was on the following line due to the backslash). Consequently, this test would pass even if2>/dev/nullwere still present in the script. Usinggrep -A 1ensures the redirection line is included in the check.