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

Commit 3fc2ba1

Browse files
authored
add make clean-kssh to actually delete all config files when the service is stopped (#96)
1 parent 4cfae45 commit 3fc2ba1

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ keybaseca.config
33
nohup.out
44
env.list
55
__pycache__
6+
**/.mypy_cache/
7+
tests/env.sh
68

79
# sphinx generated files:
810
_build

docker/Dockerfile-ca

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ COPY --from=builder --chown=keybase:keybase /bot-sshca/bin/keybaseca bin/
4444
# copy in entrypoint scripts
4545
COPY --chown=keybase:keybase ./docker/entrypoint-generate.sh ./
4646
COPY --chown=keybase:keybase ./docker/entrypoint-server.sh ./
47+
COPY --chown=keybase:keybase ./docker/entrypoint-cleanup.sh ./
4748

4849
# Run container as root but only to be able to chown the Docker bind-mount,
4950
# then immediatetly step down to the keybase user via sudo in the entrypoint scripts

docker/Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ endif
2121

2222
# Generate a new CA key
2323
generate: env-file-exists build
24-
docker run -e FORCE_WRITE=$(FORCE_WRITE) --env-file ./env.list -v $(CURDIR)/example-keybaseca-volume:/mnt:rw ca:latest ./entrypoint-generate.sh
24+
docker run --init -e FORCE_WRITE=$(FORCE_WRITE) --env-file ./env.list -v $(CURDIR)/example-keybaseca-volume:/mnt:rw ca:latest ./entrypoint-generate.sh
2525
@echo -e "\nRun these commands on each server that you wish to use with the CA chatbot\n"
2626
@echo "useradd developer && mkdir -p /home/developer && chown developer:developer /home/developer # The user that will be used for non-root logins"
2727
@echo "echo \"`cat $(CURDIR)/example-keybaseca-volume/keybase-ca-key.pub`\" > /etc/ssh/ca.pub"
@@ -33,17 +33,21 @@ generate: env-file-exists build
3333

3434
# Start the CA chatbot in the background
3535
serve: env-file-exists ca-key-exists
36-
docker run -d --restart unless-stopped --env-file ./env.list -v $(CURDIR)/example-keybaseca-volume:/mnt:rw ca:latest ./entrypoint-server.sh
36+
docker run -d --init --restart unless-stopped --env-file ./env.list -v $(CURDIR)/example-keybaseca-volume:/mnt:rw ca:latest ./entrypoint-server.sh
3737
@echo 'Started CA bot service in the background... Use `docker ps` and `docker logs` to monitor it'
3838

3939
# Stop the service
40-
stop:
40+
stop: clean-kssh
4141
docker kill `docker ps -q --filter ancestor=ca`
4242

4343
# Restart the service (useful if you updated env.list)
4444
restart: stop serve
4545

46-
# Wipe all data
46+
# Delete all kssh config files
47+
clean-kssh: env-file-exists
48+
docker run --init -e FORCE_WRITE=$(FORCE_WRITE) --env-file ./env.list -v $(CURDIR)/example-keybaseca-volume:/mnt:rw ca:latest ./entrypoint-cleanup.sh
49+
50+
# Delete all CA data
4751
clean: confirm-clean reset-permissions
4852
@# Sudo since it is likely owned by another use since it was written from a docker container
4953
sudo rm -rf example-keybaseca-volume/keybaseca*

docker/entrypoint-cleanup.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
# chown as root
6+
chown -R keybase:keybase /mnt
7+
8+
# Run everything else as the keybase user
9+
sudo -i -u keybase bash << EOF
10+
export "FORCE_WRITE=$FORCE_WRITE"
11+
export "KEYBASE_USERNAME=$KEYBASE_USERNAME"
12+
export "KEYBASE_PAPERKEY=$KEYBASE_PAPERKEY"
13+
nohup bash -c "KEYBASE_RUN_MODE=prod kbfsfuse /keybase | grep -v 'ERROR Mounting the filesystem failed' &"
14+
sleep ${KEYBASE_TIMEOUT:-5}
15+
keybase oneshot
16+
bin/keybaseca --wipe-all-configs
17+
sleep ${KEYBASE_TIMEOUT:-5}
18+
EOF

src/cmd/keybaseca/keybaseca.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
cli.BoolFlag{
4343
Name: "wipe-all-configs",
4444
Hidden: true,
45-
Usage: "Used in the integration tests to clean all client configs from KBFS",
45+
Usage: "Clean all client configs the CA Keybase user can find from KBFS",
4646
},
4747
cli.BoolFlag{
4848
Name: "wipe-logs",
@@ -214,6 +214,8 @@ func mainAction(c *cli.Context) error {
214214
semaphore := sync.WaitGroup{}
215215
semaphore.Add(len(teams))
216216
boundChan := make(chan interface{}, shared.BoundedParallelismLimit)
217+
teamsFound := []string{}
218+
teamsFoundMutex := sync.Mutex{}
217219
for _, team := range teams {
218220
go func(team string) {
219221
// Blocks until there is room in boundChan
@@ -226,6 +228,9 @@ func mainAction(c *cli.Context) error {
226228
if err != nil {
227229
fmt.Printf("%v\n", err)
228230
}
231+
teamsFoundMutex.Lock()
232+
teamsFound = append(teamsFound, team)
233+
teamsFoundMutex.Unlock()
229234
}
230235
semaphore.Done()
231236

@@ -234,6 +239,7 @@ func mainAction(c *cli.Context) error {
234239
}(team)
235240
}
236241
semaphore.Wait()
242+
fmt.Printf("Deleted configs found in these teams: %+v\n", teamsFound)
237243
case c.Bool("wipe-logs"):
238244
conf, err := loadServerConfig()
239245
if err != nil {

0 commit comments

Comments
 (0)