Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ Now on the server where you wish to run the chatbot, start the chatbot itself:
make serve # Runs inside of docker for ease of use
```

Now download the kssh binary and start SSHing! See https://github.com/keybase/bot-sshca/releases to download the most
You can confirm that the bot is running by sending the message `ping @bot_username` in any of the configured team chat
channels (if `CHAT_CHANNEL` is configured, the message must be sent in that specific channel). The bot should reply with
`pong @your_username`.

Now you can download the kssh binary and start SSHing! See https://github.com/keybase/bot-sshca/releases to download the most
recent version of kssh for your platform.

```bash
Expand All @@ -72,4 +76,3 @@ If you update any environment variables, it is necessary to restart the keybasec
by running `make restart`. Note that it is not required to re-run `make generate`.

Note that this means `kssh` will not work for a brief period of time while the container restarts.

2 changes: 1 addition & 1 deletion src/keybaseca/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func StartBot(conf config.Config) error {
if shared.IsPingRequest(messageBody, kbc.GetUsername()) {
// Respond to messages of the form `ping @botName` with `pong @senderName`
log.Debug("Responding to ping with pong")
_, err = kbc.SendMessageByConvID(msg.Message.ConvID, fmt.Sprintf(shared.GeneratePingResponse(msg.Message.Sender.Username)))
_, err = kbc.SendMessageByConvID(msg.Message.ConvID, shared.GeneratePingResponse(msg.Message.Sender.Username))
if err != nil {
LogError(conf, kbc, msg, err)
continue
Expand Down
12 changes: 6 additions & 6 deletions src/shared/chat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ func IsAckResponse(msg string) bool {
}

// Generate a ping request message
func GeneratePingRequest(botname string) string {
return fmt.Sprintf("ping @%s", botname)
func GeneratePingRequest(username string) string {
return fmt.Sprintf("ping @%s", username)
}

// Returns whether the given message is a ping request
func IsPingRequest(msg, botUsername string) bool {
return strings.TrimSpace(msg) == fmt.Sprintf("ping @%s", botUsername)
return strings.TrimSpace(msg) == GeneratePingRequest(botUsername)
}

// Generate a ping response message
func GeneratePingResponse(botname string) string {
return fmt.Sprintf("pong @%s", botname)
func GeneratePingResponse(username string) string {
return fmt.Sprintf("pong @%s", username)
}

// Returns whether the given message is a ping response
func IsPingResponse(msg, localUsername string) bool {
return strings.TrimSpace(msg) == fmt.Sprintf("pong @%s", localUsername)
return strings.TrimSpace(msg) == GeneratePingResponse(localUsername)
}
4 changes: 2 additions & 2 deletions tests/bot-entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def load_env():
"echo yes | bin/keybaseca backup > /shared/cakey.backup\n"
# The output from this sign operation is tested in test_env_1.py
"ssh-keygen -t ed25519 -f /shared/userkey -N '' && bin/keybaseca sign --public-key /shared/userkey.pub > /shared/keybaseca-sign.out\n"
"bin/keybaseca service &"
"bin/keybaseca --debug service > /tmp/debug.out &"
) % (shlex.quote(path)))
# Sleep so keybaseca has time to start
time.sleep(5)
time.sleep(10)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the tests on my (slow) laptop had some intermittent failures with this, so just bumped it. It makes the tests a little slower but they're already slow enough so /shrug

return "OK"

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def outputs_audit_log(tc: TestConfig, filename: str, expected_number: int):
yield

# And sleep to give KBFS some time
time.sleep(1.5)
time.sleep(2.5)

# Then see if there are new lines using set difference. This is only safe/reasonable since we include a
# timestamp in audit log lines.
Expand Down
8 changes: 7 additions & 1 deletion tests/tests/test_env_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def configure_env(self):
def test_config(self):
return TestConfig.getDefaultTestConfig()

def test_ping_pong_command(self, test_config):
run_command(f"keybase chat send --channel ssh-provision {test_config.subteam}.ssh 'ping @{test_config.bot_username}'")
time.sleep(5)
recent_messages = run_command(f"keybase chat list-unread --since 1m")
assert (b"pong @%s" % test_config.username.encode('utf-8')) in recent_messages

def test_kssh_staging_user(self, test_config):
# Test ksshing into staging as user
with outputs_audit_log(test_config, filename=test_env_1_log_filename, expected_number=1):
Expand Down Expand Up @@ -166,4 +172,4 @@ def test_kssh_alternate_binary(self, test_config):
assert_contains_hash(test_config.expected_hash, run_command_with_agent("bin/kssh -q -o StrictHostKeyChecking=no user@sshd-staging 'sha1sum /etc/unique'"))
run_command("bin/kssh --set-keybase-binary ''")
finally:
run_command("sudo rm /usr/local/bin/keybase")
run_command("sudo rm /usr/local/bin/keybase")