Skip to content

Commit e24b745

Browse files
committed
feat: regitry stuff
1 parent 1c41f4d commit e24b745

File tree

13 files changed

+486
-190
lines changed

13 files changed

+486
-190
lines changed

infrastructure/evault-core/src/w3id/w3id.ts

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,64 @@ import { SecretsStore } from "../secrets/secrets-store";
77
import { uint8ArrayToHex } from "../utils/codec";
88

99
export class W3ID {
10-
private static instance: W3IDClass;
11-
private static secretsStore: SecretsStore;
10+
private static instance: W3IDClass;
11+
private static secretsStore: SecretsStore;
1212

13-
private constructor() {}
13+
private constructor() { }
1414

15-
static async get(options?: {
16-
id: string;
17-
driver: Driver;
18-
password?: string;
19-
}) {
20-
if (W3ID.instance) return W3ID.instance;
21-
if (!options)
22-
throw new Error(
23-
"No instance of W3ID exists yet, please create it by passing options"
24-
);
15+
static async get(options?: {
16+
id: string;
17+
driver: Driver;
18+
password?: string;
19+
}) {
20+
if (W3ID.instance) return W3ID.instance;
21+
if (!options)
22+
throw new Error(
23+
"No instance of W3ID exists yet, please create it by passing options"
24+
);
2525

26-
// Initialize secrets store if not already done
27-
if (!W3ID.secretsStore) {
28-
if (!options.password) {
29-
throw new Error("Password is required for secrets store");
30-
}
31-
W3ID.secretsStore = new SecretsStore(
32-
process.env.SECRETS_STORE_PATH!,
33-
options.password
34-
);
35-
}
26+
// Initialize secrets store if not already done
27+
if (!W3ID.secretsStore) {
28+
if (!options.password) {
29+
throw new Error("Password is required for secrets store");
30+
}
31+
W3ID.secretsStore = new SecretsStore(
32+
process.env.SECRETS_STORE_PATH!,
33+
options.password
34+
);
35+
}
3636

37-
const repository = new LogService(options.driver);
38-
const keyId = `w3id-${options.id}`;
37+
const repository = new LogService(options.driver);
38+
const keyId = `w3id-${options.id}`;
3939

40-
try {
41-
// Try to get existing seed
42-
const { seed, nextKeyHash } = await W3ID.secretsStore.getSeed(keyId);
43-
const keyPair = nacl.sign.keyPair.fromSeed(seed);
44-
W3ID.instance = await new W3IDBuilder()
45-
.withId(options.id)
46-
.withRepository(repository)
47-
.withGlobal(true)
48-
.withSigner(createSigner(keyPair))
49-
.withNextKeyHash(nextKeyHash)
50-
.build();
51-
} catch {
52-
// If no seed exists, create new one
53-
const keyPair = nacl.sign.keyPair();
54-
const nextKeyPair = nacl.sign.keyPair();
55-
const nextKeyHash = await hash(uint8ArrayToHex(nextKeyPair.publicKey));
40+
try {
41+
// Try to get existing seed
42+
const { seed, nextKeyHash } = await W3ID.secretsStore.getSeed(keyId);
43+
const keyPair = nacl.sign.keyPair.fromSeed(seed);
44+
W3ID.instance = await new W3IDBuilder()
45+
.withId(options.id)
46+
.withRepository(repository)
47+
.withGlobal(true)
48+
.withSigner(createSigner(keyPair))
49+
.withNextKeyHash(nextKeyHash)
50+
.build();
51+
} catch {
52+
// If no seed exists, create new one
53+
const keyPair = nacl.sign.keyPair();
54+
const nextKeyPair = nacl.sign.keyPair();
55+
const nextKeyHash = await hash(uint8ArrayToHex(nextKeyPair.publicKey));
5656

57-
// Store the seed
58-
await W3ID.secretsStore.storeSeed(keyId, keyPair.secretKey, nextKeyHash);
57+
// Store the seed
58+
await W3ID.secretsStore.storeSeed(keyId, keyPair.secretKey, nextKeyHash);
5959

60-
W3ID.instance = await new W3IDBuilder()
61-
.withId(options.id)
62-
.withRepository(repository)
63-
.withSigner(createSigner(keyPair))
64-
.withNextKeyHash(nextKeyHash)
65-
.build();
66-
}
60+
W3ID.instance = await new W3IDBuilder()
61+
.withId(options.id)
62+
.withRepository(repository)
63+
.withSigner(createSigner(keyPair))
64+
.withNextKeyHash(nextKeyHash)
65+
.build();
66+
}
6767

68-
return W3ID.instance;
69-
}
68+
return W3ID.instance;
69+
}
7070
}

