Feature/script to generate conf files #54
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.
Creating a VPN for Rootski using Wireguard (Phase 1)
This PR explains how the configuration files for the wireguard VPN are created.
Scope
The three phases of this project will include:
The scope of this PR only covers phase 1.
Server Configuration File
In order to create a VPN, one must write the VPN's server configuration file which depends on a RSA key pair for
mlflow.rootski.io
,database.rootski.io
), andA wireguard server configuration file has one
[Interface]
section followed by any number of[Peer]
sections.The interface section needs to know the server's private key while a peer section needs to know the client's public key. We can also assign each peer a specific IP address on the VPN that is unique to them as
AllowedIPs
in the peer section.Here is an example of a server configuration file that needs to be on the machine hosting the Wireguard service.
Peer Configuration File
Then each client needs to create a client configuration file on their machine using their own private key and the server's public key.
Like the server's configuration file, the client configuration file will also include an
[Interface]
and[Peer]
section.The difference is the client's private key now goes in the
[Interface]
section while the server's public key is in the[Peer]
section.Here is an example of a peer configuration file using the Wireguard desktop client. Also notice that the peer section has a endpoint which is the VPN's public IP address or DNS name.
Problem addressed by this PR
The Wireguard VPN is a stateful system that depends on knowledge of several RSA key pairs. The server needs to know each client's public key and each client needs to know the server's public key.
If the server's key pair were to become compromised or lost, then we would need to
We wanted to create a solution that preserved the state of the system without having to contact rootski contributors if the system failed. This requires that the key pairs be accessible yet securely stored at the same time.
Solution
Our solution is to store the state of the system (the key pairs) in AWS Parameter Store. This way, we can use infrastructure as code to to create a Lightsail instance and an IAM user with permissions to access Parameter Store. We can then use the parameters to recreate lost configuration files if the Lightsail instance crashes.
We did this by first writing the file
wireguard_keygen_utils.py
. This file generates the wireguard key pairs and then wraps them in a dataclass with additional information about the associated IP address, key owner, and additional note. Here is an example of the server's VpnKeyPairDataNotice the note saying this key pair is reserved (for rootski services) and not for contributors. Key pairs meant for rootski contributors will have a note that says "null"
Did you notice I just exposed Eric's private key?!
Using this key pair data, we wrote another file (
store_keys_on_aws.py
) to store the key pairs on Parameter store. Observe each key pair almost has the same name except for the ending, which is the assigned ip-address.The last file created is
generate_server_conf.py
file. This file pulls the key pair data from Parameter Store and creates three file:wg0.conf
)server.key
)server.pub
)generate_server_conf.py
will be used in theinstall_wireguard.sh
where it will be concatenated locally on the AWS Lisghtsail instance and run there.