@highstate/wireguard 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-HWKQLLAH.js +255 -0
- package/dist/chunk-HWKQLLAH.js.map +1 -0
- package/dist/config/index.js +20 -24
- package/dist/config/index.js.map +1 -0
- package/dist/config-bundle/index.js +92 -0
- package/dist/config-bundle/index.js.map +1 -0
- package/dist/highstate.manifest.json +10 -0
- package/dist/identity/index.js +52 -29
- package/dist/identity/index.js.map +1 -0
- package/dist/network/index.js +9 -7
- package/dist/network/index.js.map +1 -0
- package/dist/node/index.js +101 -56
- package/dist/node/index.js.map +1 -0
- package/dist/peer/index.js +28 -12
- package/dist/peer/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/shared-D24icZbJ.js +0 -91
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// src/shared.ts
|
|
2
|
+
import { x25519 } from "@noble/curves/ed25519";
|
|
3
|
+
|
|
4
|
+
// ../../node_modules/@noble/hashes/esm/cryptoNode.js
|
|
5
|
+
import * as nc from "node:crypto";
|
|
6
|
+
var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
7
|
+
|
|
8
|
+
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
9
|
+
function randomBytes(bytesLength = 32) {
|
|
10
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
11
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
12
|
+
}
|
|
13
|
+
if (crypto && typeof crypto.randomBytes === "function") {
|
|
14
|
+
return crypto.randomBytes(bytesLength);
|
|
15
|
+
}
|
|
16
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ../../node_modules/remeda/dist/chunk-ANXBDSUI.js
|
|
20
|
+
var s = { done: false, hasNext: false };
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/remeda/dist/chunk-3GOCSNFN.js
|
|
23
|
+
function C(t, ...o) {
|
|
24
|
+
let n = t, u = o.map((e) => "lazy" in e ? y(e) : void 0), p = 0;
|
|
25
|
+
for (; p < o.length; ) {
|
|
26
|
+
if (u[p] === void 0 || !B(n)) {
|
|
27
|
+
let i2 = o[p];
|
|
28
|
+
n = i2(n), p += 1;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
let r = [];
|
|
32
|
+
for (let i2 = p; i2 < o.length; i2++) {
|
|
33
|
+
let l = u[i2];
|
|
34
|
+
if (l === void 0 || (r.push(l), l.isSingle)) break;
|
|
35
|
+
}
|
|
36
|
+
let a2 = [];
|
|
37
|
+
for (let i2 of n) if (f(i2, a2, r)) break;
|
|
38
|
+
let { isSingle: s2 } = r.at(-1);
|
|
39
|
+
n = s2 ? a2[0] : a2, p += r.length;
|
|
40
|
+
}
|
|
41
|
+
return n;
|
|
42
|
+
}
|
|
43
|
+
function f(t, o, n) {
|
|
44
|
+
if (n.length === 0) return o.push(t), false;
|
|
45
|
+
let u = t, p = s, e = false;
|
|
46
|
+
for (let [r, a2] of n.entries()) {
|
|
47
|
+
let { index: s2, items: i2 } = a2;
|
|
48
|
+
if (i2.push(u), p = a2(u, s2, i2), a2.index += 1, p.hasNext) {
|
|
49
|
+
if (p.hasMany ?? false) {
|
|
50
|
+
for (let l of p.next) if (f(l, o, n.slice(r + 1))) return true;
|
|
51
|
+
return e;
|
|
52
|
+
}
|
|
53
|
+
u = p.next;
|
|
54
|
+
}
|
|
55
|
+
if (!p.hasNext) break;
|
|
56
|
+
p.done && (e = true);
|
|
57
|
+
}
|
|
58
|
+
return p.hasNext && o.push(u), e;
|
|
59
|
+
}
|
|
60
|
+
function y(t) {
|
|
61
|
+
let { lazy: o, lazyArgs: n } = t, u = o(...n);
|
|
62
|
+
return Object.assign(u, { isSingle: o.single ?? false, index: 0, items: [] });
|
|
63
|
+
}
|
|
64
|
+
function B(t) {
|
|
65
|
+
return typeof t == "string" || typeof t == "object" && t !== null && Symbol.iterator in t;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ../../node_modules/remeda/dist/chunk-LFJW7BOT.js
|
|
69
|
+
function y2(t, i2) {
|
|
70
|
+
let a2 = i2.length - t.length;
|
|
71
|
+
if (a2 === 1) {
|
|
72
|
+
let [n, ...r] = i2;
|
|
73
|
+
return C(n, { lazy: t, lazyArgs: r });
|
|
74
|
+
}
|
|
75
|
+
if (a2 === 0) {
|
|
76
|
+
let n = { lazy: t, lazyArgs: i2 };
|
|
77
|
+
return Object.assign((e) => C(e, n), n);
|
|
78
|
+
}
|
|
79
|
+
throw new Error("Wrong number of arguments");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ../../node_modules/remeda/dist/chunk-QJLMYOTX.js
|
|
83
|
+
function i(...e) {
|
|
84
|
+
return y2(a, e);
|
|
85
|
+
}
|
|
86
|
+
function a() {
|
|
87
|
+
let e = /* @__PURE__ */ new Set();
|
|
88
|
+
return (t) => e.has(t) ? s : (e.add(t), { done: false, hasNext: true, next: t });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/shared.ts
|
|
92
|
+
function generateKey() {
|
|
93
|
+
const key = x25519.utils.randomPrivateKey();
|
|
94
|
+
return Buffer.from(key).toString("base64");
|
|
95
|
+
}
|
|
96
|
+
function convertPrivateKeyToPublicKey(privateKey) {
|
|
97
|
+
const key = Buffer.from(privateKey, "base64");
|
|
98
|
+
return Buffer.from(x25519.getPublicKey(key)).toString("base64");
|
|
99
|
+
}
|
|
100
|
+
function generatePresharedKey() {
|
|
101
|
+
const key = randomBytes(32);
|
|
102
|
+
return Buffer.from(key).toString("base64");
|
|
103
|
+
}
|
|
104
|
+
function combinePresharedKeyParts(part1, part2) {
|
|
105
|
+
const key1 = Buffer.from(part1, "base64");
|
|
106
|
+
const key2 = Buffer.from(part2, "base64");
|
|
107
|
+
const result = new Uint8Array(32);
|
|
108
|
+
for (let i2 = 0; i2 < 32; i2++) {
|
|
109
|
+
result[i2] = key1[i2] ^ key2[i2];
|
|
110
|
+
}
|
|
111
|
+
return Buffer.from(result).toString("base64");
|
|
112
|
+
}
|
|
113
|
+
function generatePeerConfig(identity, peer) {
|
|
114
|
+
const lines = [
|
|
115
|
+
//
|
|
116
|
+
"[Peer]",
|
|
117
|
+
`# ${peer.name}`,
|
|
118
|
+
`PublicKey = ${peer.publicKey}`
|
|
119
|
+
];
|
|
120
|
+
if (peer.allowedIps.length > 0) {
|
|
121
|
+
lines.push(`AllowedIPs = ${peer.allowedIps.join(", ")}`);
|
|
122
|
+
}
|
|
123
|
+
if (peer.endpoint) {
|
|
124
|
+
lines.push(`Endpoint = ${peer.endpoint}`);
|
|
125
|
+
}
|
|
126
|
+
if (identity.presharedKeyPart && peer.presharedKeyPart) {
|
|
127
|
+
const presharedKey = combinePresharedKeyParts(identity.presharedKeyPart, peer.presharedKeyPart);
|
|
128
|
+
lines.push(`PresharedKey = ${presharedKey}`);
|
|
129
|
+
} else if (identity.network?.globalPresharedKey) {
|
|
130
|
+
if (identity.network.globalPresharedKey !== peer.network?.globalPresharedKey) {
|
|
131
|
+
throw new Error("The global preshared key must be the same for all peers.");
|
|
132
|
+
}
|
|
133
|
+
lines.push(`PresharedKey = ${identity.network.globalPresharedKey}`);
|
|
134
|
+
}
|
|
135
|
+
return lines.join("\n");
|
|
136
|
+
}
|
|
137
|
+
function generateIdentityConfig({
|
|
138
|
+
identity,
|
|
139
|
+
peers,
|
|
140
|
+
listenPort,
|
|
141
|
+
dns,
|
|
142
|
+
postUp,
|
|
143
|
+
defaultInterface
|
|
144
|
+
}) {
|
|
145
|
+
const allDns = i(peers.flatMap((peer) => peer.dns ?? []).concat(dns ?? []));
|
|
146
|
+
const excludedIps = i(peers.flatMap((peer) => peer.excludedIps ?? []));
|
|
147
|
+
const lines = [
|
|
148
|
+
//
|
|
149
|
+
"[Interface]",
|
|
150
|
+
`# ${identity.name}`
|
|
151
|
+
];
|
|
152
|
+
if (identity.address) {
|
|
153
|
+
lines.push(`Address = ${identity.address}`);
|
|
154
|
+
}
|
|
155
|
+
lines.push(
|
|
156
|
+
//
|
|
157
|
+
`PrivateKey = ${identity.privateKey}`,
|
|
158
|
+
"MTU = 1280"
|
|
159
|
+
);
|
|
160
|
+
if (allDns.length > 0) {
|
|
161
|
+
lines.push(`DNS = ${allDns.join(", ")}`);
|
|
162
|
+
}
|
|
163
|
+
if (listenPort) {
|
|
164
|
+
lines.push(`ListenPort = ${listenPort}`);
|
|
165
|
+
}
|
|
166
|
+
if (postUp) {
|
|
167
|
+
lines.push();
|
|
168
|
+
for (const command of postUp) {
|
|
169
|
+
lines.push(`PostUp = ${command}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (defaultInterface) {
|
|
173
|
+
for (const excludedIp of excludedIps) {
|
|
174
|
+
lines.push(`PostUp = ip route add ${excludedIp} dev ${defaultInterface}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const otherPeers = peers.filter((peer) => peer.name !== identity.name);
|
|
178
|
+
for (const peer of otherPeers) {
|
|
179
|
+
lines.push("");
|
|
180
|
+
lines.push(generatePeerConfig(identity, peer));
|
|
181
|
+
}
|
|
182
|
+
return lines.join("\n");
|
|
183
|
+
}
|
|
184
|
+
function calculateAllowedIps({ address, allowedIps, exitNode }, network, k8sServices) {
|
|
185
|
+
const result = /* @__PURE__ */ new Set();
|
|
186
|
+
if (address) {
|
|
187
|
+
result.add(address);
|
|
188
|
+
}
|
|
189
|
+
if (allowedIps) {
|
|
190
|
+
for (const ip of allowedIps) {
|
|
191
|
+
result.add(ip);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (exitNode) {
|
|
195
|
+
result.add("0.0.0.0/0");
|
|
196
|
+
if (network?.ipv6) {
|
|
197
|
+
result.add("::/0");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (k8sServices) {
|
|
201
|
+
for (const service of k8sServices) {
|
|
202
|
+
if (service.spec.clusterIP) {
|
|
203
|
+
result.add(service.spec.clusterIP);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return Array.from(result);
|
|
208
|
+
}
|
|
209
|
+
function calculateExcludedIps({ excludedIps, excludePrivateIps }, network) {
|
|
210
|
+
const result = /* @__PURE__ */ new Set();
|
|
211
|
+
if (excludedIps) {
|
|
212
|
+
for (const ip of excludedIps) {
|
|
213
|
+
result.add(ip);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (excludePrivateIps) {
|
|
217
|
+
result.add("10.0.0.0/8");
|
|
218
|
+
result.add("172.16.0.0/12");
|
|
219
|
+
result.add("192.168.0.0/16");
|
|
220
|
+
if (network?.ipv6) {
|
|
221
|
+
result.add("fc00::/7");
|
|
222
|
+
result.add("fe80::/10");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return Array.from(result);
|
|
226
|
+
}
|
|
227
|
+
function calculateEndpoint({
|
|
228
|
+
externalIp,
|
|
229
|
+
listenPort,
|
|
230
|
+
endpoint
|
|
231
|
+
}) {
|
|
232
|
+
if (endpoint) {
|
|
233
|
+
return endpoint;
|
|
234
|
+
}
|
|
235
|
+
if (externalIp && listenPort) {
|
|
236
|
+
return `${externalIp}:${listenPort}`;
|
|
237
|
+
}
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
generateKey,
|
|
243
|
+
convertPrivateKeyToPublicKey,
|
|
244
|
+
generatePresharedKey,
|
|
245
|
+
generateIdentityConfig,
|
|
246
|
+
calculateAllowedIps,
|
|
247
|
+
calculateExcludedIps,
|
|
248
|
+
calculateEndpoint
|
|
249
|
+
};
|
|
250
|
+
/*! Bundled license information:
|
|
251
|
+
|
|
252
|
+
@noble/hashes/esm/utils.js:
|
|
253
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
254
|
+
*/
|
|
255
|
+
//# sourceMappingURL=chunk-HWKQLLAH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shared.ts","../../../node_modules/@noble/hashes/src/cryptoNode.ts","../../../node_modules/@noble/hashes/src/utils.ts","../../../node_modules/remeda/dist/chunk-ANXBDSUI.js","../../../node_modules/remeda/dist/chunk-3GOCSNFN.js","../../../node_modules/remeda/dist/chunk-LFJW7BOT.js","../../../node_modules/remeda/dist/chunk-QJLMYOTX.js"],"sourcesContent":["import type { k8s, wireguard } from \"@highstate/library\"\nimport { x25519 } from \"@noble/curves/ed25519\"\nimport { randomBytes } from \"@noble/hashes/utils\"\nimport { unique } from \"remeda\"\n\nexport function generateKey(): string {\n const key = x25519.utils.randomPrivateKey()\n\n return Buffer.from(key).toString(\"base64\")\n}\n\nexport function convertPrivateKeyToPublicKey(privateKey: string): string {\n const key = Buffer.from(privateKey, \"base64\")\n\n return Buffer.from(x25519.getPublicKey(key)).toString(\"base64\")\n}\n\nexport function generatePresharedKey(): string {\n const key = randomBytes(32)\n\n return Buffer.from(key).toString(\"base64\")\n}\n\nexport function combinePresharedKeyParts(part1: string, part2: string): string {\n const key1 = Buffer.from(part1, \"base64\")\n const key2 = Buffer.from(part2, \"base64\")\n const result = new Uint8Array(32)\n\n for (let i = 0; i < 32; i++) {\n result[i] = key1[i] ^ key2[i]\n }\n\n return Buffer.from(result).toString(\"base64\")\n}\n\nfunction generatePeerConfig(identity: wireguard.Identity, peer: wireguard.Peer): string {\n const lines = [\n //\n \"[Peer]\",\n `# ${peer.name}`,\n `PublicKey = ${peer.publicKey}`,\n ]\n\n if (peer.allowedIps.length > 0) {\n lines.push(`AllowedIPs = ${peer.allowedIps.join(\", \")}`)\n }\n\n if (peer.endpoint) {\n lines.push(`Endpoint = ${peer.endpoint}`)\n }\n\n if (identity.presharedKeyPart && peer.presharedKeyPart) {\n const presharedKey = combinePresharedKeyParts(identity.presharedKeyPart, peer.presharedKeyPart)\n\n lines.push(`PresharedKey = ${presharedKey}`)\n } else if (identity.network?.globalPresharedKey) {\n if (identity.network.globalPresharedKey !== peer.network?.globalPresharedKey) {\n throw new Error(\"The global preshared key must be the same for all peers.\")\n }\n\n lines.push(`PresharedKey = ${identity.network.globalPresharedKey}`)\n }\n\n return lines.join(\"\\n\")\n}\n\nexport type IdentityConfigArgs = {\n identity: wireguard.Identity\n peers: wireguard.Peer[]\n listenPort?: number\n dns?: string[]\n postUp?: string[]\n defaultInterface?: string\n}\n\nexport function generateIdentityConfig({\n identity,\n peers,\n listenPort,\n dns,\n postUp,\n defaultInterface,\n}: IdentityConfigArgs): string {\n const allDns = unique(peers.flatMap(peer => peer.dns ?? []).concat(dns ?? []))\n const excludedIps = unique(peers.flatMap(peer => peer.excludedIps ?? []))\n\n const lines = [\n //\n \"[Interface]\",\n `# ${identity.name}`,\n ]\n\n if (identity.address) {\n lines.push(`Address = ${identity.address}`)\n }\n\n lines.push(\n //\n `PrivateKey = ${identity.privateKey}`,\n \"MTU = 1280\",\n )\n\n if (allDns.length > 0) {\n lines.push(`DNS = ${allDns.join(\", \")}`)\n }\n\n if (listenPort) {\n lines.push(`ListenPort = ${listenPort}`)\n }\n\n if (postUp) {\n lines.push()\n for (const command of postUp) {\n lines.push(`PostUp = ${command}`)\n }\n }\n\n if (defaultInterface) {\n for (const excludedIp of excludedIps) {\n lines.push(`PostUp = ip route add ${excludedIp} dev ${defaultInterface}`)\n }\n }\n\n const otherPeers = peers.filter(peer => peer.name !== identity.name)\n\n for (const peer of otherPeers) {\n lines.push(\"\")\n lines.push(generatePeerConfig(identity, peer))\n }\n\n return lines.join(\"\\n\")\n}\n\ntype AllowedIpsArgs = {\n address?: string\n allowedIps?: string[]\n exitNode?: boolean\n}\n\nexport function calculateAllowedIps(\n { address, allowedIps, exitNode }: AllowedIpsArgs,\n network: wireguard.Network | undefined,\n k8sServices?: k8s.Service[],\n): string[] {\n const result = new Set<string>()\n\n if (address) {\n result.add(address)\n }\n\n if (allowedIps) {\n for (const ip of allowedIps) {\n result.add(ip)\n }\n }\n\n if (exitNode) {\n result.add(\"0.0.0.0/0\")\n\n if (network?.ipv6) {\n result.add(\"::/0\")\n }\n }\n\n if (k8sServices) {\n for (const service of k8sServices) {\n if (service.spec.clusterIP) {\n result.add(service.spec.clusterIP)\n }\n }\n }\n\n return Array.from(result)\n}\n\ntype ExcludedIpsArgs = {\n excludedIps?: string[]\n excludePrivateIps?: boolean\n}\n\nexport function calculateExcludedIps(\n { excludedIps, excludePrivateIps }: ExcludedIpsArgs,\n network: wireguard.Network | undefined,\n): string[] {\n const result = new Set<string>()\n\n if (excludedIps) {\n for (const ip of excludedIps) {\n result.add(ip)\n }\n }\n\n if (excludePrivateIps) {\n result.add(\"10.0.0.0/8\")\n result.add(\"172.16.0.0/12\")\n result.add(\"192.168.0.0/16\")\n\n if (network?.ipv6) {\n result.add(\"fc00::/7\")\n result.add(\"fe80::/10\")\n }\n }\n\n return Array.from(result)\n}\n\ntype EndpointArgs = {\n externalIp?: string\n listenPort?: number\n endpoint?: string\n}\n\nexport function calculateEndpoint({\n externalIp,\n listenPort,\n endpoint,\n}: EndpointArgs): string | undefined {\n if (endpoint) {\n return endpoint\n }\n\n if (externalIp && listenPort) {\n return `${externalIp}:${listenPort}`\n }\n\n return undefined\n}\n","/**\n * Internal webcrypto alias.\n * We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+.\n * Falls back to Node.js built-in crypto for Node.js <=v14.\n * See utils.ts for details.\n * @module\n */\n// @ts-ignore\nimport * as nc from 'node:crypto';\nexport const crypto: any =\n nc && typeof nc === 'object' && 'webcrypto' in nc\n ? (nc.webcrypto as any)\n : nc && typeof nc === 'object' && 'randomBytes' in nc\n ? nc\n : undefined;\n","/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\nimport { abytes } from './_assert.js';\n// export { isBytes } from './_assert.js';\n// We can't reuse isBytes from _assert, because somehow this causes huge perf issues\nexport function isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n// Cast array to different type\nexport function u8(arr: TypedArray): Uint8Array {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\nexport function u32(arr: TypedArray): Uint32Array {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n\n// Cast array to view\nexport function createView(arr: TypedArray): DataView {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word: number, shift: number): number {\n return (word << (32 - shift)) | (word >>> shift);\n}\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word: number, shift: number): number {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE: boolean = /* @__PURE__ */ (() =>\n new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n// The byte swap operation for uint32\nexport function byteSwap(word: number): number {\n return (\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff)\n );\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const byteSwapIfBE: (n: number) => number = isLE\n ? (n: number) => n\n : (n: number) => byteSwap(n);\n\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr: Uint32Array): void {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n}\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n/**\n * Convert byte array to hex string.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;\nfunction asciiToBase16(ch: number): number | undefined {\n if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n\n/**\n * Convert hex string to byte array.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async (): Promise<void> => {};\n\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(\n iters: number,\n tick: number,\n cb: (i: number) => void\n): Promise<void> {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols in both browsers and Node.js since v11\n// See https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\n\n/**\n * Convert JS string to byte array.\n * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error('utf8ToBytes expected string, got ' + typeof str);\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\n/** Accepted input of hash functions. Strings are converted to byte arrays. */\nexport type Input = Uint8Array | string;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/**\n * Copies several Uint8Arrays into one.\n */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\n/** For runtime check if class implements interface */\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('Options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\n/** Hash function */\nexport type CHash = ReturnType<typeof wrapConstructor>;\n/** Hash function with output */\nexport type CHashO = ReturnType<typeof wrapConstructorWithOpts>;\n/** XOF with output */\nexport type CHashXO = ReturnType<typeof wrapXOFConstructorWithOpts>;\n\n/** Wraps hash function, creating an interface on top of it */\nexport function wrapConstructor<T extends Hash<T>>(\n hashCons: () => Hash<T>\n): {\n (msg: Input): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(): Hash<T>;\n} {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts: T): Hash<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\nexport function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts: T): HashXOF<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return crypto.randomBytes(bytesLength);\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n","var e={done:!0,hasNext:!1},s={done:!1,hasNext:!1},a=()=>e,o=t=>({hasNext:!0,next:t,done:!1});export{s as a,a as b,o as c};\n","import{a as A}from\"./chunk-ANXBDSUI.js\";function C(t,...o){let n=t,u=o.map(e=>\"lazy\"in e?y(e):void 0),p=0;for(;p<o.length;){if(u[p]===void 0||!B(n)){let i=o[p];n=i(n),p+=1;continue}let r=[];for(let i=p;i<o.length;i++){let l=u[i];if(l===void 0||(r.push(l),l.isSingle))break}let a=[];for(let i of n)if(f(i,a,r))break;let{isSingle:s}=r.at(-1);n=s?a[0]:a,p+=r.length}return n}function f(t,o,n){if(n.length===0)return o.push(t),!1;let u=t,p=A,e=!1;for(let[r,a]of n.entries()){let{index:s,items:i}=a;if(i.push(u),p=a(u,s,i),a.index+=1,p.hasNext){if(p.hasMany??!1){for(let l of p.next)if(f(l,o,n.slice(r+1)))return!0;return e}u=p.next}if(!p.hasNext)break;p.done&&(e=!0)}return p.hasNext&&o.push(u),e}function y(t){let{lazy:o,lazyArgs:n}=t,u=o(...n);return Object.assign(u,{isSingle:o.single??!1,index:0,items:[]})}function B(t){return typeof t==\"string\"||typeof t==\"object\"&&t!==null&&Symbol.iterator in t}export{C as a};\n","import{a as o}from\"./chunk-3GOCSNFN.js\";function y(t,i){let a=i.length-t.length;if(a===1){let[n,...r]=i;return o(n,{lazy:t,lazyArgs:r})}if(a===0){let n={lazy:t,lazyArgs:i};return Object.assign(e=>o(e,n),n)}throw new Error(\"Wrong number of arguments\")}export{y as a};\n","import{a as r}from\"./chunk-LFJW7BOT.js\";import{a as n}from\"./chunk-ANXBDSUI.js\";function i(...e){return r(a,e)}function a(){let e=new Set;return t=>e.has(t)?n:(e.add(t),{done:!1,hasNext:!0,next:t})}export{i as a};\n"],"mappings":";AACA,SAAS,cAAc;;;ACOvB,YAAY,QAAQ;AACb,IAAM,SACX,MAAM,OAAO,OAAO,YAAY,eAAe,KACvC,eACJ,MAAM,OAAO,OAAO,YAAY,iBAAiB,KAC/C,KACA;;;ACyRF,SAAU,YAAY,cAAc,IAAE;AAC1C,MAAI,UAAU,OAAO,OAAO,oBAAoB,YAAY;AAC1D,WAAO,OAAO,gBAAgB,IAAI,WAAW,WAAW,CAAC;EAC3D;AAEA,MAAI,UAAU,OAAO,OAAO,gBAAgB,YAAY;AACtD,WAAO,OAAO,YAAY,WAAW;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1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import '@noble/curves/ed25519';
|
|
1
|
+
import {
|
|
2
|
+
generateIdentityConfig
|
|
3
|
+
} from "../chunk-HWKQLLAH.js";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const { inputs, outputs } = forUnit(wireguard.config);
|
|
21
|
-
const configContent = output(inputs).apply(({ identity, peers }) => {
|
|
22
|
-
return generateIdentityConfig(identity, peers);
|
|
5
|
+
// src/config/index.ts
|
|
6
|
+
import { wireguard } from "@highstate/library";
|
|
7
|
+
import { forUnit, toPromise } from "@highstate/pulumi";
|
|
8
|
+
import { text } from "@highstate/contract";
|
|
9
|
+
var { inputs, args, outputs } = forUnit(wireguard.config);
|
|
10
|
+
var { identity, peers } = await toPromise(inputs);
|
|
11
|
+
var configContent = generateIdentityConfig({
|
|
12
|
+
identity,
|
|
13
|
+
peers,
|
|
14
|
+
dns: args.dns,
|
|
15
|
+
defaultInterface: args.defaultInterface,
|
|
16
|
+
listenPort: args.listenPort ?? identity.listenPort
|
|
23
17
|
});
|
|
24
|
-
var
|
|
18
|
+
var config_default = outputs({
|
|
25
19
|
$pages: {
|
|
26
20
|
index: {
|
|
27
21
|
title: "WireGuard Configuration",
|
|
@@ -42,5 +36,7 @@ var index = outputs({
|
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
38
|
});
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
export {
|
|
40
|
+
config_default as default
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config/index.ts"],"sourcesContent":["import { wireguard } from \"@highstate/library\"\nimport { forUnit, toPromise } from \"@highstate/pulumi\"\nimport { text } from \"@highstate/contract\"\nimport { generateIdentityConfig } from \"../shared\"\n\nconst { inputs, args, outputs } = forUnit(wireguard.config)\n\nconst { identity, peers } = await toPromise(inputs)\n\nconst configContent = generateIdentityConfig({\n identity,\n peers,\n dns: args.dns,\n defaultInterface: args.defaultInterface,\n listenPort: args.listenPort ?? identity.listenPort,\n})\n\nexport default outputs({\n $pages: {\n index: {\n title: \"WireGuard Configuration\",\n content: [\n {\n type: \"markdown\",\n content: text`\n You can use this configuration to setup an external WireGuard device via \\`wg-quick\\` command.\n `,\n },\n {\n type: \"qr\",\n content: configContent,\n showContent: true,\n language: \"ini\",\n },\n ],\n },\n },\n})\n"],"mappings":";;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,YAAY;AAGrB,IAAM,EAAE,QAAQ,MAAM,QAAQ,IAAI,QAAQ,UAAU,MAAM;AAE1D,IAAM,EAAE,UAAU,MAAM,IAAI,MAAM,UAAU,MAAM;AAElD,IAAM,gBAAgB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,KAAK,KAAK;AAAA,EACV,kBAAkB,KAAK;AAAA,EACvB,YAAY,KAAK,cAAc,SAAS;AAC1C,CAAC;AAED,IAAO,iBAAQ,QAAQ;AAAA,EACrB,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,OAAO;AAAA,MACP,SAAS;AAAA,QACP;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA;AAAA;AAAA,QAGX;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,UACb,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateIdentityConfig
|
|
3
|
+
} from "../chunk-HWKQLLAH.js";
|
|
4
|
+
|
|
5
|
+
// src/config-bundle/index.ts
|
|
6
|
+
import { wireguard } from "@highstate/library";
|
|
7
|
+
import {
|
|
8
|
+
fileFromBuffer,
|
|
9
|
+
forUnit,
|
|
10
|
+
secret,
|
|
11
|
+
toPromise
|
|
12
|
+
} from "@highstate/pulumi";
|
|
13
|
+
import { text } from "@highstate/contract";
|
|
14
|
+
import ZipStream from "zip-stream";
|
|
15
|
+
var { name, inputs, args, outputs } = forUnit(wireguard.configBundle);
|
|
16
|
+
var { identity, peers, sharedPeers } = await toPromise(inputs);
|
|
17
|
+
var blocks = [];
|
|
18
|
+
var zipStream = new ZipStream();
|
|
19
|
+
for (const peer of peers) {
|
|
20
|
+
const configContent = generateIdentityConfig({
|
|
21
|
+
identity,
|
|
22
|
+
peers: [...sharedPeers, peer],
|
|
23
|
+
dns: args.dns,
|
|
24
|
+
defaultInterface: args.defaultInterface,
|
|
25
|
+
listenPort: args.listenPort ?? identity.listenPort
|
|
26
|
+
});
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
28
|
+
return zipStream.entry(
|
|
29
|
+
configContent,
|
|
30
|
+
{
|
|
31
|
+
name: `${peer.name}.conf`,
|
|
32
|
+
// to prevent zip-stream from using the current date, for reproducibility
|
|
33
|
+
date: /* @__PURE__ */ new Date(0)
|
|
34
|
+
},
|
|
35
|
+
(err) => {
|
|
36
|
+
if (err) {
|
|
37
|
+
reject(err);
|
|
38
|
+
} else {
|
|
39
|
+
resolve(null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
blocks.push(
|
|
45
|
+
{
|
|
46
|
+
type: "markdown",
|
|
47
|
+
content: `### ${peer.name}`
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "qr",
|
|
51
|
+
content: secret(configContent),
|
|
52
|
+
showContent: true,
|
|
53
|
+
language: "ini"
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
zipStream.finish();
|
|
58
|
+
var content = await new Promise((resolve, reject) => {
|
|
59
|
+
const buffers = [];
|
|
60
|
+
zipStream.on("data", (data) => buffers.push(data));
|
|
61
|
+
zipStream.on("error", (err) => reject(err));
|
|
62
|
+
zipStream.on("end", () => resolve(Buffer.concat(buffers)));
|
|
63
|
+
});
|
|
64
|
+
var zipFile = fileFromBuffer(`${name}.zip`, content, "application/zip", true);
|
|
65
|
+
var config_bundle_default = outputs({
|
|
66
|
+
$pages: {
|
|
67
|
+
index: {
|
|
68
|
+
title: "WireGuard Configuration Bundle",
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
type: "markdown",
|
|
72
|
+
content: text`
|
|
73
|
+
You can use the following configurations to setup an external WireGuard device via \`wg-quick\` command or
|
|
74
|
+
using the WireGuard app on your desktop or mobile device.
|
|
75
|
+
|
|
76
|
+
You can also bulk import all configurations from zip file using the WireGuard app.
|
|
77
|
+
`
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "file",
|
|
81
|
+
fileMeta: zipFile.meta
|
|
82
|
+
},
|
|
83
|
+
...blocks
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
$files: [zipFile]
|
|
88
|
+
});
|
|
89
|
+
export {
|
|
90
|
+
config_bundle_default as default
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config-bundle/index.ts"],"sourcesContent":["import { wireguard } from \"@highstate/library\"\nimport {\n fileFromBuffer,\n forUnit,\n secret,\n toPromise,\n type InstancePageBlock,\n} from \"@highstate/pulumi\"\nimport { text } from \"@highstate/contract\"\nimport ZipStream from \"zip-stream\"\nimport { generateIdentityConfig } from \"../shared\"\n\nconst { name, inputs, args, outputs } = forUnit(wireguard.configBundle)\n\nconst { identity, peers, sharedPeers } = await toPromise(inputs)\n\nconst blocks: InstancePageBlock[] = []\nconst zipStream = new ZipStream()\n\nfor (const peer of peers) {\n const configContent = generateIdentityConfig({\n identity,\n peers: [...sharedPeers, peer],\n dns: args.dns,\n defaultInterface: args.defaultInterface,\n listenPort: args.listenPort ?? identity.listenPort,\n })\n\n await new Promise((resolve, reject) => {\n return zipStream.entry(\n configContent,\n {\n name: `${peer.name}.conf`,\n\n // to prevent zip-stream from using the current date, for reproducibility\n date: new Date(0),\n },\n err => {\n if (err) {\n reject(err)\n } else {\n resolve(null)\n }\n },\n )\n })\n\n blocks.push(\n {\n type: \"markdown\",\n content: `### ${peer.name}`,\n },\n {\n type: \"qr\",\n content: secret(configContent),\n showContent: true,\n language: \"ini\",\n },\n )\n}\n\nzipStream.finish()\n\nconst content = await new Promise<Buffer>((resolve, reject) => {\n const buffers: Buffer[] = []\n\n zipStream.on(\"data\", data => buffers.push(data as Buffer))\n zipStream.on(\"error\", err => reject(err as Error))\n zipStream.on(\"end\", () => resolve(Buffer.concat(buffers)))\n})\n\nconst zipFile = fileFromBuffer(`${name}.zip`, content, \"application/zip\", true)\n\nexport default outputs({\n $pages: {\n index: {\n title: \"WireGuard Configuration Bundle\",\n content: [\n {\n type: \"markdown\",\n content: text`\n You can use the following configurations to setup an external WireGuard device via \\`wg-quick\\` command or\n using the WireGuard app on your desktop or mobile device.\n \n You can also bulk import all configurations from zip file using the WireGuard app.\n `,\n },\n {\n type: \"file\",\n fileMeta: zipFile.meta,\n },\n ...blocks,\n ],\n },\n },\n $files: [zipFile],\n})\n"],"mappings":";;;;;AAAA,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,YAAY;AACrB,OAAO,eAAe;AAGtB,IAAM,EAAE,MAAM,QAAQ,MAAM,QAAQ,IAAI,QAAQ,UAAU,YAAY;AAEtE,IAAM,EAAE,UAAU,OAAO,YAAY,IAAI,MAAM,UAAU,MAAM;AAE/D,IAAM,SAA8B,CAAC;AACrC,IAAM,YAAY,IAAI,UAAU;AAEhC,WAAW,QAAQ,OAAO;AACxB,QAAM,gBAAgB,uBAA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AA,UACE,MAAM;AAAA,UACN,UAAU,QAAQ;AAAA,QACpB;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,OAAO;AAClB,CAAC;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sourceHashes": {
|
|
3
|
+
"./dist/network/index.js": "3be6217a8a618a0ab026aa792f12d3ebdf97ad031bf7f8a2ccba3fbad838f5eb",
|
|
4
|
+
"./dist/identity/index.js": "b0be75155ac325d13ee6aa5a81761d0621b8b0aef5d1ffddbba2ea33b997b848",
|
|
5
|
+
"./dist/config/index.js": "2d5c6d18d33420d35bd587027951c045560c965e69892afa5ef8bf0d4662a347",
|
|
6
|
+
"./dist/config-bundle/index.js": "39f687f65e5bc77a48743c250d17207309eff2c34daa6227531e66e9148c4fac",
|
|
7
|
+
"./dist/node/index.js": "aef0e7fcda643d637266481ae99d88afae2896d72ba0edf0ad6a5cecc7c02786",
|
|
8
|
+
"./dist/peer/index.js": "9a463687e53c2e5cdef23ecaf799f90128c58c2d801f98da7d13c676a0095758"
|
|
9
|
+
}
|
|
10
|
+
}
|
package/dist/identity/index.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
calculateAllowedIps,
|
|
3
|
+
calculateEndpoint,
|
|
4
|
+
calculateExcludedIps,
|
|
5
|
+
convertPrivateKeyToPublicKey,
|
|
6
|
+
generateKey,
|
|
7
|
+
generatePresharedKey
|
|
8
|
+
} from "../chunk-HWKQLLAH.js";
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
// src/identity/index.ts
|
|
11
|
+
import { wireguard } from "@highstate/library";
|
|
12
|
+
import { forUnit, getOrCreateSecret, toPromise } from "@highstate/pulumi";
|
|
13
|
+
import { DnsRecord } from "@highstate/common";
|
|
14
|
+
var { name, args, inputs, secrets, outputs } = forUnit(wireguard.identity);
|
|
15
|
+
var privateKey = getOrCreateSecret(secrets, "privateKey", generateKey);
|
|
16
|
+
var presharedKeyPart = getOrCreateSecret(secrets, "presharedKeyPart", () => {
|
|
17
|
+
return inputs.network?.apply((network2) => {
|
|
18
|
+
return network2?.presharedKeyMode === "secure" ? generatePresharedKey() : void 0;
|
|
11
19
|
});
|
|
12
20
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
var { network, k8sServices } = await toPromise(inputs);
|
|
22
|
+
var allowedIps = calculateAllowedIps(args, network, k8sServices);
|
|
23
|
+
var excludedIps = calculateExcludedIps(args, network);
|
|
24
|
+
var endpoint = calculateEndpoint(args);
|
|
25
|
+
var publicKey = privateKey.apply(convertPrivateKeyToPublicKey);
|
|
26
|
+
if (args.fqdn && inputs.dnsProvider && args.externalIp) {
|
|
27
|
+
DnsRecord.create(args.fqdn, {
|
|
28
|
+
provider: inputs.dnsProvider,
|
|
29
|
+
type: "A",
|
|
30
|
+
value: args.externalIp
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
var isExitNode = allowedIps.includes("0.0.0.0/0") || allowedIps.includes("::/0");
|
|
34
|
+
var identity_default = outputs({
|
|
20
35
|
identity: {
|
|
21
36
|
name: args.peerName ?? name,
|
|
22
37
|
network: inputs.network,
|
|
@@ -24,10 +39,10 @@ var index = outputs({
|
|
|
24
39
|
privateKey,
|
|
25
40
|
presharedKeyPart,
|
|
26
41
|
k8sServices: inputs.k8sServices,
|
|
27
|
-
exitNode: args.exitNode ??
|
|
42
|
+
exitNode: args.exitNode ?? isExitNode,
|
|
28
43
|
listenPort: args.listenPort,
|
|
29
44
|
externalIp: args.externalIp,
|
|
30
|
-
endpoint
|
|
45
|
+
endpoint
|
|
31
46
|
},
|
|
32
47
|
peer: {
|
|
33
48
|
name: args.peerName ?? name,
|
|
@@ -35,20 +50,28 @@ var index = outputs({
|
|
|
35
50
|
address: args.address,
|
|
36
51
|
publicKey,
|
|
37
52
|
allowedIps,
|
|
38
|
-
|
|
53
|
+
excludedIps,
|
|
54
|
+
endpoint,
|
|
55
|
+
dns: args.dns,
|
|
39
56
|
presharedKeyPart
|
|
40
57
|
},
|
|
41
58
|
$status: {
|
|
42
59
|
publicKey,
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
endpoint: {
|
|
61
|
+
value: endpoint,
|
|
62
|
+
complementaryTo: "endpoint"
|
|
63
|
+
},
|
|
64
|
+
allowedIps: {
|
|
65
|
+
value: allowedIps.join(", "),
|
|
66
|
+
complementaryTo: "allowedIps"
|
|
67
|
+
},
|
|
68
|
+
excludedIps: {
|
|
69
|
+
value: excludedIps.join(", "),
|
|
70
|
+
complementaryTo: "excludedIps"
|
|
71
|
+
}
|
|
45
72
|
}
|
|
46
73
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { index as default };
|
|
74
|
+
export {
|
|
75
|
+
identity_default as default
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/identity/index.ts"],"sourcesContent":["import { wireguard } from \"@highstate/library\"\nimport { forUnit, getOrCreateSecret, toPromise } from \"@highstate/pulumi\"\nimport { DnsRecord } from \"@highstate/common\"\nimport {\n calculateAllowedIps,\n calculateEndpoint,\n calculateExcludedIps,\n convertPrivateKeyToPublicKey,\n generateKey,\n generatePresharedKey,\n} from \"../shared\"\n\nconst { name, args, inputs, secrets, outputs } = forUnit(wireguard.identity)\n\nconst privateKey = getOrCreateSecret(secrets, \"privateKey\", generateKey)\n\nconst presharedKeyPart = getOrCreateSecret(secrets, \"presharedKeyPart\", () => {\n return inputs.network?.apply(network => {\n return network?.presharedKeyMode === \"secure\" ? generatePresharedKey() : undefined\n })\n})\n\nconst { network, k8sServices } = await toPromise(inputs)\n\nconst allowedIps = calculateAllowedIps(args, network, k8sServices)\nconst excludedIps = calculateExcludedIps(args, network)\nconst endpoint = calculateEndpoint(args)\n\nconst publicKey = privateKey.apply(convertPrivateKeyToPublicKey)\n\nif (args.fqdn && inputs.dnsProvider && args.externalIp) {\n DnsRecord.create(args.fqdn, {\n provider: inputs.dnsProvider,\n type: \"A\",\n value: args.externalIp,\n })\n}\n\nconst isExitNode = allowedIps.includes(\"0.0.0.0/0\") || allowedIps.includes(\"::/0\")\n\nexport default outputs({\n identity: {\n name: args.peerName ?? name,\n network: inputs.network,\n address: args.address,\n privateKey,\n presharedKeyPart,\n k8sServices: inputs.k8sServices,\n exitNode: args.exitNode ?? isExitNode,\n listenPort: args.listenPort,\n externalIp: args.externalIp,\n endpoint,\n },\n peer: {\n name: args.peerName ?? name,\n network: inputs.network,\n address: args.address,\n publicKey,\n allowedIps,\n excludedIps,\n endpoint,\n dns: args.dns,\n presharedKeyPart,\n },\n $status: {\n publicKey,\n endpoint: {\n value: endpoint,\n complementaryTo: \"endpoint\",\n },\n allowedIps: {\n value: allowedIps.join(\", \"),\n complementaryTo: \"allowedIps\",\n },\n excludedIps: {\n value: excludedIps.join(\", \"),\n complementaryTo: \"excludedIps\",\n },\n },\n})\n"],"mappings":";;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,mBAAmB,iBAAiB;AACtD,SAAS,iBAAiB;AAU1B,IAAM,EAAE,MAAM,MAAM,QAAQ,SAAS,QAAQ,IAAI,QAAQ,UAAU,QAAQ;AAE3E,IAAM,aAAa,kBAAkB,SAAS,cAAc,WAAW;AAEvE,IAAM,mBAAmB,kBAAkB,SAAS,oBAAoB,MAAM;AAC5E,SAAO,OAAO,SAAS,MAAM,CAAAA,aAAW;AACtC,WAAOA,UAAS,qBAAqB,WAAW,qBAAqB,IAAI;AAAA,EAC3E,CAAC;AACH,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15 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
1
|
+
// src/network/index.ts
|
|
2
|
+
import { wireguard } from "@highstate/library";
|
|
3
|
+
import { forUnit } from "@highstate/pulumi";
|
|
4
|
+
var { args, secrets, outputs } = forUnit(wireguard.network);
|
|
5
|
+
var network_default = outputs({
|
|
6
6
|
network: {
|
|
7
7
|
backend: args.backend ?? "wireguard",
|
|
8
8
|
presharedKeyMode: args.presharedKeyMode ?? "none",
|
|
9
9
|
globalPresharedKey: secrets.globalPresharedKey
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export {
|
|
13
|
+
network_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/network/index.ts"],"sourcesContent":["import { wireguard } from \"@highstate/library\"\nimport { forUnit } from \"@highstate/pulumi\"\n\nconst { args, secrets, outputs } = forUnit(wireguard.network)\n\nexport default outputs({\n network: {\n backend: args.backend ?? \"wireguard\",\n presharedKeyMode: args.presharedKeyMode ?? \"none\",\n globalPresharedKey: secrets.globalPresharedKey,\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAExB,IAAM,EAAE,MAAM,SAAS,QAAQ,IAAI,QAAQ,UAAU,OAAO;AAE5D,IAAO,kBAAQ,QAAQ;AAAA,EACrB,SAAS;AAAA,IACP,SAAS,KAAK,WAAW;AAAA,IACzB,kBAAkB,KAAK,oBAAoB;AAAA,IAC3C,oBAAoB,QAAQ;AAAA,EAC9B;AACF,CAAC;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { core } from '@pulumi/kubernetes';
|
|
5
|
-
import { b as generateIdentityConfig } from '../shared-D24icZbJ.js';
|
|
6
|
-
import '@noble/curves/ed25519';
|
|
1
|
+
import {
|
|
2
|
+
generateIdentityConfig
|
|
3
|
+
} from "../chunk-HWKQLLAH.js";
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
// src/node/index.ts
|
|
6
|
+
import {
|
|
7
|
+
createNamespace,
|
|
8
|
+
createProvider,
|
|
9
|
+
Deployment,
|
|
10
|
+
getAppDisplayName,
|
|
11
|
+
getAppName,
|
|
12
|
+
getNamespace,
|
|
13
|
+
mapMetadata,
|
|
14
|
+
NetworkPolicy,
|
|
15
|
+
StatefulSet
|
|
16
|
+
} from "@highstate/k8s";
|
|
17
|
+
import { wireguard } from "@highstate/library";
|
|
18
|
+
import { forUnit, toPromise } from "@highstate/pulumi";
|
|
19
|
+
import { core } from "@pulumi/kubernetes";
|
|
20
|
+
import { deepmerge } from "deepmerge-ts";
|
|
21
|
+
var { name, args, inputs, outputs } = forUnit(wireguard.node);
|
|
22
|
+
var { identity, peers } = await toPromise(inputs);
|
|
23
|
+
var identityName = (identity.name ?? name).replaceAll(".", "-");
|
|
24
|
+
var appName = args.appName ?? `wg-${identityName}`;
|
|
25
|
+
var serviceType = args.serviceType ?? "ClusterIP";
|
|
26
|
+
var provider = await createProvider(inputs.k8sCluster);
|
|
27
|
+
var existingNamespace = await toPromise(
|
|
28
|
+
inputs.deployment?.metadata?.namespace ?? inputs.statefulSet?.metadata?.namespace ?? inputs.interface?.deployment.metadata.namespace
|
|
16
29
|
);
|
|
17
|
-
|
|
30
|
+
var namespace = existingNamespace ? getNamespace(existingNamespace, provider) : createNamespace(appName, provider);
|
|
18
31
|
new core.v1.NamespacePatch(
|
|
19
32
|
"allow-privileged",
|
|
20
33
|
{
|
|
@@ -27,56 +40,82 @@ new core.v1.NamespacePatch(
|
|
|
27
40
|
},
|
|
28
41
|
{ provider }
|
|
29
42
|
);
|
|
30
|
-
|
|
43
|
+
var listenPort = identity.listenPort ?? args.listenPort;
|
|
44
|
+
var externalIp = identity.externalIp ?? args.externalIp;
|
|
45
|
+
var downstreamInterface = await toPromise(inputs.interface);
|
|
46
|
+
var postUp = [
|
|
47
|
+
// enable masquerading for all traffic going out of the WireGuard node
|
|
48
|
+
// TODO: consider adding more specific and restrictive rules
|
|
49
|
+
"iptables -t nat -A POSTROUTING -j MASQUERADE"
|
|
50
|
+
];
|
|
51
|
+
if (downstreamInterface) {
|
|
52
|
+
postUp.push(
|
|
53
|
+
`iptables -t mangle -A PREROUTING -i ${downstreamInterface.name} -j MARK --set-mark 0x1`
|
|
54
|
+
);
|
|
55
|
+
postUp.push("ip rule del not from all fwmark 0xca6c lookup 51820");
|
|
56
|
+
postUp.push("ip rule add from all fwmark 0x1 lookup 51820");
|
|
57
|
+
}
|
|
58
|
+
var interfaceName = identityName.substring(0, 15);
|
|
59
|
+
var configSecret = new core.v1.Secret(
|
|
31
60
|
appName,
|
|
32
61
|
{
|
|
33
62
|
metadata: mapMetadata({ name: appName, namespace }),
|
|
34
63
|
stringData: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
64
|
+
[`${interfaceName}.conf`]: generateIdentityConfig({
|
|
65
|
+
identity,
|
|
66
|
+
peers,
|
|
67
|
+
listenPort,
|
|
68
|
+
dns: args.dns,
|
|
69
|
+
postUp,
|
|
70
|
+
defaultInterface: "eth0"
|
|
39
71
|
})
|
|
40
72
|
}
|
|
41
73
|
},
|
|
42
74
|
{ provider }
|
|
43
75
|
);
|
|
44
|
-
|
|
76
|
+
var workloadOptions = {
|
|
45
77
|
namespace,
|
|
46
78
|
cluster: inputs.k8sCluster,
|
|
47
|
-
container:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
container: deepmerge(
|
|
80
|
+
{
|
|
81
|
+
image: "linuxserver/wireguard:latest",
|
|
82
|
+
environment: {
|
|
83
|
+
PUID: "1000",
|
|
84
|
+
PGID: "1000",
|
|
85
|
+
TZ: "Etc/UTC"
|
|
86
|
+
},
|
|
87
|
+
securityContext: {
|
|
88
|
+
capabilities: {
|
|
89
|
+
add: ["NET_ADMIN"]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
port: identity.endpoint && listenPort ? { containerPort: listenPort, protocol: "UDP" } : void 0,
|
|
93
|
+
volumeMount: {
|
|
94
|
+
volume: configSecret,
|
|
95
|
+
mountPath: "/config/wg_confs"
|
|
57
96
|
}
|
|
58
97
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
mountPath: "/config/wg_confs"
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
service: {
|
|
98
|
+
args.containerSpec ?? {}
|
|
99
|
+
),
|
|
100
|
+
service: identity.endpoint && listenPort ? {
|
|
66
101
|
type: serviceType,
|
|
67
|
-
externalIPs:
|
|
68
|
-
port:
|
|
69
|
-
port:
|
|
102
|
+
externalIPs: externalIp ? [externalIp] : void 0,
|
|
103
|
+
port: {
|
|
104
|
+
port: listenPort,
|
|
70
105
|
protocol: "UDP",
|
|
71
|
-
nodePort:
|
|
72
|
-
}
|
|
73
|
-
}
|
|
106
|
+
nodePort: serviceType !== "ClusterIP" ? listenPort : void 0
|
|
107
|
+
}
|
|
108
|
+
} : void 0
|
|
74
109
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
110
|
+
var deployment = !inputs.statefulSet ? Deployment.create(
|
|
111
|
+
appName,
|
|
112
|
+
{ ...workloadOptions, patch: inputs.deployment ?? inputs.interface?.deployment },
|
|
113
|
+
{ provider }
|
|
114
|
+
) : void 0;
|
|
115
|
+
var statefulSet = inputs.statefulSet ? StatefulSet.create(appName, { ...workloadOptions, patch: inputs.statefulSet }, { provider }) : void 0;
|
|
116
|
+
var selector = deployment?.spec.selector ?? statefulSet?.spec.selector;
|
|
117
|
+
var service = deployment?.optionalService ?? statefulSet?.optionalService;
|
|
118
|
+
if (externalIp && listenPort) {
|
|
80
119
|
NetworkPolicy.create(
|
|
81
120
|
"allow-wireguard-ingress",
|
|
82
121
|
{
|
|
@@ -86,7 +125,7 @@ if (identity.listenPort) {
|
|
|
86
125
|
description: "Allow encapsulated WireGuard traffic to the node from anywhere.",
|
|
87
126
|
ingressRule: {
|
|
88
127
|
fromAll: true,
|
|
89
|
-
toPort: { port:
|
|
128
|
+
toPort: { port: listenPort, protocol: "UDP" }
|
|
90
129
|
}
|
|
91
130
|
},
|
|
92
131
|
{ provider }
|
|
@@ -143,7 +182,6 @@ for (const service2 of identity.k8sServices) {
|
|
|
143
182
|
{ provider }
|
|
144
183
|
);
|
|
145
184
|
}
|
|
146
|
-
const peers = await toPromise(inputs.peers);
|
|
147
185
|
for (const peer of peers) {
|
|
148
186
|
if (!peer.endpoint) {
|
|
149
187
|
continue;
|
|
@@ -158,15 +196,22 @@ for (const peer of peers) {
|
|
|
158
196
|
description: `Allow egress traffic from the WireGuard node to the endpoint of the peer "${peer.name}".`,
|
|
159
197
|
egressRule: {
|
|
160
198
|
toEndpoint: endpoint,
|
|
161
|
-
toPort: { port: port ? parseInt(port) :
|
|
199
|
+
toPort: { port: port ? parseInt(port) : 51820, protocol: "UDP" }
|
|
162
200
|
}
|
|
163
201
|
},
|
|
164
202
|
{ provider }
|
|
165
203
|
);
|
|
166
204
|
}
|
|
167
|
-
var
|
|
205
|
+
var node_default = outputs({
|
|
168
206
|
deployment: deployment?.entity,
|
|
169
|
-
|
|
207
|
+
interface: {
|
|
208
|
+
name: interfaceName,
|
|
209
|
+
deployment: deployment?.entity
|
|
210
|
+
},
|
|
211
|
+
service: service?.apply((service2) => service2?.entity),
|
|
212
|
+
$terminals: [deployment?.terminal]
|
|
170
213
|
});
|
|
171
|
-
|
|
172
|
-
|
|
214
|
+
export {
|
|
215
|
+
node_default as default
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/node/index.ts"],"sourcesContent":["import {\n createNamespace,\n createProvider,\n Deployment,\n getAppDisplayName,\n getAppName,\n getNamespace,\n mapMetadata,\n NetworkPolicy,\n StatefulSet,\n type DeploymentArgs,\n type StatefulSetArgs,\n} from \"@highstate/k8s\"\nimport { wireguard } from \"@highstate/library\"\nimport { forUnit, toPromise } from \"@highstate/pulumi\"\nimport { core } from \"@pulumi/kubernetes\"\nimport { deepmerge } from \"deepmerge-ts\"\nimport { generateIdentityConfig } from \"../shared\"\n\nconst { name, args, inputs, outputs } = forUnit(wireguard.node)\n\nconst { identity, peers } = await toPromise(inputs)\n\nconst identityName = (identity.name ?? name).replaceAll(\".\", \"-\")\nconst appName = args.appName ?? `wg-${identityName}`\nconst serviceType = args.serviceType ?? \"ClusterIP\"\n\nconst provider = await createProvider(inputs.k8sCluster)\n\nconst existingNamespace = await toPromise(\n inputs.deployment?.metadata?.namespace ??\n inputs.statefulSet?.metadata?.namespace ??\n inputs.interface?.deployment.metadata.namespace,\n)\n\nconst namespace = existingNamespace\n ? getNamespace(existingNamespace, provider)\n : createNamespace(appName, provider)\n\nnew core.v1.NamespacePatch(\n \"allow-privileged\",\n {\n metadata: {\n name: namespace.metadata.name,\n labels: {\n \"pod-security.kubernetes.io/enforce\": \"privileged\",\n },\n },\n },\n { provider },\n)\n\nconst listenPort = identity.listenPort ?? args.listenPort\nconst externalIp = identity.externalIp ?? args.externalIp\n\nconst downstreamInterface = await toPromise(inputs.interface)\n\nconst postUp: string[] = [\n // enable masquerading for all traffic going out of the WireGuard node\n // TODO: consider adding more specific and restrictive rules\n \"iptables -t nat -A POSTROUTING -j MASQUERADE\",\n]\n\nif (downstreamInterface) {\n // mark all downstream traffic with 0x1\n postUp.push(\n `iptables -t mangle -A PREROUTING -i ${downstreamInterface.name} -j MARK --set-mark 0x1`,\n )\n\n // remove the default rule to route all non-encapsulated traffic to upstream wireguard interface\n postUp.push(\"ip rule del not from all fwmark 0xca6c lookup 51820\")\n\n // add a rule to route all downstream traffic to the upstream wireguard interface\n postUp.push(\"ip rule add from all fwmark 0x1 lookup 51820\")\n}\n\nconst interfaceName = identityName.substring(0, 15) // linux kernel limit\n\nconst configSecret = new core.v1.Secret(\n appName,\n {\n metadata: mapMetadata({ name: appName, namespace }),\n stringData: {\n [`${interfaceName}.conf`]: generateIdentityConfig({\n identity,\n peers,\n listenPort,\n dns: args.dns,\n postUp,\n defaultInterface: \"eth0\",\n }),\n },\n },\n { provider },\n)\n\nconst workloadOptions: DeploymentArgs & StatefulSetArgs = {\n namespace,\n cluster: inputs.k8sCluster,\n\n container: deepmerge(\n {\n image: \"linuxserver/wireguard:latest\",\n\n environment: {\n PUID: \"1000\",\n PGID: \"1000\",\n TZ: \"Etc/UTC\",\n },\n\n securityContext: {\n capabilities: {\n add: [\"NET_ADMIN\"],\n },\n },\n\n port:\n identity.endpoint && listenPort\n ? { containerPort: listenPort, protocol: \"UDP\" }\n : undefined,\n\n volumeMount: {\n volume: configSecret,\n mountPath: \"/config/wg_confs\",\n },\n },\n args.containerSpec ?? {},\n ),\n\n service:\n identity.endpoint && listenPort\n ? {\n type: serviceType,\n externalIPs: externalIp ? [externalIp] : undefined,\n\n port: {\n port: listenPort,\n protocol: \"UDP\",\n nodePort: serviceType !== \"ClusterIP\" ? listenPort : undefined,\n },\n }\n : undefined,\n}\n\nconst deployment = !inputs.statefulSet\n ? Deployment.create(\n appName,\n { ...workloadOptions, patch: inputs.deployment ?? inputs.interface?.deployment },\n { provider },\n )\n : undefined\n\nconst statefulSet = inputs.statefulSet\n ? StatefulSet.create(appName, { ...workloadOptions, patch: inputs.statefulSet }, { provider })\n : undefined\n\nconst selector = deployment?.spec.selector ?? statefulSet?.spec.selector\nconst service = deployment?.optionalService ?? statefulSet?.optionalService\n\nif (externalIp && listenPort) {\n NetworkPolicy.create(\n \"allow-wireguard-ingress\",\n {\n cni: inputs.k8sCluster.info.cni,\n namespace,\n selector,\n\n description: \"Allow encapsulated WireGuard traffic to the node from anywhere.\",\n\n ingressRule: {\n fromAll: true,\n toPort: { port: listenPort, protocol: \"UDP\" },\n },\n },\n { provider },\n )\n}\n\nif (identity.exitNode) {\n NetworkPolicy.create(\n \"allow-all-egress\",\n {\n cni: inputs.k8sCluster.info.cni,\n namespace,\n selector,\n\n description: \"Allow all egress traffic from the WireGuard node.\",\n\n egressRule: {\n toAll: true,\n },\n },\n { provider },\n )\n}\n\nfor (const service of identity.k8sServices) {\n const displayName = getAppDisplayName(service.metadata)\n\n NetworkPolicy.create(\n `allow-egress-to-${getAppName(service.metadata)}`,\n {\n cni: inputs.k8sCluster.info.cni,\n namespace,\n selector,\n\n description: `Allow egress traffic from the WireGuard node to the service \"${displayName}\".`,\n\n egressRules: [\n {\n toNamespace: service.metadata.namespace,\n toSelector: service.spec.selector,\n },\n\n // for compatibility with Cilium which cannot correctly detect the destination endpoint when the packet is redirected by the WireGuard node\n ...(service.spec.clusterIP ? [{ toCidr: `${service.spec.clusterIP}/32` }] : []),\n ],\n },\n { provider },\n )\n\n NetworkPolicy.create(\n `allow-ingress-to-${getAppName(service.metadata)}`,\n {\n name: `allow-ingress-from-${appName}`,\n\n cni: inputs.k8sCluster.info.cni,\n namespace: service.metadata.namespace,\n selector: service.spec.selector,\n\n description: `Allow ingress traffic from the WireGuard node \"${appName}\" to the service \"${displayName}\".`,\n\n ingressRule: {\n fromNamespace: namespace,\n fromSelector: selector,\n },\n },\n { provider },\n )\n}\n\nfor (const peer of peers) {\n if (!peer.endpoint) {\n continue\n }\n\n const [endpoint, port] = peer.endpoint.split(\":\")\n\n NetworkPolicy.create(\n `allow-egress-to-peer-${peer.name}`,\n {\n cni: inputs.k8sCluster.info.cni,\n namespace,\n selector,\n\n description: `Allow egress traffic from the WireGuard node to the endpoint of the peer \"${peer.name}\".`,\n\n egressRule: {\n toEndpoint: endpoint,\n toPort: { port: port ? parseInt(port) : 51820, protocol: \"UDP\" },\n },\n },\n { provider },\n )\n}\n\nexport default outputs({\n deployment: deployment?.entity,\n interface: {\n name: interfaceName,\n deployment: deployment?.entity,\n },\n service: service?.apply(service => service?.entity),\n $terminals: [deployment?.terminal],\n})\n"],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAG1B,IAAM,EAAE,MAAM,MAAM,QAAQ,QAAQ,IAAI,QAAQ,UAAU,IAAI;AAE9D,IAAM,EAAE,UAAU,MAAM,IAAI,MAAM,UAAU,MAAM;AAElD,IAAM,gBAAgB,SAAS,QAAQ,MAAM,WAAW,KAAK,GAAG;AAChE,IAAM,UAAU,KAAK,WAAW,MAAM,YAAY;AAClD,IAAM,cAAc,KAAK,eAAe;AAExC,IAAM,WAAW,MAAM,eAAe,OAAO,UAAU;AAEvD,IAAM,oBAAoB,MAAM;AAAA,EAC9B,OAAO,YAAY,UAAU,aAC3B,OAAO,aAAa,UAAU,aAC9B,OAAO,WAAW,WAAW,SAAS;AAC1C;AAEA,IAAM,YAAY,oBACd,aAAa,mBAAmB,QAAQ,IACxC,gBAAgB,SAAS,QAAQ;AAErC,IAAI,KAAK,GAAG;AAAA,EACV;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM,UAAU,SAAS;AAAA,MACzB,QAAQ;AAAA,QACN,sCAAsC;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA,EACA,EAAE,SAAS;AACb;AAEA,IAAM,aAAa,SAAS,cAAc,KAAK;AAC/C,IAAM,aAAa,SAAS,cAAc,KAAK;AAE/C,IAAM,sBAAsB,MAAM,UAAU,OAAO,SAAS;AAE5D,IAAM,SAAmB;AAAA;AAAA;AAA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js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
calculateAllowedIps,
|
|
3
|
+
calculateExcludedIps
|
|
4
|
+
} from "../chunk-HWKQLLAH.js";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
6
|
+
// src/peer/index.ts
|
|
7
|
+
import { wireguard } from "@highstate/library";
|
|
8
|
+
import { forUnit, toPromise } from "@highstate/pulumi";
|
|
9
|
+
var { name, args, inputs, outputs } = forUnit(wireguard.peer);
|
|
10
|
+
var network = await toPromise(inputs.network);
|
|
11
|
+
var allowedIps = calculateAllowedIps(args, network);
|
|
12
|
+
var excludedIps = calculateExcludedIps(args, network);
|
|
13
|
+
var peer_default = outputs({
|
|
9
14
|
peer: {
|
|
10
15
|
name: args.peerName ?? name,
|
|
11
16
|
network: inputs.network,
|
|
12
17
|
address: args.address,
|
|
13
18
|
publicKey: args.publicKey,
|
|
14
|
-
allowedIps
|
|
15
|
-
endpoint: args.endpoint
|
|
19
|
+
allowedIps,
|
|
20
|
+
endpoint: args.endpoint,
|
|
21
|
+
excludedIps,
|
|
22
|
+
dns: args.dns
|
|
16
23
|
},
|
|
17
24
|
$status: {
|
|
18
|
-
allowedIps:
|
|
25
|
+
allowedIps: {
|
|
26
|
+
value: allowedIps.join(", "),
|
|
27
|
+
complementaryTo: "allowedIps"
|
|
28
|
+
},
|
|
29
|
+
excludedIps: {
|
|
30
|
+
value: excludedIps.join(", "),
|
|
31
|
+
complementaryTo: "excludedIps"
|
|
32
|
+
}
|
|
19
33
|
}
|
|
20
34
|
});
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
export {
|
|
36
|
+
peer_default as default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/peer/index.ts"],"sourcesContent":["import { wireguard } from \"@highstate/library\"\nimport { forUnit, toPromise } from \"@highstate/pulumi\"\nimport { calculateAllowedIps, calculateExcludedIps } from \"../shared\"\n\nconst { name, args, inputs, outputs } = forUnit(wireguard.peer)\n\nconst network = await toPromise(inputs.network)\n\nconst allowedIps = calculateAllowedIps(args, network)\nconst excludedIps = calculateExcludedIps(args, network)\n\nexport default outputs({\n peer: {\n name: args.peerName ?? name,\n network: inputs.network,\n address: args.address,\n publicKey: args.publicKey,\n allowedIps,\n endpoint: args.endpoint,\n excludedIps,\n dns: args.dns,\n },\n $status: {\n allowedIps: {\n value: allowedIps.join(\", \"),\n complementaryTo: \"allowedIps\",\n },\n excludedIps: {\n value: excludedIps.join(\", \"),\n complementaryTo: \"excludedIps\",\n },\n },\n})\n"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAGnC,IAAM,EAAE,MAAM,MAAM,QAAQ,QAAQ,IAAI,QAAQ,UAAU,IAAI;AAE9D,IAAM,UAAU,MAAM,UAAU,OAAO,OAAO;AAE9C,IAAM,aAAa,oBAAoB,MAAM,OAAO;AACpD,IAAM,cAAc,qBAAqB,MAAM,OAAO;AAEtD,IAAO,eAAQ,QAAQ;AAAA,EACrB,MAAM;AAAA,IACJ,MAAM,KAAK,YAAY;AAAA,IACvB,SAAS,OAAO;AAAA,IAChB,SAAS,KAAK;AAAA,IACd,WAAW,KAAK;AAAA,IAChB;AAAA,IACA,UAAU,KAAK;AAAA,IACf;AAAA,IACA,KAAK,KAAK;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,YAAY;AAAA,MACV,OAAO,WAAW,KAAK,IAAI;AAAA,MAC3B,iBAAiB;AAAA,IACnB;AAAA,IACA,aAAa;AAAA,MACX,OAAO,YAAY,KAAK,IAAI;AAAA,MAC5B,iBAAiB;AAAA,IACnB;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highstate/wireguard",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"./network": "./dist/network/index.js",
|
|
10
10
|
"./identity": "./dist/identity/index.js",
|
|
11
11
|
"./config": "./dist/config/index.js",
|
|
12
|
+
"./config-bundle": "./dist/config-bundle/index.js",
|
|
12
13
|
"./node": "./dist/node/index.js",
|
|
13
14
|
"./peer": "./dist/peer/index.js"
|
|
14
15
|
},
|
|
@@ -16,19 +17,24 @@
|
|
|
16
17
|
"access": "public"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
+
"build": "highstate build"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@highstate/
|
|
23
|
-
"@highstate/
|
|
23
|
+
"@highstate/common": "^0.7.3",
|
|
24
|
+
"@highstate/contract": "^0.7.3",
|
|
25
|
+
"@highstate/k8s": "^0.7.3",
|
|
26
|
+
"@highstate/pulumi": "^0.7.3",
|
|
24
27
|
"@noble/curves": "^1.8.0",
|
|
25
|
-
"@pulumi/kubernetes": "^4.18.0"
|
|
28
|
+
"@pulumi/kubernetes": "^4.18.0",
|
|
29
|
+
"deepmerge-ts": "^7.1.5",
|
|
30
|
+
"zip-stream": "^7.0.2"
|
|
26
31
|
},
|
|
27
32
|
"peerDependencies": {
|
|
28
33
|
"@highstate/library": "workspace:^0.4.4"
|
|
29
34
|
},
|
|
30
35
|
"devDependencies": {
|
|
31
|
-
"
|
|
36
|
+
"@highstate/cli": "^0.7.3",
|
|
37
|
+
"@types/zip-stream": "^7.0.0"
|
|
32
38
|
},
|
|
33
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "5cf7cec27262c8fa1d96f6478833b94841459d64"
|
|
34
40
|
}
|
package/dist/shared-D24icZbJ.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { x25519 } from '@noble/curves/ed25519';
|
|
2
|
-
|
|
3
|
-
const crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
4
|
-
|
|
5
|
-
function randomBytes(bytesLength = 32) {
|
|
6
|
-
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
7
|
-
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
8
|
-
}
|
|
9
|
-
if (crypto && typeof crypto.randomBytes === "function") {
|
|
10
|
-
return crypto.randomBytes(bytesLength);
|
|
11
|
-
}
|
|
12
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function generateKey() {
|
|
16
|
-
const key = x25519.utils.randomPrivateKey();
|
|
17
|
-
return Buffer.from(key).toString("base64");
|
|
18
|
-
}
|
|
19
|
-
function convertPrivateKeyToPublicKey(privateKey) {
|
|
20
|
-
const key = Buffer.from(privateKey, "base64");
|
|
21
|
-
return Buffer.from(x25519.getPublicKey(key)).toString("base64");
|
|
22
|
-
}
|
|
23
|
-
function generatePresharedKey() {
|
|
24
|
-
const key = randomBytes(32);
|
|
25
|
-
return Buffer.from(key).toString("base64");
|
|
26
|
-
}
|
|
27
|
-
function combinePresharedKeyParts(part1, part2) {
|
|
28
|
-
const key1 = Buffer.from(part1, "base64");
|
|
29
|
-
const key2 = Buffer.from(part2, "base64");
|
|
30
|
-
const result = new Uint8Array(32);
|
|
31
|
-
for (let i = 0; i < 32; i++) {
|
|
32
|
-
result[i] = key1[i] ^ key2[i];
|
|
33
|
-
}
|
|
34
|
-
return Buffer.from(result).toString("base64");
|
|
35
|
-
}
|
|
36
|
-
function generatePeerConfig(identity, peer) {
|
|
37
|
-
const lines = [
|
|
38
|
-
"[Peer]",
|
|
39
|
-
`# ${peer.name}`,
|
|
40
|
-
`PublicKey = ${peer.publicKey}`,
|
|
41
|
-
`AllowedIPs = ${peer.allowedIps.join(", ")}`
|
|
42
|
-
];
|
|
43
|
-
if (peer.endpoint) {
|
|
44
|
-
lines.push(`Endpoint = ${peer.endpoint}`);
|
|
45
|
-
}
|
|
46
|
-
if (identity.presharedKeyPart && peer.presharedKeyPart) {
|
|
47
|
-
const presharedKey = combinePresharedKeyParts(identity.presharedKeyPart, peer.presharedKeyPart);
|
|
48
|
-
lines.push(`PresharedKey = ${presharedKey}`);
|
|
49
|
-
} else if (identity.network?.globalPresharedKey) {
|
|
50
|
-
if (identity.network.globalPresharedKey !== peer.network?.globalPresharedKey) {
|
|
51
|
-
throw new Error("The global preshared key must be the same for all peers.");
|
|
52
|
-
}
|
|
53
|
-
lines.push(`PresharedKey = ${identity.network.globalPresharedKey}`);
|
|
54
|
-
}
|
|
55
|
-
return lines.join("\n");
|
|
56
|
-
}
|
|
57
|
-
function generateIdentityConfig(identity, peers, listenPort, dns, postUp) {
|
|
58
|
-
const lines = [
|
|
59
|
-
//
|
|
60
|
-
"[Interface]",
|
|
61
|
-
`# ${identity.name}`
|
|
62
|
-
];
|
|
63
|
-
if (identity.address) {
|
|
64
|
-
lines.push(`Address = ${identity.address}`);
|
|
65
|
-
}
|
|
66
|
-
lines.push(
|
|
67
|
-
//
|
|
68
|
-
`PrivateKey = ${identity.privateKey}`,
|
|
69
|
-
"MTU = 1280"
|
|
70
|
-
);
|
|
71
|
-
if (dns) {
|
|
72
|
-
lines.push(`DNS = ${dns.join(", ")}`);
|
|
73
|
-
}
|
|
74
|
-
if (listenPort) {
|
|
75
|
-
lines.push(`ListenPort = ${listenPort}`);
|
|
76
|
-
}
|
|
77
|
-
if (postUp) {
|
|
78
|
-
lines.push();
|
|
79
|
-
for (const command of postUp) {
|
|
80
|
-
lines.push(`PostUp = ${command}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const otherPeers = peers.filter((peer) => peer.name !== identity.name);
|
|
84
|
-
for (const peer of otherPeers) {
|
|
85
|
-
lines.push("");
|
|
86
|
-
lines.push(generatePeerConfig(identity, peer));
|
|
87
|
-
}
|
|
88
|
-
return lines.join("\n");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { generatePresharedKey as a, generateIdentityConfig as b, convertPrivateKeyToPublicKey as c, generateKey as g };
|