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

Commit 8ea43a4

Browse files
ddworkenmmou
andauthored
Add KEYBASE_TIMEOUT configuration parameter to configure a custom timeout for interacting with the bot (#92)
* Update dependency versions in order to make it possible to configure keybase timeouts In order to configure the timeouts for #91, we need to pull in the latest KB chat library which was updated here: keybase/go-keybase-chat-bot#67 The library also changed the arg order to a function, so swapped that in our code to make everything continue to work. * Add KEYBASE_TIMEOUT configuration parameter to configure a custom timeout for interacting with the bot * Add docs for KEYBASE_TIMEOUT * Make the sleeps that are waiting for keybase to startup also wait for * make sleep time 5s, to be consistent with how KEYBASE_TIMEOUT is used elsewhere Co-authored-by: M Mou <[email protected]>
1 parent add9e36 commit 8ea43a4

File tree

12 files changed

+103
-33
lines changed

12 files changed

+103
-33
lines changed

docker/Dockerfile-ca

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN apk update && apk add --no-cache go curl git musl-dev gcc
88
# build keybase binary
99
WORKDIR /go
1010
ENV GOPATH=/go
11-
ENV KEYBASE_VERSION=5.0.0
11+
ENV KEYBASE_VERSION=5.4.0
1212
RUN go get -d github.com/keybase/client/go/keybase
1313
RUN cd src/github.com/keybase/client/go/keybase && git checkout v$KEYBASE_VERSION
1414
RUN go install -tags production github.com/keybase/client/go/keybase

docker/entrypoint-generate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export "TEAMS=$TEAMS"
1212
export "KEYBASE_USERNAME=$KEYBASE_USERNAME"
1313
export "KEYBASE_PAPERKEY=$KEYBASE_PAPERKEY"
1414
nohup bash -c "KEYBASE_RUN_MODE=prod kbfsfuse /keybase | grep -v 'ERROR Mounting the filesystem failed' &"
15-
sleep 3
15+
sleep ${KEYBASE_TIMEOUT:-5}
1616
keybase oneshot
1717
bin/keybaseca generate
1818
EOF

docker/entrypoint-server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export "TEAMS=$TEAMS"
1111
export "KEYBASE_USERNAME=$KEYBASE_USERNAME"
1212
export "KEYBASE_PAPERKEY=$KEYBASE_PAPERKEY"
1313
nohup bash -c "KEYBASE_RUN_MODE=prod kbfsfuse /keybase | grep -v 'ERROR Mounting the filesystem failed' &"
14-
sleep 3
14+
sleep ${KEYBASE_TIMEOUT:-5}
1515
keybase oneshot
1616
bin/keybaseca service
1717
EOF

docs/env.md

+13
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ export ANNOUNCEMENT="Hello! I'm {USERNAME} and I'm an SSH bot! I'm currently lis
106106
export ANNOUNCEMENT="Hello! I'm {USERNAME} and I'm an SSH bot! Being in {CURRENT_TEAM} will grant you SSH access to certain servers. Reach out to @dworken for more information."
107107
```
108108

109+
### Timeout
110+
111+
The `KEYBASE_TIMEOUT` environment specifies the number of seconds to wait for Keybase operations. If you are running
112+
the bot on an especially slow computer (ie a Raspberry Pi) or with a high latency internet connection, you may need
113+
to tune this. Defaults to 5 seconds.
114+
115+
Examples:
116+
117+
```bash
118+
export KEYBASE_TIMEOUT="5"
119+
export KEYBASE_TIMEOUT="15"
120+
```
121+
109122
## Developer Options
110123

111124
These environment variables are mainly useful for dev work. For security reasons, it is recommended always to run a

go.mod

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ module github.com/keybase/bot-sshca
33
go 1.12
44

55
require (
6+
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
67
github.com/google/uuid v1.1.1
7-
github.com/keybase/go-keybase-chat-bot v0.0.0-20190903135515-79c56220e558
8-
github.com/sirupsen/logrus v1.4.2
9-
github.com/stretchr/testify v1.3.0
10-
github.com/urfave/cli v1.21.0
11-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
12-
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e // indirect
8+
github.com/keybase/go-keybase-chat-bot v0.0.0-20200420153642-84a89a8a3623
9+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
10+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
11+
github.com/sirupsen/logrus v1.5.0
12+
github.com/stretchr/testify v1.5.1
13+
github.com/urfave/cli v1.22.4
14+
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877
15+
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
16+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
17+
gopkg.in/yaml.v2 v2.2.8 // indirect
1318
)

go.sum

+30-13
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
4+
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
25
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
36
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
47
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
58
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
69
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
710
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
8-
github.com/keybase/go-keybase-chat-bot v0.0.0-20190903135515-79c56220e558 h1:iZ1RdFAAftDrkcuYWWNOJt+LBUo8tefd0GywewLuTqE=
9-
github.com/keybase/go-keybase-chat-bot v0.0.0-20190903135515-79c56220e558/go.mod h1:vNc28YFzigVJod0j5EbuTtRIe7swx8vodh2yA4jZ2s8=
11+
github.com/keybase/go-keybase-chat-bot v0.0.0-20200420153642-84a89a8a3623 h1:QN/gM9pje2q1r36STbYP+D0Qr47AKsCG/c0V7Uy0iFY=
12+
github.com/keybase/go-keybase-chat-bot v0.0.0-20200420153642-84a89a8a3623/go.mod h1:vNc28YFzigVJod0j5EbuTtRIe7swx8vodh2yA4jZ2s8=
1013
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
1114
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
15+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
16+
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
17+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
18+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
19+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
20+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
21+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
1222
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1323
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14-
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
15-
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
24+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
25+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
26+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
27+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
28+
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
29+
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
1630
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
17-
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1831
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
19-
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
20-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
21-
github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE=
22-
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
32+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
33+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
34+
github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
35+
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
2336
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
24-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
25-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
37+
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877 h1:IhZPbxNd1UjBCaD5AfpSSbJTRlp+ZSuyuH5uoksNS04=
38+
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
2639
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
2740
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2841
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
2942
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3043
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31-
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
32-
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
44+
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8=
45+
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3346
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3447
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3548
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
49+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
50+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3651
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
3752
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
53+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
54+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

src/keybaseca/bot/bot.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
// Get a running instance of the keybase chat API. Will use the configured credentials if necessary.
2222
func GetKBChat(conf config.Config) (*kbchat.API, error) {
23-
return botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername())
23+
return botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername(), conf.GetKeybaseTimeout())
2424
}
2525

2626
// Get the username of the user that the keybaseca bot is running as
@@ -190,7 +190,7 @@ func sendAnnouncementMessage(conf config.Config, kbc *kbchat.API) error {
190190
Teams: conf.GetTeams()})
191191

192192
var channel *string
193-
_, err := kbc.SendMessageByTeamName(team, announcement, channel)
193+
_, err := kbc.SendMessageByTeamName(team, channel, announcement)
194194
if err != nil {
195195
return err
196196
}

src/keybaseca/botwrapper/get_bot.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ package botwrapper
66
// dependency cycle.
77

88
import (
9+
"time"
10+
911
"github.com/keybase/go-keybase-chat-bot/kbchat"
1012
)
1113

1214
// Get a running instance of the keybase chat API. Will use the supplied credentials if necessary. If possible, it
1315
// is preferred to reference the `GetKBChat` method in the `bot` package instead
14-
func GetKBChat(keybaseHomeDir, keybasePaperKey, keybaseUsername string) (*kbchat.API, error) {
16+
func GetKBChat(keybaseHomeDir, keybasePaperKey, keybaseUsername string, keybaseTimeout time.Duration) (*kbchat.API, error) {
1517
runOptions := kbchat.RunOptions{}
1618
if keybaseHomeDir != "" {
1719
runOptions.HomeDir = keybaseHomeDir
1820
}
1921
if keybasePaperKey != "" && keybaseUsername != "" {
2022
runOptions.Oneshot = &kbchat.OneshotOptions{PaperKey: keybasePaperKey, Username: keybaseUsername}
2123
}
22-
return kbchat.Start(runOptions)
24+
api, err := kbchat.Start(runOptions)
25+
if err != nil {
26+
return nil, err
27+
}
28+
api.Timeout = keybaseTimeout
29+
return api, nil
2330
}

src/keybaseca/config/config.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7+
"strconv"
78
"strings"
9+
"time"
810

911
"github.com/keybase/bot-sshca/src/keybaseca/constants"
1012

@@ -29,11 +31,18 @@ type Config interface {
2931
GetStrictLogging() bool
3032
GetAnnouncement() string
3133
DebugString() string
34+
GetKeybaseTimeout() time.Duration
3235
}
3336

3437
// Validate the given config file. If offline, do so without connecting to keybase (used in code that is meant
3538
// to function without any reliance on Keybase).
3639
func ValidateConfig(conf EnvConfig, offline bool) error {
40+
if conf.getKeybaseTimeout() != "" {
41+
_, err := strconv.Atoi(conf.getKeybaseTimeout())
42+
if err != nil {
43+
return fmt.Errorf("failed to validate KEYBASE_TIMEOUT, value is not an integer: %v", err)
44+
}
45+
}
3746
if len(conf.GetTeams()) == 0 {
3847
return fmt.Errorf("must specify at least one team via the TEAMS environment variable")
3948
}
@@ -70,7 +79,7 @@ func ValidateConfig(conf EnvConfig, offline bool) error {
7079
return fmt.Errorf("you must set set a paper key if you set a username (username='%s', key='%s')", conf.GetKeybaseUsername(), conf.GetKeybasePaperKey())
7180
}
7281
if !offline {
73-
err := validateUsernamePaperkey(conf.GetKeybaseHomeDir(), conf.GetKeybaseUsername(), conf.GetKeybasePaperKey())
82+
err := validateUsernamePaperkey(conf.GetKeybaseHomeDir(), conf.GetKeybaseUsername(), conf.GetKeybasePaperKey(), conf.GetKeybaseTimeout())
7483
if err != nil {
7584
return fmt.Errorf("failed to validate KEYBASE_USERNAME and KEYBASE_PAPERKEY: %v", err)
7685
}
@@ -80,8 +89,8 @@ func ValidateConfig(conf EnvConfig, offline bool) error {
8089
return nil
8190
}
8291

83-
func validateUsernamePaperkey(homedir, username, paperkey string) error {
84-
api, err := botwrapper.GetKBChat(homedir, username, paperkey)
92+
func validateUsernamePaperkey(homedir, username, paperkey string, keybaseTimeout time.Duration) error {
93+
api, err := botwrapper.GetKBChat(homedir, username, paperkey, keybaseTimeout)
8594
if err != nil {
8695
return err
8796
}
@@ -98,7 +107,7 @@ func validateUsernamePaperkey(homedir, username, paperkey string) error {
98107
// Validates the given teamName and channelName to determine whether or not the given channelName is the name
99108
// of a channel inside the given team. Returns nil if everything validates.
100109
func validateChannel(conf Config, teamName string, channelName string) error {
101-
api, err := botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername())
110+
api, err := botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername(), conf.GetKeybaseTimeout())
102111
if err != nil {
103112
return err
104113
}
@@ -256,6 +265,24 @@ func (ef *EnvConfig) GetAnnouncement() string {
256265
return os.Getenv("ANNOUNCEMENT")
257266
}
258267

268+
// Get the timeout for interacting with Keybase specified as a string. May be empty.
269+
func (ef *EnvConfig) getKeybaseTimeout() string {
270+
return os.Getenv("KEYBASE_TIMEOUT")
271+
}
272+
273+
// Get the timeout for interacting with Keybase as a time.Duration. Defaults to 5 seconds.
274+
func (ef *EnvConfig) GetKeybaseTimeout() time.Duration {
275+
timeoutStr := ef.getKeybaseTimeout()
276+
if timeoutStr == "" {
277+
return 5 * time.Second
278+
}
279+
timeoutInt, err := strconv.Atoi(timeoutStr)
280+
if err != nil {
281+
panic("Found non-int in the keybase timeout field! This should never happen due to config validation...")
282+
}
283+
return time.Duration(timeoutInt) * time.Second
284+
}
285+
259286
// Dump this EnvConfig to a string for debugging purposes
260287
func (ef *EnvConfig) DebugString() string {
261288
return fmt.Sprintf("CAKeyLocation='%s'; KeybaseHomeDir='%s'; KeybasePaperKey='%s'; KeybaseUsername='%s'; "+

src/keybaseca/sshutils/sshutils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func SignKey(caKeyLocation, keyID, principals, expiration, publicKey string) (si
156156
// attacker would be able to provision SSH keys for environments that they should not have access to.
157157
func getPrincipals(conf config.Config, sr shared.SignatureRequest) (string, error) {
158158
// Start by getting the list of teams the user is in
159-
api, err := botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername())
159+
api, err := botwrapper.GetKBChat(conf.GetKeybaseHomeDir(), conf.GetKeybasePaperKey(), conf.GetKeybaseUsername(), conf.GetKeybaseTimeout())
160160
if err != nil {
161161
return "", fmt.Errorf("failed to retrieve the list of teams the user is in: %v", err)
162162
}

src/kssh/bot.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func GetSignedKey(config ConfigFile, request shared.SignatureRequest) (shared.Si
4848
default:
4949

5050
}
51-
_, err = kbc.SendMessageByTeamName(config.TeamName, shared.GenerateAckRequest(kbc.GetUsername()), getChannel(config))
51+
_, err = kbc.SendMessageByTeamName(config.TeamName, getChannel(config), shared.GenerateAckRequest(kbc.GetUsername()))
5252
if err != nil {
5353
fmt.Printf("Failed to send AckRequest: %v\n", err)
5454
}
@@ -86,7 +86,7 @@ func GetSignedKey(config ConfigFile, request shared.SignatureRequest) (shared.Si
8686
if err != nil {
8787
return empty, err
8888
}
89-
_, err = kbc.SendMessageByTeamName(config.TeamName, shared.SignatureRequestPreamble+string(marshaledRequest), getChannel(config))
89+
_, err = kbc.SendMessageByTeamName(config.TeamName, getChannel(config), shared.SignatureRequestPreamble+string(marshaledRequest))
9090
if err != nil {
9191
return empty, err
9292
}

tests/envFiles/test_env_1

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export KEYBASE_USERNAME="$BOT_USERNAME"
88
export CHAT_CHANNEL="$SUBTEAM.ssh#ssh-provision"
99
export CA_KEY_LOCATION="/shared/keybase-ca-key"
1010
export ANNOUNCEMENT='Hello my name is {USERNAME}. This is {CURRENT_TEAM} and the configured teams are {TEAMS}'
11+
export KEYBASE_TIMEOUT='10'

0 commit comments

Comments
 (0)