Skip to content

Commit 7373499

Browse files
Kubernetes demo (#17)
Run the tool in a distributed manner in Kubernetes cluster.
1 parent 6ce6b61 commit 7373499

2 files changed

Lines changed: 107 additions & 3 deletions

File tree

README.md

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,71 @@ Each additional character increases search time by a factor of 64.
6161

6262
The tool supports blind search, i.e., when the worker does not know the private key. See [demo-blind.sh](demo-blind.sh).
6363

64+
## Kubernetes
65+
66+
You can run the tool in a distributed manner in Kubernetes cluster using the [demo-k8s.yaml](demo-k8s.yaml) manifest
67+
to search for a vanity key without exposing the private key:
68+
69+
```console
70+
$ # Generate secure starting key pair
71+
$ wg genkey | tee /dev/stderr | wg pubkey
72+
YI5+UcKmyLdeRDqU8l3k53wrUZO9Mw23NpvB8tDtvWU=
73+
startkQgqI9Gv1IX7eNa2qeFhpYBRDwpz40JIAAYOSk=
74+
75+
$ # Edit demo-k8s.yaml to configure prefix, starting public key, parallelism, and resource limits 💸
76+
77+
$ # Create search job
78+
$ kubectl apply -f demo-k8s.yaml
79+
job.batch/wvk created
80+
81+
$ # Check job
82+
$ kubectl get job wvk
83+
NAME STATUS COMPLETIONS DURATION AGE
84+
wvk Running 0/10 2m53s 2m53s
85+
86+
$ # Check pods
87+
$ kubectl get pods --selector=batch.kubernetes.io/job-name=wvk
88+
NAME READY STATUS RESTARTS AGE
89+
wvk-0-8tdz5 1/1 Running 0 3m8s
90+
wvk-1-pmnkn 1/1 Running 0 3m8s
91+
wvk-2-2ls7m 1/1 Running 0 3m8s
92+
wvk-3-rd7gx 1/1 Running 0 3m8s
93+
wvk-4-jqksz 1/1 Running 0 3m8s
94+
wvk-5-vj6gd 1/1 Running 0 3m8s
95+
wvk-6-vhgmc 1/1 Running 0 3m8s
96+
wvk-7-drr98 1/1 Running 0 3m8s
97+
wvk-8-tmb6c 1/1 Running 0 3m8s
98+
wvk-9-gxlp2 1/1 Running 0 3m8s
99+
100+
$ # Check resource usage
101+
$ kubectl top pods --selector=batch.kubernetes.io/job-name=wvk
102+
103+
$ # Wait for the job to complete
104+
$ kubectl wait --for=condition=complete job/wvk --timeout=1h
105+
job.batch/wvk condition met
106+
107+
$ # Job is complete
108+
$ kubectl get job wvk
109+
NAME STATUS COMPLETIONS DURATION AGE
110+
wvk Complete 1/999999 34m 37m
111+
112+
$ # Get found offset from the logs
113+
$ kubectl logs jobs/wvk
114+
7538451707115552752
115+
116+
$ # Generate new private vanity key by offsetting the starting private key
117+
$ echo YI5+UcKmyLdeRDqU8l3k53wrUZO9Mw23NpvB8tDtvWU= | wireguard-vanity-key add --offset=7538451707115552752 --prefix=wvk+k8s
118+
4I4EWan32HJbRDqU8l3k53wrUZO9Mw23NpvB8tDtvWU=
119+
120+
$ # Get the vanity public key
121+
$ echo 4I4EWan32HJbRDqU8l3k53wrUZO9Mw23NpvB8tDtvWU= | wg pubkey
122+
wvk+k8shgsJcW5EKet2AkViKc7a/0Ud8/EDOy91aCQg=
123+
124+
$ # Delete the job
125+
$ kubectl delete job wvk
126+
job.batch "wvk" deleted
127+
```
128+
64129
## Similar tools
65130

66131
* [wireguard-vanity-address](https://github.com/warner/wireguard-vanity-address)
@@ -91,8 +156,8 @@ Inspired by [wireguard-vanity-address "faster algorithm"](https://github.com/war
91156
instead of doing full scalar multiplication for each candidate, this tool applies a point increment technique that reduces the number of multiplications:
92157
```
93158
public_key0 = private_key0 × base_point
94-
public_key1 = (private_key0 + const_offset) × base_point
95-
= private_key0 × base_point + const_offset × base_point
159+
public_key1 = (private_key0 + const_offset) × base_point
160+
= private_key0 × base_point + const_offset × base_point
96161
= public_key0 + const_offset × base_point
97162
= public_key0 + const_point_offset
98163
```
@@ -119,7 +184,7 @@ Other tools encode the full public key to base64 and compare the prefix. This to
119184

120185
### 🏆 High-performance C implementation
121186

122-
For raw speed, the C worker (`wvk`) uses [awslabs/s2n-bignum](https://github.com/awslabs/s2n-bignum) -
187+
For raw speed, the C worker (`wvk`) uses [awslabs/s2n-bignum](https://github.com/awslabs/s2n-bignum) -
123188
a highly optimized field arithmetic library written in assembly.
124189
The worker supports prefix lengths up to 10 base64 characters, so the prefix check becomes a single masked integer comparison.
125190
These two optimizations make `wvk` ~2 times faster than the Go implementation.

demo-k8s.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: wvk
5+
annotations:
6+
kubernetes.io/description: |
7+
This Kubernetes Job configuration demonstrates how to run the
8+
[wireguard-vanity-key](https://github.com/AlexanderYastrebov/wireguard-vanity-key)
9+
tool in a distributed manner across multiple pods.
10+
spec:
11+
parallelism: 10 # 👈 Number of pods to run in parallel. See also resource limits below
12+
activeDeadlineSeconds: 3600 # Job must complete within 1 hour
13+
ttlSecondsAfterFinished: 86400 # Job will be deleted after 1 day
14+
# Indexed Job with successPolicy to complete the Job when at least one pod succeeds
15+
completionMode: Indexed
16+
completions: 999999
17+
successPolicy:
18+
rules:
19+
- succeededCount: 1
20+
template:
21+
spec:
22+
restartPolicy: Never
23+
terminationGracePeriodSeconds: 0
24+
containers:
25+
- name: wvk
26+
image: ghcr.io/alexanderyastrebov/wireguard-vanity-key:latest
27+
args:
28+
- --prefix
29+
- wvk+k8s # 👈 Vanity prefix to find
30+
- --public
31+
- startkQgqI9Gv1IX7eNa2qeFhpYBRDwpz40JIAAYOSk= # 👈 Starting public key, use your own ☣️
32+
- --output=offset
33+
resources:
34+
requests:
35+
cpu: 7 # 👈 Set pod size
36+
memory: 64Mi # The tool does not need much memory
37+
limits: # Set equal to requests
38+
cpu: 7
39+
memory: 64Mi

0 commit comments

Comments
 (0)