Skip to content

Commit

Permalink
Temporal ssl fixes (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uros Marolt authored Oct 27, 2023
1 parent 68d2db7 commit 4c805c6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 10 deletions.
1 change: 0 additions & 1 deletion backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
"temporal": {
"serverUrl": "CROWD_TEMPORAL_SERVER_URL",
"namespace": "CROWD_TEMPORAL_NAMESPACE",
"rootCa": "CROWD_TEMPORAL_ROOT_CA",
"certificate": "CROWD_TEMPORAL_CERTIFICATE",
"privateKey": "CROWD_TEMPORAL_PRIVATE_KEY"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/services/docker/Dockerfile.automations_worker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-slim
FROM node:16-bookworm

WORKDIR /usr/crowd/app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"temporal": {
"serverUrl": "CROWD_TEMPORAL_SERVER_URL",
"namespace": "CROWD_TEMPORAL_NAMESPACE",
"rootCa": "CROWD_TEMPORAL_ROOT_CA",
"certificate": "CROWD_TEMPORAL_CERTIFICATE",
"privateKey": "CROWD_TEMPORAL_PRIVATE_KEY"
}
Expand Down
13 changes: 10 additions & 3 deletions services/archetypes/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,23 @@ export class ServiceWorker extends Service {
}

try {
const rootCa = process.env['CROWD_TEMPORAL_ROOT_CA']
const certificate = process.env['CROWD_TEMPORAL_CERTIFICATE']
const privateKey = process.env['CROWD_TEMPORAL_PRIVATE_KEY']

this.log.info(
{
address: process.env['CROWD_TEMPORAL_SERVER_URL'],
certificate: certificate ? 'yes' : 'no',
privateKey: privateKey ? 'yes' : 'no',
},
'Connecting to Temporal server as a worker!',
)

const connection = await NativeConnection.connect({
address: process.env['CROWD_TEMPORAL_SERVER_URL'],
tls:
rootCa && certificate && privateKey
certificate && privateKey
? {
serverRootCACertificate: Buffer.from(rootCa, 'base64'),
clientCertPair: {
crt: Buffer.from(certificate, 'base64'),
key: Buffer.from(privateKey, 'base64'),
Expand Down
45 changes: 45 additions & 0 deletions services/libs/temporal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion services/libs/temporal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"typescript": "^5.0.4"
},
"dependencies": {
"@temporalio/client": "~1.8.6"
"@temporalio/client": "~1.8.6",
"@crowd/logging": "file:../logging"
}
}
17 changes: 14 additions & 3 deletions services/libs/temporal/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import { getServiceChildLogger } from '@crowd/logging'
import { Connection, Client } from '@temporalio/client'

export interface ITemporalConfig {
serverUrl: string
namespace: string
identity: string
rootCa?: string
certificate?: string
privateKey?: string
}

const log = getServiceChildLogger('temporal')

let client: Client | undefined
export const getTemporalClient = async (cfg: ITemporalConfig): Promise<Client> => {
if (client) {
return client
}

log.info(
{
serverUrl: cfg.serverUrl,
namespace: cfg.namespace,
identity: cfg.identity,
certificate: cfg.certificate ? 'yes' : 'no',
privateKey: cfg.privateKey ? 'yes' : 'no',
},
'Creating temporal client!',
)
const connection = await Connection.connect({
address: cfg.serverUrl,
tls:
cfg.rootCa && cfg.certificate && cfg.privateKey
cfg.certificate && cfg.privateKey
? {
serverRootCACertificate: Buffer.from(cfg.rootCa, 'base64'),
clientCertPair: {
crt: Buffer.from(cfg.certificate, 'base64'),
key: Buffer.from(cfg.privateKey, 'base64'),
Expand Down

0 comments on commit 4c805c6

Please sign in to comment.