@@ -76,19 +76,181 @@ Note that this column will always be recorded if there were updated values in ot
76
76
77
77
## SSH Tunnel
78
78
79
- If your PostgreSQL source database is not accessible over the internet, you can specify SSH credentials to enable an SSH tunnel via a jump host.
79
+ ![ ] ( /img/new-source-db-ssh-arch.png )
80
+
81
+ If your PostgreSQL source database is not accessible over the internet, you can specify SSH credentials to enable an SSH tunnel via your public jump host:
80
82
81
83
![ dashboard] ( /img/new-source-db-ssh.png )
82
84
83
- Once the source database connection settings are submitted, we'll generate a public SSH key.
85
+ Once the source database connection settings are submitted, we'll generate a public SSH key:
86
+
87
+ ![ ] ( /img/new-source-db-ssh-key.png )
88
+
84
89
Add this public SSH key to your SSH host to allow Bemi workers to connect and SSH-tunnel to the PostgreSQL database:
85
90
86
91
``` sh
87
92
touch ~ /.ssh/authorized_keys && chmod 600 ~ /.ssh/authorized_keys
88
93
echo ' ssh-ed25519 AAAAC3Nz...' >> ~ /.ssh/authorized_keys
89
94
```
90
95
91
- If you need a public SSH Key before you know the SSH host address, just specify any address and later reach out to us to update it.
96
+ Note: if you need a public SSH Key before you know the SSH host address, just specify any address and later reach out to us to update it.
97
+
98
+ ## VPN Tunnel
99
+
100
+ If your PostgreSQL source database and SSH jump host can't be accessible over the internet, you can establish a secure VPN tunnel to our VPN server.
101
+
102
+ ![ ] ( /img/new-source-db-vpn-arch.png )
103
+
104
+ You need to provision a VPN node and configure VPN using [ WireGuard] ( https://www.wireguard.com/ ) that combines strong encryption with fast speeds:
105
+
106
+ ``` sh
107
+ # Install WireGuard
108
+ sudo apt update && sudo apt install -y resolvconf wireguard
109
+
110
+ # Generate a private and public keys
111
+ wg genkey | tee wg-privatekey | wg pubkey > wg-publickey
112
+
113
+ # Get your network interface name (e.g., ens5)
114
+ NETWORK_INTERFACE=$( ip route get 8.8.8.8 | grep 8.8.8.8 | awk ' {print $5}' )
115
+
116
+ # Reach out to us to get the VPN server public key and endpoint
117
+ BEMI_PUBLIC_KEY=
118
+ BEMI_ENDPOINT=
119
+
120
+ # Send us your public key and PostgreSQL private IP address
121
+ cat wg-publickey
122
+ dig your-prod-postgres.abcdef5ghij.us-west-1.rds.amazonaws.com A +short | tail -n 1
123
+
124
+ # Enable IP forwarding
125
+ echo " net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
126
+ sudo sysctl -p
127
+
128
+ # Create a WireGuard configuration file with the following content
129
+ cat << EOF > wg0.conf
130
+ [Interface]
131
+ PrivateKey = $( cat ./wg-privatekey)
132
+ Address = 10.0.0.1/24
133
+ PostUp = iptables -t nat -A POSTROUTING -o $NETWORK_INTERFACE -j MASQUERADE
134
+ PostDown = iptables -t nat -D POSTROUTING -o $NETWORK_INTERFACE -j MASQUERAD
135
+
136
+ [Peer]
137
+ PublicKey = $BEMI_PUBLIC_KEY
138
+ AllowedIPs = 10.0.0.2/32
139
+ Endpoint = $BEMI_ENDPOINT :51820
140
+ PersistentKeepalive = 25
141
+ EOF
142
+ sudo mv wg0.conf /etc/wireguard/wg0.conf
143
+
144
+ sudo systemctl
enable [email protected]
145
+ sudo systemctl start
[email protected]
146
+ systemctl status
[email protected]
147
+ ```
148
+
149
+ Once you have the WireGuard running, we'll be able to connect to your PostgreSQL database over the VPN tunnel.
150
+
151
+ Here is a Terraform snippet to run all the commands above on AWS:
152
+
153
+ ``` tf
154
+ locals {
155
+ # For example, Ubuntu 24.04 LTS - arm64
156
+ ami = "ami-..."
157
+ instance_type = "t4g.micro"
158
+
159
+ # Your private subnet ID
160
+ private_subnet_id = "subnet-..."
161
+
162
+ # Bemi VPN server information
163
+ bemi_public_key = "..."
164
+ bemi_endpoint = "..."
165
+
166
+ # Optionally if you want to SSH to the VPN node
167
+ ssh_key_name = "..."
168
+ ssh_cidr_blocks = [".../32"]
169
+ }
170
+
171
+ resource "aws_security_group" "bemi-vpn-node" {
172
+ name = "bemi-vpn-node"
173
+ description = "Security group for bemi-vpn-node"
174
+
175
+ ingress {
176
+ description = "SSH"
177
+ from_port = 22
178
+ to_port = 22
179
+ protocol = "tcp"
180
+ cidr_blocks = local.ssh_cidr_blocks
181
+ }
182
+
183
+ egress {
184
+ from_port = 0
185
+ to_port = 0
186
+ protocol = "-1"
187
+ cidr_blocks = ["0.0.0.0/0"]
188
+ ipv6_cidr_blocks = ["::/0"]
189
+ }
190
+
191
+ tags = {
192
+ Name = "bemi-vpn-node"
193
+ }
194
+ }
195
+
196
+ resource "aws_instance" "bemi-vpn-node" {
197
+ ami = local.ami
198
+ instance_type = local.instance_type
199
+ key_name = local.ssh_key_name
200
+ associate_public_ip_address = false
201
+ subnet_id = local.private_subnet_id
202
+ security_groups = [aws_security_group.bemi-vpn-node.id]
203
+
204
+ tags = {
205
+ Name = "bemi-vpn-node"
206
+ }
207
+
208
+ user_data = <<-EOF
209
+ #!/bin/bash
210
+
211
+ sudo apt update
212
+ sudo apt install -y resolvconf wireguard
213
+
214
+ cd /home/ubuntu
215
+ wg genkey | tee wg-privatekey | wg pubkey > wg-publickey
216
+
217
+ echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
218
+ sudo sysctl -p
219
+
220
+ cat << EOF_WG_CONF > wg0.conf
221
+ [Interface]
222
+ PrivateKey = $(cat ./wg-privatekey)
223
+ Address = 10.0.0.1/24
224
+ PostUp = iptables -t nat -A POSTROUTING -o ens5 -j MASQUERADE
225
+ PostDown = iptables -t nat -D POSTROUTING -o ens5 -j MASQUERAD
226
+
227
+ [Peer]
228
+ PublicKey = ${local.bemi_public_key}
229
+ AllowedIPs = 10.0.0.2/32
230
+ Endpoint = ${local.bemi_endpoint}:51820
231
+ PersistentKeepalive = 25
232
+ EOF_WG_CONF
233
+ sudo mv wg0.conf /etc/wireguard/wg0.conf
234
+
235
+ sudo systemctl enable [email protected]
236
+ sudo systemctl start [email protected]
237
+ EOF
238
+ }
239
+ ```
240
+
241
+ To check the WireGuard status, SSH to the VPN node and run:
242
+
243
+ ``` sh
244
+ # Check the WireGuard status
245
+ systemctl status
[email protected]
246
+ sudo wg show
247
+
248
+ # Check the WireGuard configuration file
249
+ sudo cat /etc/wireguard/wg0.conf
250
+
251
+ # Check your public WireGuard key and share it with us
252
+ cat ./wg-publickey
253
+ ```
92
254
93
255
## Bemi Static IPs
94
256
0 commit comments