Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(calls): setup call recording (#2405)
Will Hutchinson8e334f020359
diff --git a/infra/bun.lock b/infra/bun.lockindex 553722ee89..ec14ec8e34 100644--- a/infra/bun.lock+++ b/infra/bun.lock@@ -51,6 +51,10 @@"stacks/bulk-upload": {"name": "bulk-upload-stack",},+ "stacks/call-recording": {+ "name": "call-recording-stack",+ "version": "0.0.0",+ },"stacks/cloud-storage-cache": {"name": "cloud-storage-cache-stack","version": "0.0.0",@@ -554,6 +558,8 @@"cacheable-request": ["[email protected]", "", { "dependencies": { "clone-response": "^1.0.2", "get-stream": "^5.1.0", "http-cache-semantics": "^4.0.0", "keyv": "^4.0.0", "lowercase-keys": "^2.0.0", "normalize-url": "^6.0.1", "responselike": "^2.0.0" } }, "sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg=="],+ "call-recording-stack": ["call-recording-stack@workspace:stacks/call-recording"],+"chownr": ["[email protected]", "", {}, "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ=="],"cjs-module-lexer": ["[email protected]", "", {}, "sha512-cuSVIHi9/9E/+821Qjdvngor+xpnlwnuwIyZOaLmHBVdXL+gP+I6QQB9VkO7RI77YIcTV+S1W9AreJ5eN63JBA=="],diff --git a/infra/packages/resources/src/resources/bucket.ts b/infra/packages/resources/src/resources/bucket.tsindex 45fffb6162..844358d0f8 100644--- a/infra/packages/resources/src/resources/bucket.ts+++ b/infra/packages/resources/src/resources/bucket.ts@@ -14,6 +14,7 @@ export function createBucket({lifecycleRules,enableVersioning,exposeHeaders,+ tags,}: {id: string;bucketName: string;@@ -21,6 +22,7 @@ export function createBucket({lifecycleRules?: aws.types.input.s3.BucketLifecycleRule[];enableVersioning?: boolean;exposeHeaders?: string[];+ tags?: { [name: string]: string };}): Bucket {// Document Storage S3 Bucketreturn new aws.s3.Bucket(id, {@@ -51,6 +53,7 @@ export function createBucket({targetPrefix: `${bucketName}/`,}: undefined,+ tags,});}diff --git a/infra/stacks/call-recording/Pulumi.dev.yaml b/infra/stacks/call-recording/Pulumi.dev.yamlnew file mode 100644index 0000000000..9cfd7a1eb5--- /dev/null+++ b/infra/stacks/call-recording/Pulumi.dev.yaml@@ -0,0 +1,3 @@+config:+ aws-native:region: us-east-1+ aws:region: us-east-1diff --git a/infra/stacks/call-recording/Pulumi.prod.yaml b/infra/stacks/call-recording/Pulumi.prod.yamlnew file mode 100644index 0000000000..9cfd7a1eb5--- /dev/null+++ b/infra/stacks/call-recording/Pulumi.prod.yaml@@ -0,0 +1,3 @@+config:+ aws-native:region: us-east-1+ aws:region: us-east-1diff --git a/infra/stacks/call-recording/Pulumi.yaml b/infra/stacks/call-recording/Pulumi.yamlnew file mode 100644index 0000000000..6a6da5b1a6--- /dev/null+++ b/infra/stacks/call-recording/Pulumi.yaml@@ -0,0 +1,3 @@+name: call-recording+runtime: nodejs+description: Call recordingdiff --git a/infra/stacks/call-recording/index.ts b/infra/stacks/call-recording/index.tsnew file mode 100644index 0000000000..e0fe83b9fd--- /dev/null+++ b/infra/stacks/call-recording/index.ts@@ -0,0 +1,229 @@+import * as aws from '@pulumi/aws';+import * as pulumi from '@pulumi/pulumi';+import { createBucket } from '../../packages/resources';+import { stack } from '../../packages/shared';++const tags = {+ environment: stack,+ tech_lead: 'hutch',+ project: 'call-recording',+};++// ---------------------------------------------------------------------------+// Bucket+// ---------------------------------------------------------------------------+const callRecordingBucket = createBucket({+ id: `macro-call-recording-${stack}`,+ bucketName: `macro-call-recording-${stack}`,+ transferAcceleration: stack === 'prod',+ enableVersioning: false,+ exposeHeaders: ['Content-Length', 'Content-Range'],+ tags,+});++export const callRecordingBucketId = callRecordingBucket.id;+export const callRecordingBucketArn = callRecordingBucket.arn;++// ---------------------------------------------------------------------------+// 1. IAM Policies (attach to users or roles)+// ---------------------------------------------------------------------------++// CRUD — standard object operations on the bucket+const crudPolicy = new aws.iam.Policy(`macro-call-recording-crud-${stack}`, {+ name: `macro-call-recording-crud-${stack}`,+ description: 'CRUD access to call recording objects',+ policy: pulumi.all([callRecordingBucket.arn]).apply(([bucketArn]) =>+ JSON.stringify({+ Version: '2012-10-17',+ Statement: [+ {+ Sid: 'ListBucket',+ Effect: 'Allow',+ Action: ['s3:ListBucket', 's3:GetBucketLocation'],+ Resource: bucketArn,+ },+ {+ Sid: 'ObjectCrud',+ Effect: 'Allow',+ Action: [+ 's3:ListBucket',+ 's3:GetObject',+ 's3:PutObject',+ 's3:DeleteObject',+ 's3:HeadObject',+ 's3:ListMultipartUploadParts',+ 's3:ListBucketMultipartUploads',+ 's3:AbortMultipartUpload',+ ],+ Resource: `${bucketArn}/*`,+ },+ ],+ })+ ),+ tags,+});++export const crudPolicyArn = crudPolicy.arn;++// Modify — bucket-level admin (policy, ACL, versioning, lifecycle, etc.)+const modifyPolicy = new aws.iam.Policy(+ `macro-call-recording-modify-${stack}`,+ {+ name: `macro-call-recording-modify-${stack}`,+ description: 'Admin/modify access to call recording bucket configuration',+ policy: pulumi.all([callRecordingBucket.arn]).apply(([bucketArn]) =>+ JSON.stringify({+ Version: '2012-10-17',+ Statement: [+ {+ Sid: 'BucketAdmin',+ Effect: 'Allow',+ Action: [+ 's3:PutBucketCORS',+ 's3:ListBucket',+ 's3:PutBucketLogging',+ 's3:PutBucketPolicy',+ 's3:DeleteBucketPolicy',+ 's3:GetBucketVersioning',+ 's3:PutBucketVersioning',+ 's3:GetBucketTagging',+ 's3:GetEncryptionConfiguration',+ 's3:PutEncryptionConfiguration',+ 's3:GetIntelligentTieringConfiguration',+ 's3:GetBucketLogging',+ 's3:GetBucketNotification',+ 's3:PutBucketNotification',+ 's3:GetAccelerateConfiguration',+ 's3:GetBucketObjectLockConfiguration',+ 's3:GetBucketRequestPayment',+ 's3:GetBucketWebsite',+ 's3:GetBucketPublicAccessBlock',+ 's3:GetBucketPolicy',+ 's3:GetBucketOwnershipControls',+ 's3:GetBucketAcl',+ 's3:PutBucketAcl',+ 's3:GetBucketCORS',+ 's3:GetAnalyticsConfiguration',+ 's3:GetReplicationConfiguration',+ 's3:PutReplicationConfiguration',+ 's3:GetLifecycleConfiguration',+ 's3:PutLifecycleConfiguration',+ 's3:GetInventoryConfiguration',+ 's3:PutInventoryConfiguration',+ 's3:DeleteInventoryConfiguration',+ 's3:DeleteBucket',+ 's3:PutBucketTagging',+ 's3:DeleteBucketTagging',+ 's3:PutBucketPublicAccessBlock',+ 's3:DeletePublicAccessBlock',+ 's3:PutBucketOwnershipControls',+ 's3:PutAccelerateConfiguration',+ 's3:PutBucketObjectLockConfiguration',+ 's3:PutAnalyticsConfiguration',+ 's3:DeleteAnalyticsConfiguration',+ 's3:PutIntelligentTieringConfiguration',+ 's3:DeleteIntelligentTieringConfiguration',+ 's3:PutBucketWebsite',+ 's3:DeleteBucketWebsite',+ 's3:PutBucketRequestPayment',+ 's3:GetMetricsConfiguration',+ 's3:PutMetricsConfiguration',+ 's3:DeleteMetricsConfiguration',+ ],+ Resource: bucketArn,+ },+ ],+ })+ ),+ tags,+ }+);++export const modifyPolicyArn = modifyPolicy.arn;++// ---------------------------------------------------------------------------+// 2. Service IAM User with CRUD access+// ---------------------------------------------------------------------------++const serviceUser = new aws.iam.User(`macro-call-recording-svc-${stack}`, {+ name: `macro-call-recording-svc-${stack}`,+ tags: { ...tags, 'call-recording-access': 'true' },+});++new aws.iam.UserPolicyAttachment(`macro-call-recording-svc-crud-${stack}`, {+ user: serviceUser.name,+ policyArn: crudPolicy.arn,+});++const serviceUserAccessKey = new aws.iam.AccessKey(+ `macro-call-recording-svc-key-${stack}`,+ {+ user: serviceUser.name,+ }+);++// Store credentials in Secrets Manager — NOT exported+const serviceUserSecret = new aws.secretsmanager.Secret(+ `macro-call-recording-svc-creds-${stack}`,+ {+ name: `macro-call-recording-svc-creds-${stack}`,+ description: 'IAM credentials for call recording bucket service user',+ tags,+ }+);++export const serviceUserSecretId = serviceUserSecret.id;+export const serviceUserSecretArn = serviceUserSecret.arn;++new aws.secretsmanager.SecretVersion(+ `macro-call-recording-svc-creds-version-${stack}`,+ {+ secretId: serviceUserSecret.id,+ secretString: pulumi+ .all([serviceUserAccessKey.id, serviceUserAccessKey.secret])+ .apply(([accessKey, secretAccessKey]) =>+ JSON.stringify({ accessKey, secretAccessKey })+ ),+ }+);++// ---------------------------------------------------------------------------+// 3. Bucket Policy — tag-based access control+// ---------------------------------------------------------------------------+// Denies all access unless the caller's principal is tagged with+// call-recording-access: "true". This blocks broad dev IAM permissions.+//+// When attaching crudPolicy or modifyPolicy to a user/role, also tag them+// with { 'call-recording-access': 'true' } to grant access.++const bucketPolicy = new aws.s3.BucketPolicy(+ `macro-call-recording-policy-${stack}`,+ {+ bucket: callRecordingBucket.id,+ policy: callRecordingBucket.arn.apply((bucketArn) =>+ JSON.stringify({+ Version: '2012-10-17',+ Statement: [+ {+ Sid: 'DenyWithoutTag',+ Effect: 'Deny',+ Principal: '*',+ Action: 's3:*',+ Resource: [bucketArn, `${bucketArn}/*`],+ Condition: {+ StringNotEquals: {+ 'aws:PrincipalTag/call-recording-access': 'true',+ },+ // Never deny the account root — prevents lockout+ ArnNotEquals: {+ 'aws:PrincipalArn': `arn:aws:iam::569036502058:root`,+ },+ },+ },+ ],+ })+ ),+ }+);++export const bucketPolicyId = bucketPolicy.id;diff --git a/infra/stacks/call-recording/package.json b/infra/stacks/call-recording/package.jsonnew file mode 100644index 0000000000..c0a3bdd86c--- /dev/null+++ b/infra/stacks/call-recording/package.json@@ -0,0 +1,7 @@+{+ "name": "call-recording-stack",+ "version": "0.0.0",+ "private": true,+ "license": "MIT",+ "main": "index.ts"+}diff --git a/infra/stacks/call-recording/tsconfig.json b/infra/stacks/call-recording/tsconfig.jsonnew file mode 100644index 0000000000..4082f16a5d--- /dev/null+++ b/infra/stacks/call-recording/tsconfig.json@@ -0,0 +1,3 @@+{+ "extends": "../../tsconfig.json"+}diff --git a/infra/stacks/cloud-storage-service/cloud-storage-service.ts b/infra/stacks/cloud-storage-service/cloud-storage-service.tsindex b0b5fd8a24..3c8f90c19f 100644--- a/infra/stacks/cloud-storage-service/cloud-storage-service.ts+++ b/infra/stacks/cloud-storage-service/cloud-storage-service.ts@@ -37,6 +37,7 @@ type CreateCloudStorageServiceServiceArgs = {healthCheckPath: string;secretKeyArns: (pulumi.Output<string> | string)[];queueArns: (pulumi.Output<string> | string)[];+ callRecordingCrudPolicyArn: pulumi.Output<string> | string;tags: { [key: string]: string };};@@ -68,6 +69,7 @@ export class CloudStorageService extends pulumi.ComponentResource {cloudStorageClusterName,secretKeyArns,queueArns,+ callRecordingCrudPolicyArn,tags,}: CreateCloudStorageServiceServiceArgs,opts?: pulumi.ComponentResourceOptions@@ -170,7 +172,7 @@ export class CloudStorageService extends pulumi.ComponentResource {},],},- tags: this.tags,+ tags: { ...this.tags, 'call-recording-access': 'true' },},{ parent: this });@@ -209,6 +211,14 @@ export class CloudStorageService extends pulumi.ComponentResource {{ parent: this, dependsOn: [queuePolicy, this.role] });+ new aws.iam.RolePolicyAttachment(+ `${BASE_NAME}-role-call-recording-att-${stack}`,+ {+ role: this.role,+ policyArn: pulumi.interpolate`${callRecordingCrudPolicyArn}`,+ }+ );+// ecr imageconst image = new EcrImage(`${BASE_NAME}-ecr-image-${stack}`,diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.tsindex a8441f22d7..dd1a0088fb 100644--- a/infra/stacks/cloud-storage-service/index.ts+++ b/infra/stacks/cloud-storage-service/index.ts@@ -281,6 +281,39 @@ const INTERNAL_CALL_SECRET = aws.secretsmanager.getSecretVersionOutput({ secretId: config.require('call_internal_secret') }).apply((secret) => secret.secretString);+const callRecordingStack = new pulumi.StackReference('call-recording-stack', {+ name: `macro-inc/call-recording/${stack}`,+});++const callRecordingCrudPolicyArn: pulumi.Output<string> = callRecordingStack+ .getOutput('crudPolicyArn')+ .apply((t) => t as string);++const CALL_RECORDING_S3_BUCKET: pulumi.Output<string> = callRecordingStack+ .getOutput('callRecordingBucketId')+ .apply((t) => t as string);++const CALL_RECORDING_S3_REGION = 'us-east-1';+const callRecordingServiceUserSecretId: pulumi.Output<string> =+ callRecordingStack.getOutput('serviceUserSecretId').apply((t) => t as string);++const callRecordingCreds = aws.secretsmanager+ .getSecretVersionOutput({ secretId: callRecordingServiceUserSecretId })+ .apply(+ (secret) =>+ JSON.parse(secret.secretString) as {+ accessKey: string;+ secretAccessKey: string;+ }+ );++const CALL_RECORDING_S3_ACCESS_KEY = callRecordingCreds.apply(+ (c) => c.accessKey+);+const CALL_RECORDING_S3_SECRET = callRecordingCreds.apply(+ (c) => c.secretAccessKey+);+const cloudStorageService = new CloudStorageService(`cloud-storage-service-${stack}`,{@@ -313,7 +346,24 @@ const cloudStorageService = new CloudStorageService(githubWebhookSecretKeyArn,githubSyncAppPemArn,],+ callRecordingCrudPolicyArn,containerEnvVars: [+ {+ name: 'CALL_RECORDING_S3_BUCKET',+ value: pulumi.interpolate`${CALL_RECORDING_S3_BUCKET}`,+ },+ {+ name: 'CALL_RECORDING_S3_REGION',+ value: CALL_RECORDING_S3_REGION,+ },+ {+ name: 'CALL_RECORDING_S3_ACCESS_KEY',+ value: CALL_RECORDING_S3_ACCESS_KEY,+ },+ {+ name: 'CALL_RECORDING_S3_SECRET',+ value: CALL_RECORDING_S3_SECRET,+ },{name: 'INTERNAL_CALL_SECRET',value: pulumi.interpolate`${INTERNAL_CALL_SECRET}`,diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rsindex dbae5381c8..7366365308 100644--- a/rust/cloud-storage/document_storage_service/src/config.rs+++ b/rust/cloud-storage/document_storage_service/src/config.rs@@ -77,6 +77,23 @@ maybe_env_var! {pub struct InternalCallSecret;}+maybe_env_var! {+ /// S3 bucket for call recording egress.+ pub struct CallRecordingS3Bucket;+}+maybe_env_var! {+ /// AWS region for the call recording S3 bucket.+ pub struct CallRecordingS3Region;+}+maybe_env_var! {+ /// AWS access key for call recording S3 uploads.+ pub struct CallRecordingS3AccessKey;+}+maybe_env_var! {+ /// AWS secret key for call recording S3 uploads.+ pub struct CallRecordingS3Secret;+}+env_var! { struct Port; }env_var! { struct DocumentLimit; }env_var! { struct DocumentStorageServicePresignedUrlExpirySeconds; }diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex af1b93fa0b..79cd7c0f3b 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -374,7 +374,24 @@ async fn main() -> anyhow::Result<()> {if let Some(secret) = internal_call_secret {call_service_builder = call_service_builder.with_internal_call_secret(secret);}+ if let (Some(bucket), Some(region), Some(access_key), Some(secret)) = (+ config::CallRecordingS3Bucket::new(),+ config::CallRecordingS3Region::new(),+ config::CallRecordingS3AccessKey::new(),+ config::CallRecordingS3Secret::new(),+ ) {+ tracing::info!(bucket = bucket.as_ref(), "call recording enabled");+ call_service_builder =+ call_service_builder.with_egress(call::domain::models::EgressS3Config {+ bucket: bucket.as_ref().to_string(),+ region: region.as_ref().to_string(),+ access_key: access_key.as_ref().to_string(),+ secret: secret.as_ref().to_string(),+ });+ }+let call_service = Arc::new(call_service_builder);+let call_state = CallRouterState::new(call_service.clone(), entity_access_service.clone());let call_webhook_state = WebhookRouterState::new(call_service.clone());let call_internal_state = InternalCallRouterState::new(call_service.clone());