Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 64 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,86 @@
version: "3.9"
name: 'io-sign-dev'

services:
cosmos-db:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
#preview version wich supports ARM
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
mem_limit: 3G
cpu_count: 2
tty: true
environment:
- AZURE_COSMOS_EMULATOR_PARTITION_COUNT=3
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
- COSMOSDB_EMULATOR_URI=http://cosmos-db:8081
- COSMOSDB_EMULATOR_KEY='C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=='
- NODE_TLS_REJECT_UNAUTHORIZED=0
ports:
- 8081:8081
- 1234:1234
- 10251:10251
- 10252:10252
- 10253:10253
- 10254:10254
# volume persistence disabled for local debugging on macOS (permission issues)
# volumes:
# - cosmos-db-volume:/data/db

cosmos-db-setup:
image: node:20-alpine
working_dir: /app
depends_on:
- cosmos-db
environment:
- COSMOS_ENDPOINT=http://cosmos-db:8081
- NODE_TLS_REJECT_UNAUTHORIZED=0
volumes:
- cosmos-db-volume:/data/db
- ./setup-cosmos-containers.js:/app/setup-cosmos-containers.js
command: sh -c "npm install @azure/cosmos && node setup-cosmos-containers.js"

storage:
image: mcr.microsoft.com/azure-storage/azurite
command: "azurite -l /data --blobHost 0.0.0.0 --queueHost 0.0.0.0 --skipApiVersionCheck"
azurite:
platform: linux/amd64
image: mcr.microsoft.com/azure-storage/azurite:latest
ports:
- 10000:10000
- 10001:10001
- 10002:10002
command: azurite --skipApiVersionCheck --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0

azurite-setup:
image: node:20-alpine
working_dir: /app
depends_on:
- azurite
volumes:
- ./setup-azurite-containers.js:/app/setup-azurite-containers.js
command: sh -c "npm install @azure/storage-blob @azure/storage-queue @azure/data-tables && node setup-azurite-containers.js"

eventhubs:
image: "mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest@sha256:25ec4141efb69933a0c82e6a787fa147a3895519e7d236d4c41ba568e03100eb"
depends_on:
- "azurite"
ports:
- "5672:5672"
- "9092:9092"
- "9093:9093"
volumes:
- "./eventhubs-emulator.json:/Eventhubs_Emulator/ConfigFiles/Config.json"
environment:
BLOB_SERVER: azurite
METADATA_SERVER: azurite
ACCEPT_EULA: Y

kafka-ui:
image: "provectuslabs/kafka-ui:latest@sha256:8f2ff02d64b0a7a2b71b6b3b3148b85f66d00ec20ad40c30bdcd415d46d31818"
depends_on:
- "eventhubs"
ports:
- "8002:8080"
environment:
KAFKA_CLUSTERS_0_NAME: "local"
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: "eventhubs:9092"
KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: "SASL_PLAINTEXT"
KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: "PLAIN"
KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="Endpoint=sb://eventhubs;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;";'

volumes:
cosmos-db-volume:
43 changes: 43 additions & 0 deletions eventhubs-emulator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://raw.githubusercontent.com/Azure/azure-event-hubs-emulator-installer/refs/heads/main/EventHub-Emulator/Schema/Config-schema.json",
"UserConfig": {
"NamespaceConfig": [
{
"Type": "EventHub",
"Name": "emulatorNs1",
"Entities": [
{
"Name": "sc-contracts",
"PartitionCount": 2,
"ConsumerGroups": [
{
"Name": "Default"
}
]
},
{
"Name": "billing",
"PartitionCount": 2,
"ConsumerGroups": [
{
"Name": "Default"
}
]
},
{
"Name": "analytics",
"PartitionCount": 2,
"ConsumerGroups": [
{
"Name": "Default"
}
]
}
]
}
],
"LoggingConfig": {
"Type": "Console"
}
}
}
53 changes: 53 additions & 0 deletions setup-azurite-containers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// this script creates the necessary containers, queues in the Azurite storage emulator

const { BlobServiceClient } = require("@azure/storage-blob");
const { QueueServiceClient } = require("@azure/storage-queue");

const connectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=devstoreaccount1;" +
"AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
"BlobEndpoint=http://azurite:10000/devstoreaccount1;" +
"QueueEndpoint=http://azurite:10001/devstoreaccount1;" +
"TableEndpoint=http://azurite:10002/devstoreaccount1;";

const blobServiceClient =
BlobServiceClient.fromConnectionString(connectionString);
const queueServiceClient =
QueueServiceClient.fromConnectionString(connectionString);

const containers = ["uploaded-documents", "signed-documents","validated-documents"];
const queues = [
"on-signature-request-ready",
"waiting-for-signature-request-updates",
"on-signature-request-wait-for-signature",
"on-signature-request-signed",
"on-signature-request-rejected"
];

const createContainerIfNotExists = async (name) => {
try {
const containerClient = blobServiceClient.getContainerClient(name);
await containerClient.createIfNotExists();
console.log(`Container ${name} created.`);
} catch (error) {
console.error(`Error creating container ${name}:`, error);
}
};

const createQueueIfNotExists = async (name) => {
try {
const queueClient = queueServiceClient.getQueueClient(name);
await queueClient.createIfNotExists();
console.log(`Queue ${name} created.`);
} catch (error) {
console.error(`Error creating queue ${name}:`, error);
}
};

