Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 15b45e7

Browse files
committed
Working integration test for setting the default binary
1 parent 1f151a3 commit 15b45e7

5 files changed

Lines changed: 42 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ GLOBAL OPTIONS:
164164
--set-default-user Set the default SSH user to be used for kssh. Useful if you use ssh configs that do not set
165165
a default SSH user
166166
--clear-default-user Clear the default SSH user
167+
--set-keybase-binary Run kssh with a specific keybase binary rather than resolving via $PATH
167168
```
168169

169170
## Architecture

src/cmd/kssh/kssh.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var cliArguments = []kssh.CLIArgument{
103103
{Name: "--clear-default-user", HasArgument: false},
104104
{Name: "--help", HasArgument: false},
105105
{Name: "-v", HasArgument: false, Preserve: true},
106+
{Name: "--set-keybase-binary", HasArgument: true},
106107
}
107108

108109
func generateHelpPage() string {
@@ -127,7 +128,8 @@ GLOBAL OPTIONS:
127128
is using Keybase SSH CA
128129
--set-default-user Set the default SSH user to be used for kssh. Useful if you use ssh configs that do not set
129130
a default SSH user
130-
--clear-default-user Clear the default SSH user`)
131+
--clear-default-user Clear the default SSH user
132+
--set-keybase-binary Run kssh with a specific keybase binary rather than resolving via $PATH `)
131133
}
132134

133135
type Action int
@@ -188,6 +190,15 @@ func handleArgs(args []string) (string, []string, Action, error) {
188190
fmt.Println("Cleared default bot, exiting...")
189191
os.Exit(0)
190192
}
193+
if arg.Argument.Name == "--set-keybase-binary" {
194+
err := kssh.SetKeybaseBinaryPath(arg.Value)
195+
if err != nil {
196+
fmt.Printf("Failed to set the keybase binary: %v\n", err)
197+
os.Exit(1)
198+
}
199+
fmt.Println("Set keybase binary, exiting...")
200+
os.Exit(0)
201+
}
191202
if arg.Argument.Name == "--provision" {
192203
action = Provision
193204
}

src/kssh/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ func GetDefaultSSHUser() (string, error) {
149149
return lcf.DefaultSSHUser, nil
150150
}
151151

152+
// Set the default SSH user to use for kssh connections.
153+
func SetKeybaseBinaryPath(path string) error {
154+
lcf, err := getCurrentConfig()
155+
if err != nil {
156+
return err
157+
}
158+
159+
lcf.KeybaseBinPath = path
160+
return writeConfig(lcf)
161+
}
162+
152163
// Set the default SSH user to use for kssh connections.
153164
func SetDefaultSSHUser(username string) error {
154165
if strings.ContainsAny(username, " \t\n\r'\"") {

tests/Dockerfile-kssh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ USER keybase
1818
# Install go
1919
USER root
2020
RUN add-apt-repository ppa:gophers/archive -y
21-
RUN apt-get update
22-
RUN apt-get install golang-1.11-go git sudo python3 python3-pip -y
21+
RUN apt-get update -y
22+
RUN apt-get install golang-1.11-go git sudo python3 python3-pip sudo -y
2323
RUN pip3 install pytest requests
24-
USER keybase
24+
25+
# Make it so the keybase user has passwordless sudo so it can move the keybase binary around
26+
RUN echo "keybase ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/keybase && \
27+
chmod 0440 /etc/sudoers.d/keybase
2528

2629
# Install go dependencies (speeds up future builds)
2730
COPY --chown=keybase go.mod .

tests/tests/test_env_1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,15 @@ def test_kssh_default_user(self, test_config):
156156
assert_contains_hash(test_config.expected_hash, run_command_with_agent("bin/kssh -q -o StrictHostKeyChecking=no -J sshd-staging sshd-prod 'sha1sum /etc/unique'"))
157157
# Reset the default user
158158
run_command_with_agent("bin/kssh --clear-default-user")
159+
160+
def test_kssh_alternate_binary(self, test_config):
161+
# Test it by creating another keybase binary earlier in the path and running kssh. This isn't a perfect test but it is
162+
# enough to smoketest it
163+
run_command("echo '#!/bin/bash' | sudo tee /usr/local/bin/keybase")
164+
run_command("sudo chmod +x /usr/local/bin/keybase")
165+
try:
166+
run_command("bin/kssh --set-keybase-binary /usr/bin/keybase")
167+
assert_contains_hash(test_config.expected_hash, run_command_with_agent("bin/kssh -q -o StrictHostKeyChecking=no user@sshd-staging 'sha1sum /etc/unique'"))
168+
run_command("bin/kssh --set-keybase-binary ''")
169+
finally:
170+
run_command("sudo rm /usr/local/bin/keybase")

0 commit comments

Comments
 (0)