This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Merged
Prototype #1
Changes from 85 commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
b128bdd
Basic keys working
richfitz d919036
Fix lint
richfitz 322ed5e
Correct format for known_hosts
richfitz e840e54
Relint
richfitz 94df3e0
Check a configuration
richfitz 674e38c
Tidy up to work locally
richfitz c0d4144
Add simple server commands
richfitz d151bea
Smalll pull utility
richfitz 3aa477f
Add ssh configuration
richfitz 0ee8303
Allow basic backup
richfitz efb6ff9
Basic support for restore
richfitz 57f0b31
Tidy up
richfitz dbe078d
Better handling of input commands
richfitz 86fd3c1
Support data export
richfitz 3f9cf45
Big tidyup, simpler now
richfitz d93b3cd
Add manual import path
richfitz 409931e
Reformat
richfitz 4f6f43a
Ignore more files
richfitz b265da9
Add docker images
richfitz a095405
Add volume marker
richfitz 3d12d0d
Update ssh config
richfitz 28b2ccc
Basic config validation
richfitz bde6225
Fix tests
richfitz 777ddec
Expand config examples
richfitz e25da6d
Add dev notes
richfitz 3357c88
Drop extra spaces in cli usage
richfitz 156cce6
Generate all keys at once
richfitz 21d533c
Use correct vault
richfitz c910290
Compatibility tweaks
richfitz bd3a78e
Start moving to having an identity file
richfitz 835b277
Test for unconfigured
richfitz 3fc461e
Better error with invalid name given
richfitz 6d4cbff
Expand testing
richfitz 9889dde
Expand testing
richfitz 6ce7f86
Fix lint
richfitz 357a70b
Basic tests for server
richfitz 54b341c
Bunch more mocks
richfitz 8e89f5b
A little utility testing
richfitz 729daee
Expand server control
richfitz ca229c3
Tidy up docs
richfitz 9bf458d
Basic dry run tests for backup/restore
richfitz faa1cf9
Interaction tests of running backup/restore
richfitz ce7b332
Tidy up docs
richfitz c293b94
Expand testing
richfitz 1c11d19
More utility tests
richfitz e536299
Share approach from containers to volumes
richfitz da9b625
New docker fixture
richfitz be20b85
Isolate tests with fixtures
richfitz 99aedd5
Add connection test
richfitz 9594d3e
Expand development docs
richfitz 3290070
Expand main docs
richfitz 1eea639
Add extra cli test
richfitz eba7ca6
Drop archive creation for now
richfitz 173a17c
Shut down server
richfitz dbb4ff9
Try installing vault from git
richfitz d5f6246
Correct package-from-github syntax
richfitz dafd0b5
Another attempt at versions
richfitz 1b00827
Install vault if required
richfitz 10e2397
Add tmate
richfitz 58ea371
Skip test for now
richfitz 89e16be
Correct skip syntax
richfitz 59f5f39
Fix lint
richfitz f16b601
Replace integration test with unit test
richfitz 10c61a8
Fix lint
richfitz a8ddeb0
Change mount point
richfitz 9f0a6b7
Use different structure for storage
richfitz 5145c13
Move keys too
richfitz ab1eab6
Add buildkite configuration
richfitz 4ce714c
Fix lint
richfitz 22890cf
Fix docker build
richfitz 71898cd
Relax naming requirement
richfitz fba1963
Use correct branch for images
richfitz f71a507
Pull images in action
richfitz 63b3d65
Better docs
richfitz 16fbbdf
Remove dep from docker
richfitz c8e28e6
Remove redundant call
richfitz b44e61b
Add missing arg to backup
richfitz 1f15bbd
Don't store things double-secret
richfitz c7478c1
Don't hardcode branch in tests
richfitz 569b308
Use literal branch name
richfitz 43e3648
Allow ommitting the path
richfitz 4e14809
Apply suggestions from code review
richfitz 6bc9e1c
Fix fstring, with test
richfitz 6765c34
Use more descriptive name for utility
richfitz 859dae2
Apply suggestions from code review
richfitz d5e2233
Update README.md
richfitz c876866
Refactor to use a common service approach
richfitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.pyc | ||
__pycache__ | ||
dist/ | ||
.coverage | ||
coverage.xml | ||
*.tar | ||
.privateer_identity | ||
tmp/ | ||
.coverage.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
steps: | ||
- label: ":whale: Build and push" | ||
command: docker/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Development notes | ||
|
||
Because this uses docker, vault and requires work with hostnames, this is going to be hard to test properly without a lot of mocking. We'll update this as our strategy improves. | ||
|
||
## Vault server for testing | ||
|
||
We use [`vault-dev`](https://github.com/vimc/vault-dev) to bring up vault in testing mode. You can also do this manually (e.g., to match the configuration in [`example/simple.json`](example/simple.json) by running | ||
|
||
``` | ||
vault server -dev -dev-kv-v1 | ||
``` | ||
|
||
If you need to interact with this on the command line, use: | ||
|
||
``` | ||
export VAULT_ADDR='http://127.0.0.1:8200' | ||
export VAULT_TOKEN=$(cat ~/.vault-token) | ||
``` | ||
|
||
within the hatch environment before running any commands. | ||
|
||
## Worked example | ||
|
||
We need to swap in the globally-findable address for alice (`alice.example.com`) for the value of the machine this is tested on: | ||
|
||
``` | ||
mkdir -p tmp | ||
sed "s/alice.example.com/$(hostname)/" example/local.json > tmp/privateer.json | ||
``` | ||
|
||
Create a set of keys | ||
|
||
``` | ||
privateer2 --path tmp keygen --all | ||
``` | ||
|
||
You could also do this individually like | ||
|
||
``` | ||
privateer2 --path tmp keygen alice | ||
``` | ||
|
||
Set up the key volumes | ||
|
||
``` | ||
privateer2 --path tmp configure alice | ||
privateer2 --path tmp configure bob | ||
``` | ||
|
||
Start the server, as a background process (note that if these were on different machine the `privateer2 configure <name>` step would generate the `.privateer_identity` automatically so the `--as` argument is not needed) | ||
|
||
``` | ||
privateer2 --path tmp --as=alice server start | ||
``` | ||
|
||
Once `alice` is running, we can test this connection from `bob`: | ||
|
||
``` | ||
privateer2 --path tmp --as=bob check --connection | ||
``` | ||
|
||
This command would be simpler to run if we are in the `tmp` directory, which would be the usual situation in a multi-machine setup | ||
|
||
``` | ||
privateer2 check --connection | ||
``` | ||
|
||
For all other commands below, you can drop the `--path` and `--as` arguments if you change directory. | ||
|
||
Create some random data within the `data` volume (this is the one that we want to send from `bob` to `alice`) | ||
|
||
``` | ||
docker volume create data | ||
docker run -it --rm -v data:/data ubuntu bash -c "base64 /dev/urandom | head -c 100000 > /data/file1.txt" | ||
``` | ||
|
||
We can now backup from `bob` to `alice` as: | ||
|
||
``` | ||
privateer2 --path tmp --as=bob backup data | ||
``` | ||
|
||
or see what commands you would need in order to try this yourself: | ||
|
||
``` | ||
privateer2 --path tmp --as=bob backup data --dry-run | ||
``` | ||
|
||
Delete the volume | ||
|
||
``` | ||
docker volume rm data | ||
``` | ||
|
||
We can now restore it: | ||
|
||
``` | ||
privateer2 --path tmp --as=bob restore data | ||
``` | ||
|
||
or see the commands to do this ourselves: | ||
|
||
``` | ||
privateer2 --path tmp --as=bob restore data --dry-run | ||
``` | ||
|
||
Tear down the server with | ||
|
||
``` | ||
privateer2 --path tmp --as=alice server stop | ||
``` | ||
|
||
## Writing tests | ||
|
||
We use a lot of global resources, so it's easy to leave behind volumes and containers (often exited) after running tests. At best this is lazy and messy, but at worst it creates hard-to-diagnose dependencies between tests. Try and create names for auto-cleaned volumes and containers using the `managed_docker` fixture (see [`tests/conftest.py`](tests/conftest.py) for details). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM ubuntu | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
openssh-client \ | ||
rsync && \ | ||
mkdir -p /root/.ssh | ||
|
||
COPY ssh_config /etc/ssh/ssh_config | ||
VOLUME /privateer/keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM ubuntu | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
openssh-client \ | ||
openssh-server \ | ||
rsync && \ | ||
mkdir -p /var/run/sshd && \ | ||
mkdir -p /root/.ssh | ||
|
||
COPY sshd_config /etc/ssh/sshd_config | ||
|
||
VOLUME /privateer/keys | ||
VOLUME /privateer/volumes | ||
EXPOSE 22 | ||
|
||
ENTRYPOINT ["/usr/sbin/sshd", "-D", "-E", "/dev/stderr"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
set -exu | ||
|
||
HERE=$(dirname $0) | ||
. $HERE/common | ||
|
||
docker build --pull \ | ||
--tag $TAG_SERVER_SHA \ | ||
-f $HERE/Dockerfile.server \ | ||
$HERE | ||
|
||
docker build --pull \ | ||
--tag $TAG_CLIENT_SHA \ | ||
-f $HERE/Dockerfile.client \ | ||
$HERE | ||
|
||
docker push $TAG_SERVER_SHA | ||
docker push $TAG_CLIENT_SHA | ||
|
||
docker tag $TAG_SERVER_SHA $TAG_SERVER_BRANCH | ||
docker push $TAG_SERVER_BRANCH | ||
docker tag $TAG_CLIENT_SHA $TAG_CLIENT_BRANCH | ||
docker push $TAG_CLIENT_BRANCH | ||
|
||
if [ $GIT_BRANCH == "main" ]; then | ||
docker tag $TAG_SERVER_SHA $TAG_SERVER_LATEST | ||
docker push $TAG_SERVER_LATEST | ||
docker tag $TAG_CLIENT_SHA $TAG_CLIENT_LATEST | ||
docker push $TAG_CLIENT_LATEST | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*-sh-*- | ||
DOCKER_ROOT=$(realpath $HERE/..) | ||
PACKAGE_ORG=mrcide | ||
CLIENT_NAME=privateer-client | ||
SERVER_NAME=privateer-server | ||
|
||
# Buildkite doesn't check out a full history from the remote (just the | ||
# single commit) so you end up with a detached head and git rev-parse | ||
# doesn't work | ||
if [ false && "$BUILDKITE" = "true" ]; then | ||
GIT_SHA=${BUILDKITE_COMMIT:0:7} | ||
GIT_BRANCH=$BUILDKITE_BRANCH | ||
else | ||
GIT_SHA=$(git -C "$DOCKER_ROOT" rev-parse --short=7 HEAD) | ||
GIT_BRANCH=$(git -C "$DOCKER_ROOT" symbolic-ref --short HEAD) | ||
fi | ||
|
||
TAG_CLIENT_SHA="${PACKAGE_ORG}/${CLIENT_NAME}:${GIT_SHA}" | ||
TAG_CLIENT_BRANCH="${PACKAGE_ORG}/${CLIENT_NAME}:${GIT_BRANCH}" | ||
TAG_CLIENT_LATEST="${PACKAGE_ORG}/${CLIENT_NAME}:latest" | ||
|
||
TAG_SERVER_SHA="${PACKAGE_ORG}/${SERVER_NAME}:${GIT_SHA}" | ||
TAG_SERVER_BRANCH="${PACKAGE_ORG}/${SERVER_NAME}:${GIT_BRANCH}" | ||
TAG_SERVER_LATEST="${PACKAGE_ORG}/${SERVER_NAME}:latest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PasswordAuthentication no | ||
IdentityFile /privateer/keys/id_rsa | ||
SendEnv LANG LC_* | ||
HashKnownHosts no | ||
UserKnownHostsFile /privateer/keys/known_hosts | ||
Include /privateer/keys/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Include /etc/ssh/sshd_config.d/*.conf | ||
|
||
PermitRootLogin prohibit-password | ||
#StrictModes yes | ||
#MaxAuthTries 1 | ||
#MaxSessions 10 | ||
|
||
PubkeyAuthentication yes | ||
|
||
AuthorizedKeysFile /privateer/keys/authorized_keys | ||
HostKey /privateer/keys/id_rsa | ||
|
||
PasswordAuthentication no | ||
ChallengeResponseAuthentication no | ||
UsePAM no | ||
|
||
#AllowAgentForwarding yes | ||
#AllowTcpForwarding yes | ||
#GatewayPorts no | ||
X11Forwarding no | ||
# PermitTTY no | ||
PrintMotd no | ||
|
||
# Allow client to pass locale environment variables | ||
AcceptEnv LANG LC_* | ||
|
||
# override default of no subsystems | ||
# Subsystem sftp /usr/lib/openssh/sftp-server |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this going to replace privateer eventually?
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.
yeah, I'll do some sort of merge into that package source