infrastructure/evault-provisioner/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ app.post(
3737
res: Response<ProvisionResponse>,
3838
) => {
3939
try {
40-
// TODO: change this to take namespace from the payload, and signed entropy
41-
// JWT so that we can verify both parts of the UUID come from know source
4240
const { registryEntropy, namespace } = req.body;
4341

4442
if (!registryEntropy || !namespace) {

infrastructure/evault-provisioner/src/listeners/alloc.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

infrastructure/evault-provisioner/src/templates/evault.nomad.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ export async function provisionEVault(w3id: string, eVaultId: string) {
4444
});
4545
await coreApi.createNamespacedPersistentVolumeClaim({ namespace: namespaceName, body: pvcSpec('neo4j-data') });
4646
await coreApi.createNamespacedPersistentVolumeClaim({ namespace: namespaceName, body: pvcSpec('evault-store') });
47+
await coreApi.createNamespacedPersistentVolumeClaim({
48+
namespace: namespaceName, body: {
49+
metadata: { name: 'evault-secrets', namespace: namespaceName },
50+
spec: {
51+
accessModes: ['ReadWriteOnce'],
52+
resources: {
53+
requests: {
54+
storage: '2Mi'
55+
}
56+
}
57+
}
58+
}
59+
});
60+
4761

4862
const deployment = {
4963
metadata: { name: 'evault', namespace: namespaceName },
@@ -73,14 +87,17 @@ export async function provisionEVault(w3id: string, eVaultId: string) {
7387
{ name: 'NEO4J_USER', value: 'neo4j' },
7488
{ name: 'NEO4J_PASSWORD', value: neo4jPassword },
7589
{ name: 'PORT', value: containerPort.toString() },
76-
{ name: 'W3ID', value: w3id }
90+
{ name: 'W3ID', value: w3id },
91+
{ name: "ENCRYPTION_PASSWORD", value: neo4jPassword },
92+
{ name: "SECRETS_STORE_PATH", value: "/secrets" }
7793
],
7894
volumeMounts: [{ name: 'evault-store', mountPath: '/evault/data' }]
7995
}
8096
],
8197
volumes: [
8298
{ name: 'neo4j-data', persistentVolumeClaim: { claimName: 'neo4j-data' } },
83-
{ name: 'evault-store', persistentVolumeClaim: { claimName: 'evault-store' } }
99+
{ name: 'evault-store', persistentVolumeClaim: { claimName: 'evault-store' } },
100+
{ name: 'evault-secrets', persistentVolumeClaim: { claimName: "evault-secrets" } }
84101
]
85102
}
86103
}

platforms/registry/package.json

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
{
2-
"name": "registry",
3-
"version": "1.0.0",
4-
"description": "Registry service for entropy and service discovery",
5-
"main": "dist/index.js",
6-
"scripts": {
7-
"build": "tsc",
8-
"start": "node dist/index.js",
9-
"dev": "ts-node src/index.ts",
10-
"test": "jest"
11-
},
12-
"dependencies": {
13-
"@fastify/jwt": "^7.2.3",
14-
"axios": "^1.6.7",
15-
"dotenv": "^16.5.0",
16-
"fastify": "^4.26.1",
17-
"jose": "^5.2.2"
18-
},
19-
"devDependencies": {
20-
"@types/jest": "^29.5.12",
21-
"@types/node": "^20.11.19",
22-
"jest": "^29.7.0",
23-
"ts-jest": "^29.1.2",
24-
"ts-node": "^10.9.2",
25-
"typescript": "^5.3.3"
26-
}
2+
"name": "registry",
3+
"version": "1.0.0",
4+
"description": "Registry service for entropy and service discovery",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "tsc",
8+
"start": "node dist/index.js",
9+
"dev": "ts-node src/index.ts",
10+
"test": "jest",
11+
"typeorm": "typeorm-ts-node-commonjs",
12+
"migration:generate": "npm run typeorm migration:generate -- -d src/config/database.ts",
13+
"migration:run": "npm run typeorm migration:run -- -d src/config/database.ts",
14+
"migration:revert": "npm run typeorm migration:revert -- -d src/config/database.ts",
15+
"migration:create": "npm run typeorm migration:create"
16+
},
17+
"dependencies": {
18+
"@fastify/jwt": "^7.2.3",
19+
"axios": "^1.6.7",
20+
"dotenv": "^16.5.0",
21+
"fastify": "^4.26.1",
22+
"jose": "^5.2.2",
23+
"pg": "^8.11.3",
24+
"reflect-metadata": "^0.2.1",
25+
"typeorm": "^0.3.24"
26+
},
27+
"devDependencies": {
28+
"@types/jest": "^29.5.12",
29+
"@types/node": "^20.11.19",
30+
"@types/pg": "^8.11.0",
31+
"jest": "^29.7.0",
32+
"ts-jest": "^29.1.2",
33+
"ts-node": "^10.9.2",
34+
"typescript": "^5.3.3"
35+
}
2736
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { DataSource } from "typeorm"
2+
import { Vault } from "../entities/Vault"
3+
import * as dotenv from "dotenv"
4+
import { join } from "path"
5+
6+
// Load environment variables from root .env file
7+
dotenv.config({ path: join(__dirname, "../../../.env") })
8+
9+
export const AppDataSource = new DataSource({
10+
type: "postgres",
11+
url: process.env.REGISTRY_DATABASE_URL || "postgresql://postgres:postgres@localhost:5432/registry",
12+
synchronize: process.env.NODE_ENV !== "production",
13+
logging: process.env.NODE_ENV !== "production",
14+
entities: [Vault],
15+
migrations: [join(__dirname, "../migrations/*.{ts,js}")],
16+
migrationsTableName: "migrations",
17+
subscribers: [],
18+
})

platforms/registry/src/consul.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
2+
3+
@Entity()
4+
export class Vault {
5+
@PrimaryGeneratedColumn()
6+
id!: number
7+
8+
@Column()
9+
ename!: string
10+
11+
@Column()
12+
uri!: string
13+
14+
@Column()
15+
evault!: string
16+
}

0 commit comments

Comments
 (0)