From 4ee5904b00762eaf175a45acfb6eacc21228f5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20Ha=C3=9F?= Date: Thu, 18 Apr 2024 17:53:16 +0200 Subject: [PATCH] refactored traefik and added postman collection --- .env | 2 +- backend/src/main.ts | 2 +- docker-compose.dev.yml | 49 ++++++++++++++++----- docker-compose.yml | 61 ++++++++++++--------------- oid4vc/TangleLabs/src/httpServer.ts | 2 +- oid4vc/TangleLabs/src/index.ts | 14 +++--- oid4vc/TangleLabs/src/remoteSigner.ts | 8 ++-- tooling/Selv.postman_collection.json | 60 ++++++++++++++++++++++++++ web/src/config.json | 2 +- 9 files changed, 142 insertions(+), 58 deletions(-) create mode 100644 tooling/Selv.postman_collection.json diff --git a/.env b/.env index fb6e6557..c9cf2386 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ HTTP_PORT=81 -GRPC_PORT=5000 \ No newline at end of file +GRPC_PORT=5001 \ No newline at end of file diff --git a/backend/src/main.ts b/backend/src/main.ts index 6c688f8d..c0247a8c 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -20,7 +20,7 @@ async function bootstrap() { 'proto', 'user/user.proto', ), - url: '0.0.0.0:5000', + url: '0.0.0.0:50051', }, }); diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 28c6a6c3..58b8b689 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,6 +1,16 @@ version: '3' services: + whoami: + # A container that exposes an API to show its IP address + image: traefik/whoami + expose: + - '80' + labels: + traefik.enable: true + traefik.http.routers.whoami.rule: Host(`whoami.localhost`) + traefik.http.routers.whoami.entrypoints: web + backend: extends: file: docker-compose.yml @@ -15,23 +25,40 @@ services: - run - start:dev labels: - - "traefik.http.routers.backend-grpc.rule=Host(`backend.localhost`)" - - "traefik.http.routers.backend-grpc.entrypoints=grpc" - - "traefik.http.routers.backend-grpc.service=svc_backend-grpc" - - "traefik.http.services.svc_backend-grpc.loadbalancer.server.port=5000" - - "traefik.http.services.svc_backend-grpc.loadbalancer.server.scheme=h2c" + traefik.http.routers.backend-grpc.rule: PathPrefix(`/backend`) + traefik.http.routers.backend-grpc.middlewares: backend-grpc-stripprefix + traefik.http.middlewares.backend-grpc-stripprefix.stripprefix.prefixes: /backend + traefik.http.routers.backend-grpc.entrypoints: grpc + traefik.http.routers.backend-grpc.service: svc_backend-grpc + traefik.http.services.svc_backend-grpc.loadbalancer.server.port: "50051" + traefik.http.services.svc_backend-grpc.loadbalancer.server.scheme: h2c identity: extends: file: docker-compose.yml service: identity labels: - - "traefik.enable=true" - - "traefik.http.routers.identity-grpc.rule=Host(`identity.localhost`)" - - "traefik.http.routers.identity-grpc.entrypoints=grpc" - - "traefik.http.routers.identity-grpc.service=svc_identity-grpc" - - "traefik.http.services.svc_identity-grpc.loadbalancer.server.port=50051" - - "traefik.http.services.svc_identity-grpc.loadbalancer.server.scheme=h2c" + traefik.enable: true + traefik.http.routers.identity-grpc.rule: PathPrefix(`/identity`) + traefik.http.routers.identity-grpc.middlewares: identity-grpc-stripprefix + traefik.http.middlewares.identity-grpc-stripprefix.stripprefix.prefixes: /identity + traefik.http.routers.identity-grpc.entrypoints: grpc + traefik.http.routers.identity-grpc.service: svc_identity-grpc + traefik.http.services.svc_identity-grpc.loadbalancer.server.port: "50051" + traefik.http.services.svc_identity-grpc.loadbalancer.server.scheme: h2c + + oid4vc-tanglelabs: + extends: + file: docker-compose.yml + service: oid4vc-tanglelabs + labels: + traefik.http.routers.oid4vc-tanglelabs-grpc.rule: PathPrefix(`/oid4vc-tanglelabs`) + traefik.http.routers.oid4vc-tanglelabs-grpc.middlewares: oid4vc-tanglelabs-grpc-stripprefix + traefik.http.middlewares.oid4vc-tanglelabs-grpc-stripprefix.stripprefix.prefixes: /oid4vc-tanglelabs + traefik.http.routers.oid4vc-tanglelabs-grpc.entrypoints: grpc + traefik.http.routers.oid4vc-tanglelabs-grpc.service: svc_oid4vc-tanglelabs-grpc + traefik.http.services.svc_oid4vc-tanglelabs-grpc.loadbalancer.server.port: "50051" + traefik.http.services.svc_oid4vc-tanglelabs-grpc.loadbalancer.server.scheme: h2c grpcurl: image: fullstorydev/grpcurl:latest diff --git a/docker-compose.yml b/docker-compose.yml index d0921175..7cd9908d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,27 +14,18 @@ services: - "--providers.docker.exposedbydefault=false" - "--entrypoints.web.address=:80" - "--entrypoints.grpc.address=:5000" + - "--log.level=DEBUG" ports: - "${HTTP_PORT}:80/tcp" - "${GRPC_PORT}:5000/tcp" volumes: - "/var/run/docker.sock:/var/run/docker.sock:ro" - "./data/letsencrypt:/letsencrypt" - - whoami: - # A container that exposes an API to show its IP address - image: traefik/whoami - expose: - - '80' - labels: - - "traefik.enable=true" - - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)" - - "traefik.http.routers.whoami.entrypoints=web" redis: image: redis:latest labels: - - "traefik.enable=false" + traefik.enable: false backend: build: @@ -42,7 +33,7 @@ services: dockerfile: ./backend/Dockerfile expose: - '3000' - - '5000' + - '50051' # depends_on: # - redis # - identity @@ -50,28 +41,32 @@ services: ISSUERS_BANK_DID: did:iota:snd:0x2cfb60f00089a91a96fa8fcee5e2bda15f51b0b062762ad9ca846bba536f8818 ISSUERS_BANK_FRAGMENT: S3zEW4inNy8FYZEMVTEthdzqqSBq1WglM2k75xKHzy0 labels: - - "traefik.enable=true" - - "traefik.http.routers.backend.rule=Host(`backend.localhost`)" - - "traefik.http.routers.backend.entrypoints=web" - - "traefik.http.routers.backend.service=backend" - - "traefik.http.services.backend.loadbalancer.server.port=3000" + traefik.enable: true + traefik.http.routers.backend.rule: Host(`backend.localhost`) + traefik.http.routers.backend.entrypoints: web + traefik.http.routers.backend.service: backend + traefik.http.services.backend.loadbalancer.server.port: "3000" oid4vc-tanglelabs: build: context: ./ dockerfile: ./oid4vc/TangleLabs/Dockerfile environment: + RP_DID: did:iota:snd:0x2cfb60f00089a91a96fa8fcee5e2bda15f51b0b062762ad9ca846bba536f8818 SIGNER_KEYID: pK0JAYw5RFFKqorBn0x4w98zl2UBfRys + KEY_FRAGMENT: key-1 + PUBLIC_URL: "192.168.0.234:8080" expose: + - '3333' - '50051' volumes: - ./proto:/usr/proto labels: - - "traefik.enable=true" - - "traefik.http.routers.oid4vc-tanglelabs.rule=Host(`bank.localhost`)" - - "traefik.http.routers.oid4vc-tanglelabs.entrypoints=web" - - "traefik.http.routers.oid4vc-tanglelabs.service=oid4vc-tanglelabs" - - "traefik.http.services.oid4vc-tanglelabs.loadbalancer.server.port=3000" + traefik.enable: true + traefik.http.routers.oid4vc-tanglelabs.rule: Host(`bank.localhost`) + traefik.http.routers.oid4vc-tanglelabs.entrypoints: web + traefik.http.routers.oid4vc-tanglelabs.service: oid4vc-tanglelabs + traefik.http.services.oid4vc-tanglelabs.loadbalancer.server.port: "3333" oid4vc-waltid: build: @@ -82,11 +77,11 @@ services: volumes: - ./proto:/usr/proto labels: - - "traefik.enable=true" - - "traefik.http.routers.oid4vc-waltid.rule=Host(`government.localhost`)" - - "traefik.http.routers.oid4vc-waltid.entrypoints=web" - - "traefik.http.routers.oid4vc-waltid.service=oid4vc-waltid" - - "traefik.http.services.oid4vc-waltid.loadbalancer.server.port=3000" + traefik.enable: true + traefik.http.routers.oid4vc-waltid.rule: Host(`government.localhost`) + traefik.http.routers.oid4vc-waltid.entrypoints: web + traefik.http.routers.oid4vc-waltid.service: oid4vc-waltid + traefik.http.services.oid4vc-waltid.loadbalancer.server.port: "3000" oid4vc-impierce: image: impierce/ssi-agent @@ -95,11 +90,11 @@ services: volumes: - ./proto:/usr/proto labels: - - "traefik.enable=true" - - "traefik.http.routers.oid4vc-impierce.rule=Host(`insurance.localhost`)" - - "traefik.http.routers.oid4vc-impierce.entrypoints=web" - - "traefik.http.routers.oid4vc-impierce.service=oid4vc-impierce" - - "traefik.http.services.oid4vc-impierce.loadbalancer.server.port=3033" + traefik.enable: true + traefik.http.routers.oid4vc-impierce.rule: Host(`insurance.localhost`) + traefik.http.routers.oid4vc-impierce.entrypoints: web + traefik.http.routers.oid4vc-impierce.service: oid4vc-impierce + traefik.http.services.oid4vc-impierce.loadbalancer.server.port: "3033" environment: #AGENT_CONFIG_LOG_FORMAT: json AGENT_CONFIG_EVENT_STORE: postgres @@ -129,4 +124,4 @@ services: expose: - '50051' labels: - - "traefik.enable=false" + traefik.enable: false diff --git a/oid4vc/TangleLabs/src/httpServer.ts b/oid4vc/TangleLabs/src/httpServer.ts index 7d7c4ae0..0d35c0dd 100644 --- a/oid4vc/TangleLabs/src/httpServer.ts +++ b/oid4vc/TangleLabs/src/httpServer.ts @@ -12,7 +12,7 @@ export const createServer = (rp) => { ); app.route("/api/auth").post( asyncHandler(async (req, res) => { - console.log(req); + console.debug(req); await rp.verifyAuthResponse(req.body); res.status(204).send(); }) diff --git a/oid4vc/TangleLabs/src/index.ts b/oid4vc/TangleLabs/src/index.ts index 228f905b..c59a57bf 100644 --- a/oid4vc/TangleLabs/src/index.ts +++ b/oid4vc/TangleLabs/src/index.ts @@ -25,16 +25,16 @@ import { createServer } from "./httpServer"; fromMultibase: Ed25519VerificationKey2020.from, }); - const verificationKeyPair = await Ed25519VerificationKey2020.generate(); + // const verificationKeyPair = await Ed25519VerificationKey2020.generate(); - console.log(bytesToString(verificationKeyPair._publicKeyBuffer)); - console.log(bytesToString(verificationKeyPair._privateKeyBuffer)); + // console.log(bytesToString(verificationKeyPair._publicKeyBuffer)); + // console.log(bytesToString(verificationKeyPair._privateKeyBuffer)); const keyDidResolver = KeyDIDResolver.getResolver(); let resolver = new Resolver(keyDidResolver); const rp = new RelyingParty({ - clientId: "did:iota:0x", + clientId: process.env.RP_DID, clientMetadata: { subjectSyntaxTypesSupported: [ "did:iota" @@ -43,10 +43,10 @@ import { createServer } from "./httpServer"; SigningAlgs.EdDSA ], }, - did: "did:iota:0x", - kid: "did:iota:0x#my_key", + did: process.env.RP_DID, + kid: `${process.env.SIGNER_KEYID}#${process.env.KEY_FRAGMENT}`, signer: remoteSigner(process.env.SIGNER_KEYID), - redirectUri: "http://192.168.0.234:8080/api/auth", + redirectUri: `http://${process.env.PUBLIC_URL}/api/auth`, resolver: resolver, }); diff --git a/oid4vc/TangleLabs/src/remoteSigner.ts b/oid4vc/TangleLabs/src/remoteSigner.ts index 8b3a7a02..9c8c951e 100644 --- a/oid4vc/TangleLabs/src/remoteSigner.ts +++ b/oid4vc/TangleLabs/src/remoteSigner.ts @@ -30,14 +30,16 @@ export const remoteSigner: (keyId: string) => Signer = (keyId) => async (data) = const response = await new Promise((resolve, reject) => identityClient.sign({ keyId, - data: Array.from(Buffer.from(data)), + data: Uint8Array.from(Buffer.from(data)), }, (err, response) => { if (err) { - console.error(err); + reject(err); } resolve(response); })); console.log(response) - return response as string; + return (response as { + signature: Buffer + }).signature.toString('base64'); }; \ No newline at end of file diff --git a/tooling/Selv.postman_collection.json b/tooling/Selv.postman_collection.json new file mode 100644 index 00000000..a6a18a38 --- /dev/null +++ b/tooling/Selv.postman_collection.json @@ -0,0 +1,60 @@ +{ + "info": { + "_postman_id": "31612dd5-1b94-47b6-8180-ee256374ab94", + "name": "Selv", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "10688" + }, + "item": [ + { + "name": "OID4VC", + "item": [ + { + "name": "TangleLabs", + "item": [ + { + "name": "Health", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "bank.localhost:81/api/health", + "host": [ + "bank", + "localhost" + ], + "port": "81", + "path": [ + "api", + "health" + ] + } + }, + "response": [] + }, + { + "name": "Auth", + "request": { + "method": "POST", + "header": [], + "url": { + "raw": "bank.localhost:81/api/auth", + "host": [ + "bank", + "localhost" + ], + "port": "81", + "path": [ + "api", + "auth" + ] + } + }, + "response": [] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/web/src/config.json b/web/src/config.json index e3d5e9ee..76e8a932 100644 --- a/web/src/config.json +++ b/web/src/config.json @@ -1,5 +1,5 @@ { - "websocketURL": "http://backend.localhost/", + "websocketURL": "http://backend.localhost:81/", "serverAPI": "https://selv01.iota.cafe", "provider": "https://nodes.devnet.iota.org:443", "keyId": "selv",