(async () => {
await Promise.all([
...containers.map(createContainerIfNotExists),
...queues.map(createQueueIfNotExists),
]);
})();
122 changes: 122 additions & 0 deletions setup-cosmos-containers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

Check failure

Code scanning / CodeQL

Disabling certificate validation High

Disabling certificate validation is strongly discouraged.

Copilot Autofix

AI 1 day ago

In general, you should not globally disable TLS certificate validation. Instead, either (a) leave the default verification behavior in place, or (b) if you must trust a custom/self‑signed certificate (for an emulator or internal endpoint), explicitly configure a proper CA/certificate for that connection only, rather than changing NODE_TLS_REJECT_UNAUTHORIZED.

The single best fix here, without changing existing functionality beyond restoring secure defaults, is to remove the line that sets process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";. Cosmos DB client connections will then use standard TLS verification rules, and any other libraries in the process will no longer have their certificate checks disabled globally. No other code in this file appears to rely on this environment variable, and we do not need to add any imports or helper methods to achieve the fix. The change is localized to the very top of setup-cosmos-containers.js, removing line 2.

Suggested changeset 1
setup-cosmos-containers.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/setup-cosmos-containers.js b/setup-cosmos-containers.js
--- a/setup-cosmos-containers.js
+++ b/setup-cosmos-containers.js
@@ -1,6 +1,6 @@
 
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
 
+
 const { CosmosClient } = require("@azure/cosmos");
 
 const endpoint = process.env.COSMOS_ENDPOINT || "http://cosmos-db:8081";
EOF
@@ -1,6 +1,6 @@

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";


const { CosmosClient } = require("@azure/cosmos");

const endpoint = process.env.COSMOS_ENDPOINT || "http://cosmos-db:8081";
Copilot is powered by AI and may make mistakes. Always verify output.

const { CosmosClient } = require("@azure/cosmos");

const endpoint = process.env.COSMOS_ENDPOINT || "http://cosmos-db:8081";
const key =
process.env.COSMOS_KEY ||
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

const client = new CosmosClient({ endpoint, key, connectionPolicy: { enableEndpointDiscovery: false } });

// Databases and their containers with specific partition keys
const databases = [
{
id: "backoffice",
containers: [
{ id: "api-keys", partitionPath: "/institutionId" },
{ id: "api-keys-by-id", partitionPath: "/id" },
{ id: "consents", partitionPath: "/institutionId" },
{ id: "issuers", partitionPath: "/institutionId" },
],
},
{
id: "issuer",
containers: [
{ id: "dossiers", partitionPath: "/issuerId" },
{ id: "issuers", partitionPath: "/subscriptionId" },
{ id: "issuers-by-subscription-id", partitionPath: "/id" },
{ id: "issuers-by-vat-number", partitionPath: "/id" },
{ id: "issuers-whitelist", partitionPath: "/id" },
{ id: "signature-requests", partitionPath: "/issuerId" },
{ id: "uploads", partitionPath: "/id" },
],
},
{
id: "user",
containers: [
{ id: "signature-requests", partitionPath: "/signerId" },
{ id: "signatures", partitionPath: "/signerId" },
],
},
];

const DEFAULT_PARTITION_PATH = "/id";

const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function createDatabaseAndContainers(dbDef) {
const { id: dbId, containers } = dbDef;
try {
const { database } = await client.databases.createIfNotExists({ id: dbId });
console.log(`Database '${dbId}' ready.`);

for (const containerDef of containers) {
const containerId = containerDef.id || containerDef;
const partitionPath = containerDef.partitionPath || DEFAULT_PARTITION_PATH;
try {
await database.containers.createIfNotExists(
{
id: containerId,
partitionKey: { paths: [partitionPath], kind: "Hash" },
},
{ offerThroughput: 400 }
);
console.log(` Container '${containerId}' (partition: '${partitionPath}') created in DB '${dbId}'.`);
} catch (innerErr) {
console.error(` Error creating container '${containerId}' in DB '${dbId}':`, innerErr.message || innerErr);
}
}
} catch (err) {
console.error(`Error creating/reading database '${dbId}':`, err.message || err);
throw err;
}
}

async function main() {
const maxAttempts = 30;
const delayMs = 2000;
let attempt = 0;

while (attempt < maxAttempts) {
try {
// quick call to check emulator availability
await client.database("" + databases[0].id).read();
// If read doesn't throw, connection works (or DB exists).
break;
} catch (err) {
// Cosmos emulator returns 404 for read when DB doesn't exist; that's fine.
// We just want to verify the emulator is responding.
if (err.code === 404) {
console.log("Cosmos emulator is reachable (Database not found yet).");
break;
}
const isNetworkErr = /ENOTFOUND|ECONNREFUSED|ECONNRESET|certificate|CERT_|EPROTO/i.test((err && err.code) || err.message || "");
attempt++;
if (attempt >= maxAttempts) {
console.error("Cosmos emulator not reachable after retries, giving up.");
throw err;
}
console.log(`Waiting for Cosmos emulator (${attempt}/${maxAttempts})... reason: ${err.code || err.message}`);
await sleep(delayMs);
}
}

// Create databases and containers
for (const dbDef of databases) {
try {
await createDatabaseAndContainers(dbDef);
} catch (err) {
console.error(`Failed to provision DB '${dbDef.id}':`, err.message || err);
}
}

console.log("Cosmos provisioning finished.");
}

main().catch((err) => {
console.error("setup-cosmos-containers.js failed:", err.message || err);
process.exit(1);
});