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
refactor: internal api key (#4329)
Will Hutchinson9360b879da5d
diff --git a/infra/biome.jsonc b/infra/biome.jsoncindex dadb850294..a2edc47904 100644--- a/infra/biome.jsonc+++ b/infra/biome.jsonc@@ -1,5 +1,5 @@{- "$schema": "https://biomejs.dev/schemas/2.4.12/schema.json",+ "$schema": "https://biomejs.dev/schemas/2.4.16/schema.json","vcs": {"clientKind": "git","enabled": true,diff --git a/infra/packages/shared/src/ai_tools.ts b/infra/packages/shared/src/ai_tools.tsindex cb47f6980d..9debb86f1a 100644--- a/infra/packages/shared/src/ai_tools.ts+++ b/infra/packages/shared/src/ai_tools.ts@@ -1,6 +1,6 @@import * as aws from '@pulumi/aws';import * as pulumi from '@pulumi/pulumi';-import { config, getServiceUrl, ServiceUrl, stack } from '../../shared';+import { stack } from '../../shared';/*** Infrastructure wiring required by services that host the `ai_tools` crate@@ -9,7 +9,6 @@ import { config, getServiceUrl, ServiceUrl, stack } from '../../shared';* service-specific values.*/export type AiToolsInfra = {- envVars: { name: string; value: pulumi.Output<string> | string }[];secretArns: pulumi.Output<string>[];queueArns: pulumi.Output<string>[];bucketArns: pulumi.Output<string>[];@@ -34,46 +33,23 @@ export function getAiToolsInfra(): AiToolsInfra {'ai-tools-email-service-stack',{ name: `macro-inc/email-service/${stack}` });- const linksharingStack = new pulumi.StackReference(- 'ai-tools-linksharing-stack',- { name: `macro-inc/link-sharing/${stack}` }- );- const documentStorageBucketId: pulumi.Output<string> = cloudStorageStack- .getOutput('documentStorageBucketId')- .apply((v) => v as string);const documentStorageBucketArn: pulumi.Output<string> = cloudStorageStack.getOutput('documentStorageBucketArn').apply((v) => v as string);- const docxUploadBucketName: pulumi.Output<string> = cloudStorageServiceStack- .getOutput('docxUploadBucketName')- .apply((v) => v as string);const docxUploadBucketArn: pulumi.Output<string> = cloudStorageServiceStack.getOutput('docxUploadBucketArn').apply((v) => v as string);- const emailScheduledQueueName: pulumi.Output<string> = emailServiceStack- .getOutput('scheduledQueueName')- .apply((v) => v as string);const emailScheduledQueueArn: pulumi.Output<string> = emailServiceStack.getOutput('scheduledQueueArn').apply((v) => v as string);- const gmailOpsQueueName: pulumi.Output<string> = emailServiceStack- .getOutput('gmailOpsQueueName')- .apply((v) => v as string);const gmailOpsQueueArn: pulumi.Output<string> = emailServiceStack.getOutput('gmailOpsQueueArn').apply((v) => v as string);- const cloudfrontDistributionUrl: pulumi.Output<string> = linksharingStack- .getOutput('cloudfrontDistributionUrl')- .apply((v) => v as string);- const cloudfrontSignerPublicKeyId: pulumi.Output<string> = linksharingStack- .getOutput('cloudfrontDistributionPublicKeyId')- .apply((v) => v as string);-const CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME = `linksharing-private-key-${stack}`;const cloudfrontPrivateKeySecretArn: pulumi.Output<string> =aws.secretsmanager@@ -90,125 +66,7 @@ export function getAiToolsInfra(): AiToolsInfra {.getSecretOutput({ name: MCP_CREDENTIALS_KEY_SECRET_NAME }).apply((s) => s.arn);- const INTERNAL_AUTH_KEY_SECRET_NAME = `document-storage-service-auth-key-${stack}`;- const internalAuthKey: pulumi.Output<string> = aws.secretsmanager- .getSecretVersionOutput({ secretId: INTERNAL_AUTH_KEY_SECRET_NAME })- .apply((s) => s.secretString);-- const SLACK_MCP_CLIENT_ID = aws.secretsmanager- .getSecretVersionOutput({ secretId: 'slack-mcp-client-id' })- .apply((secret) => secret.secretString);-- const SLACK_MCP_CLIENT_SECRET = aws.secretsmanager- .getSecretVersionOutput({ secretId: 'slack-mcp-client-secret' })- .apply((secret) => secret.secretString);-- const GITHUB_CLIENT_ID = aws.secretsmanager- .getSecretVersionOutput({ secretId: `github-client-id-${stack}` })- .apply((secret) => secret.secretString);-- const GITHUB_CLIENT_SECRET = aws.secretsmanager- .getSecretVersionOutput({ secretId: `github-client-secret-${stack}` })- .apply((secret) => secret.secretString);-- const OPENAI_API_KEY = aws.secretsmanager- .getSecretVersionOutput({ secretId: config.require('openai_api_key') })- .apply((secret) => secret.secretString);-- const ANTHROPIC_API_KEY = aws.secretsmanager- .getSecretVersionOutput({ secretId: config.require('anthropic_api_key') })- .apply((secret) => secret.secretString);-- const envVars: AiToolsInfra['envVars'] = [- {- name: 'INTERNAL_API_SECRET_KEY',- value: pulumi.interpolate`${internalAuthKey}`,- },- {- name: 'DOCUMENT_STORAGE_SERVICE_AUTH_KEY',- value: pulumi.interpolate`${internalAuthKey}`,- },- {- name: ServiceUrl.DOCUMENT_STORAGE_SERVICE_URL,- value: getServiceUrl(ServiceUrl.DOCUMENT_STORAGE_SERVICE_URL),- },- {- name: ServiceUrl.EMAIL_SERVICE_URL,- value: getServiceUrl(ServiceUrl.EMAIL_SERVICE_URL),- },- {- name: ServiceUrl.SYNC_SERVICE_URL,- value: getServiceUrl(ServiceUrl.SYNC_SERVICE_URL),- },- {- name: ServiceUrl.LEXICAL_SERVICE_URL,- value: getServiceUrl(ServiceUrl.LEXICAL_SERVICE_URL),- },- {- name: ServiceUrl.STATIC_FILE_SERVICE_URL,- value: getServiceUrl(ServiceUrl.STATIC_FILE_SERVICE_URL),- },- { name: 'SYNC_SERVICE_AUTH_KEY', value: SYNC_SERVICE_AUTH_KEY_SECRET_NAME },- {- name: 'MCP_CREDENTIALS_KEY_SECRET_NAME',- value: MCP_CREDENTIALS_KEY_SECRET_NAME,- },- {- name: 'DOCUMENT_STORAGE_BUCKET',- value: pulumi.interpolate`${documentStorageBucketId}`,- },- {- name: 'DOCX_DOCUMENT_UPLOAD_BUCKET',- value: pulumi.interpolate`${docxUploadBucketName}`,- },- {- name: 'EMAIL_SCHEDULED_QUEUE',- value: pulumi.interpolate`${emailScheduledQueueName}`,- },- {- name: 'GMAIL_OPS_QUEUE',- value: pulumi.interpolate`${gmailOpsQueueName}`,- },- {- name: 'DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL',- value: pulumi.interpolate`${cloudfrontDistributionUrl}`,- },- {- name: 'DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID',- value: pulumi.interpolate`${cloudfrontSignerPublicKeyId}`,- },- {- name: 'DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME',- value: CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME,- },- {- name: 'SLACK_MCP_CLIENT_ID',- value: pulumi.interpolate`${SLACK_MCP_CLIENT_ID}`,- },- {- name: 'SLACK_MCP_CLIENT_SECRET',- value: pulumi.interpolate`${SLACK_MCP_CLIENT_SECRET}`,- },- {- name: 'GITHUB_CLIENT_SECRET',- value: pulumi.interpolate`${GITHUB_CLIENT_SECRET}`,- },- {- name: 'GITHUB_CLIENT_ID',- value: pulumi.interpolate`${GITHUB_CLIENT_ID}`,- },- {- name: 'OPENAI_API_KEY',- value: pulumi.interpolate`${OPENAI_API_KEY}`,- },- {- name: 'ANTHROPIC_API_KEY',- value: pulumi.interpolate`${ANTHROPIC_API_KEY}`,- },- ];-return {- envVars,secretArns: [syncServiceAuthKeyArn,cloudfrontPrivateKeySecretArn,diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.tsindex 13a5044848..55bcca39b7 100644--- a/infra/stacks/cloud-storage-service/index.ts+++ b/infra/stacks/cloud-storage-service/index.ts@@ -51,9 +51,6 @@ const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);const internalApiSecret = aws.secretsmanager.getSecretVersionOutput({secretId: INTERNAL_API_SECRET_KEY,});-const internalApiKeyArn: pulumi.Output<string> = internalApiSecret.apply(- (secret) => secret.arn-);const internalApiSecretValue: pulumi.Output<string> = internalApiSecret.apply((secret) => secret.secretString);@@ -267,7 +264,6 @@ const cloudStorageService = new CloudStorageService(jwtSecretKeyArn,documentStoragePermissionsKeyArn,cloudfrontPrivateKeySecretArn,- internalApiKeyArn,syncServiceAuthKeyArn,MACRO_API_TOKENS.macroApiTokenPublicKeyArn,githubWebhookSecretKeyArn,diff --git a/infra/stacks/contacts-service/index.ts b/infra/stacks/contacts-service/index.tsindex 826832076e..2e2a2b2618 100644--- a/infra/stacks/contacts-service/index.ts+++ b/infra/stacks/contacts-service/index.ts@@ -25,16 +25,10 @@ const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager.getSecretVersionOutput({ secretId: JWT_SECRET_KEY }).apply((secret) => secret.arn);-const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);-const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager- .getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY })- .apply((secret) => secret.arn);-let MACRO_API_TOKENS = getMacroApiToken();const secretKeyArns = [pulumi.interpolate`${jwtSecretKeyArn}`,- pulumi.interpolate`${internalApiKeyArn}`,MACRO_API_TOKENS.macroApiTokenPublicKeyArn,];diff --git a/infra/stacks/convert-service/index.ts b/infra/stacks/convert-service/index.tsindex d20138009f..e4eb70d6db 100644--- a/infra/stacks/convert-service/index.ts+++ b/infra/stacks/convert-service/index.ts@@ -1,7 +1,6 @@-import * as aws from '@pulumi/aws';import * as pulumi from '@pulumi/pulumi';import { Queue } from '../../packages/resources';-import { config, stack } from '../../packages/shared';+import { stack } from '../../packages/shared';import { get_coparse_api_vpc } from '../../packages/vpc';import { ConvertService } from './service';@@ -21,13 +20,6 @@ export const convertQueueName = convertQueue.queue.name;export const coparse_api_vpc = get_coparse_api_vpc();-const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);-const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager- .getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY })- .apply((secret) => secret.arn);--const secretKeyArns = [pulumi.interpolate`${internalApiKeyArn}`];-const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {name: `macro-inc/document-storage/${stack}`,});@@ -88,7 +80,6 @@ const convertService = new ConvertService('convert-service', {isPrivate: false,ecsClusterArn: cloudStorageClusterArn,cloudStorageClusterName,- secretKeyArns,});export const convertServiceRoleArn = pulumi.interpolate`${convertService.role.arn}`;diff --git a/infra/stacks/convert-service/service.ts b/infra/stacks/convert-service/service.tsindex 578a277157..3be9adb9d8 100644--- a/infra/stacks/convert-service/service.ts+++ b/infra/stacks/convert-service/service.ts@@ -38,7 +38,6 @@ type CreateConvertServiceArgs = {isPrivate?: boolean;ecsClusterArn: pulumi.Output<string> | string;cloudStorageClusterName: pulumi.Output<string> | string;- secretKeyArns: (pulumi.Output<string> | string)[];jobUpdateHandlerLambdaArn: pulumi.Output<string> | string;};@@ -68,7 +67,6 @@ export class ConvertService extends pulumi.ComponentResource {ecsClusterArn,containerEnvVars,cloudStorageClusterName,- secretKeyArns,jobUpdateHandlerLambdaArn,}: CreateConvertServiceArgs,opts?: pulumi.ComponentResourceOptions@@ -78,28 +76,6 @@ export class ConvertService extends pulumi.ComponentResource {this.tags = tags;this.cloudStorageClusterName = cloudStorageClusterName;- const secretsManagerPolicy = new aws.iam.Policy(- `${BASE_NAME}-secrets-manager-policy`,- {- name: `${BASE_NAME}-secrets-manager-policy-${stack}`,- policy: {- Version: '2012-10-17',- Statement: [- {- Action: [- 'secretsmanager:GetSecretValue',- 'secretsmanager:DescribeSecret',- ],- Resource: [...secretKeyArns],- Effect: 'Allow',- },- ],- },- tags: this.tags,- },- { parent: this }- );-const queuePolicy = new aws.iam.Policy(`${BASE_NAME}-sqs-policy`,{@@ -156,11 +132,7 @@ export class ConvertService extends pulumi.ComponentResource {],},tags: this.tags,- managedPolicyArns: [- secretsManagerPolicy.arn,- queuePolicy.arn,- lambdaInvokePolicy.arn,- ],+ managedPolicyArns: [queuePolicy.arn, lambdaInvokePolicy.arn],},{ parent: this });diff --git a/infra/stacks/notification-service/index.ts b/infra/stacks/notification-service/index.tsindex 5790be995a..137e692809 100644--- a/infra/stacks/notification-service/index.ts+++ b/infra/stacks/notification-service/index.ts@@ -17,11 +17,6 @@ const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager.getSecretVersionOutput({ secretId: JWT_SECRET_KEY }).apply((secret) => secret.arn);-const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);-const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager- .getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY })- .apply((secret) => secret.arn);-const appleTeamId = config.require(`apple_team_id`);const APPLE_TEAM_ID = aws.secretsmanager.getSecretVersionOutput({ secretId: appleTeamId })@@ -154,7 +149,6 @@ const notificationService = new NotificationService('notification-service', {cloudStorageClusterName,secretKeyArns: [jwtSecretKeyArn,- internalApiKeyArn,MACRO_API_TOKENS.macroApiTokenPublicKeyArn,authenticationServiceInternalApiKeyArn,unsubscribeHmacSecretArn,diff --git a/infra/stacks/static-file-service/index.ts b/infra/stacks/static-file-service/index.tsindex c684090212..1785385c85 100644--- a/infra/stacks/static-file-service/index.ts+++ b/infra/stacks/static-file-service/index.ts@@ -17,11 +17,6 @@ const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager.getSecretVersionOutput({ secretId: JWT_SECRET_KEY }).apply((secret) => secret.arn);-const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);-const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager- .getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY })- .apply((secret) => secret.arn);-export const coparse_api_vpc = get_coparse_api_vpc();const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {@@ -65,11 +60,7 @@ const staticFileService = new StaticFileService(`${SERVICE_NAME}-${stack}`, {family: 'linux',architecture: 'amd64',},- secretKeyArns: [- jwtSecretKeyArn,- internalApiKeyArn,- MACRO_API_TOKENS.macroApiTokenPublicKeyArn,- ],+ secretKeyArns: [jwtSecretKeyArn, MACRO_API_TOKENS.macroApiTokenPublicKeyArn],healthCheckPath: '/api/health',serviceContainerPort: 8080,tags,diff --git a/rust/cloud-storage/authentication_service/src/api/context.rs b/rust/cloud-storage/authentication_service/src/api/context.rsindex aff56fb293..e418f02316 100644--- a/rust/cloud-storage/authentication_service/src/api/context.rs+++ b/rust/cloud-storage/authentication_service/src/api/context.rs@@ -14,7 +14,7 @@ use macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_cache_client::MacroCache;use macro_env::Environment;use macro_env_var::env_var;-use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;use native_app_service::{domain::service::NativeAppServiceImpl, outbound::DefaultBundleFetcher};use notification::outbound::queue::SqsQueue;use notification::{@@ -75,7 +75,7 @@ pub(crate) struct ApiContext {pub environment: Environment,pub jwt_args: JwtValidationArgs,pub token_context: MacroApiTokenContext,- pub internal_api_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub stripe_webhook_secret: LocalOrRemoteSecret<StripeWebhookSecretKey>,pub user_roles_and_permissions_service:Arc<UserRolesAndPermissionsServiceImpl<MacroDB, MacroDB>>, // Note: since FromRef doesn't support generics we have to specify the concrete types herediff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rsindex d610abd53b..f0361a9910 100644--- a/rust/cloud-storage/authentication_service/src/config.rs+++ b/rust/cloud-storage/authentication_service/src/config.rs@@ -4,6 +4,7 @@ use anyhow::Context;use database_env_vars::{DatabaseUrl, RedisUri};pub use macro_env::Environment;use macro_env_var::{env_vars, maybe_env_vars};+use macro_middleware::auth::internal_access::InternalApiKey;// BASE_URL config value. This is validated when creating the config in main.rspub static BASE_URL: LazyLock<String> = LazyLock::new(|| {@@ -120,6 +121,8 @@ pub struct Config {pub posthog_host: PosthogHost,/// The stripe price idpub stripe_price_id: StripePriceId,+ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rsindex 42a3fedc05..ff5e89f21c 100644--- a/rust/cloud-storage/authentication_service/src/main.rs+++ b/rust/cloud-storage/authentication_service/src/main.rs@@ -19,7 +19,6 @@ use github::{};use macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_entrypoint::MacroEntrypoint;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use macro_service_urls::AppServiceUrl;use macro_service_urls::DocumentStorageServiceUrl;use native_app_service::{@@ -69,17 +68,15 @@ async fn main() -> anyhow::Result<()> {aws_sdk_secretsmanager::Client::new(¯o_aws_config::get_macro_aws_config().await),);- let internal_api_key = secretsmanager_client- .get_maybe_secret_value(env, InternalApiSecretKey::new()?)- .await?;+ // Parse our configuration from the environment.+ let config = Config::from_env().context("expected to be able to generate config")?;++ let internal_api_key = config.internal_api_key.clone();let stripe_webhook_secret = secretsmanager_client.get_maybe_secret_value(env, StripeWebhookSecretKey::new()?).await?;- // Parse our configuration from the environment.- let config = Config::from_env().context("expected to be able to generate config")?;-tracing::trace!("initialized config");let (min_connections, max_connections): (u32, u32) = match config.environment {diff --git a/rust/cloud-storage/connection_gateway/src/config.rs b/rust/cloud-storage/connection_gateway/src/config.rsindex d161fbf0d0..bc4b5b7f18 100644--- a/rust/cloud-storage/connection_gateway/src/config.rs+++ b/rust/cloud-storage/connection_gateway/src/config.rs@@ -1,6 +1,7 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::env_vars;+use macro_middleware::auth::internal_access::InternalApiKey;use secretsmanager_client::LocalOrRemoteSecret;env_vars! {@@ -26,6 +27,8 @@ pub struct Config {pub environment: Environment,pub redis_host: RedisHost,pub macro_db_url: LocalOrRemoteSecret<MacroDbUrl>,+ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/connection_gateway/src/context.rs b/rust/cloud-storage/connection_gateway/src/context.rsindex 6d4e9075e7..c0521f72a2 100644--- a/rust/cloud-storage/connection_gateway/src/context.rs+++ b/rust/cloud-storage/connection_gateway/src/context.rs@@ -7,9 +7,8 @@ use frecency::{};use last_online_tracker::inbound::LastOnlineWorker;use macro_auth::middleware::decode_jwt::JwtValidationArgs;-use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;use redis::{RedisError, aio::MultiplexedConnection};-use secretsmanager_client::LocalOrRemoteSecret;use std::sync::Arc;use stream::domain::StreamManager;@@ -34,7 +33,7 @@ pub struct AppState {pub context: ApiContext,pub config: Arc<Config>,pub jwt_args: JwtValidationArgs,- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub frecency_worker: Arc<FrecencyAggregatorWorkerHandle>,}diff --git a/rust/cloud-storage/connection_gateway/src/main.rs b/rust/cloud-storage/connection_gateway/src/main.rsindex c620c7b8a7..b9cb8aeac2 100644--- a/rust/cloud-storage/connection_gateway/src/main.rs+++ b/rust/cloud-storage/connection_gateway/src/main.rs@@ -31,8 +31,6 @@ use last_online_tracker::{use macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_entrypoint::MacroEntrypoint;use macro_env::Environment;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;use service::dynamodb::create_dynamo_db_connection_manager;use service::redis::poll_messages;use sqlx::postgres::PgPoolOptions;@@ -123,9 +121,9 @@ async fn main() -> Result<()> {let app = router(AppState {context,+ internal_api_key: config.internal_api_key.clone(),config: Arc::clone(&config),jwt_args,- internal_auth_key: LocalOrRemoteSecret::Local(InternalApiSecretKey::new()?),frecency_worker: Arc::new(FrecencyAggregatorWorkerHandle::new_worker(PullAggregatorImpl::new(FrecencyPgProcessor::new(pgpool), DefaultTime),Duration::from_secs(60),diff --git a/rust/cloud-storage/contacts_service/src/config.rs b/rust/cloud-storage/contacts_service/src/config.rsindex 3200e99ea0..656b939083 100644--- a/rust/cloud-storage/contacts_service/src/config.rs+++ b/rust/cloud-storage/contacts_service/src/config.rs@@ -2,6 +2,7 @@ use anyhow::Context;use database_env_vars::{DatabaseUrl, RedisUri};pub use macro_env::Environment;use macro_env_var::{env_vars, maybe_env_vars};+use macro_middleware::auth::internal_access::InternalApiKey;env_vars! {pub struct BaseUrl;@@ -32,6 +33,8 @@ pub struct Config {pub contacts_queue_max_messages: ContactsQueueMaxMessages,/// The notification queue wait time secondspub contacts_queue_wait_time_seconds: ContactsQueueWaitTimeSeconds,+ /// The internal api key value.+ pub internal_api_key: InternalApiKey,}impl Config {@@ -51,6 +54,7 @@ impl Config {contacts_queue: ContactsQueue::new_testing(""),contacts_queue_max_messages: ContactsQueueMaxMessages::new_unset(),contacts_queue_wait_time_seconds: ContactsQueueWaitTimeSeconds::new_unset(),+ internal_api_key: InternalApiKey::Comptime(""),}}}diff --git a/rust/cloud-storage/contacts_service/src/main.rs b/rust/cloud-storage/contacts_service/src/main.rsindex c6a5a0bf2d..5d79bc556d 100644--- a/rust/cloud-storage/contacts_service/src/main.rs+++ b/rust/cloud-storage/contacts_service/src/main.rs@@ -11,10 +11,8 @@ use contacts::inbound::worker::{ContactsWorker, OutboxWorker};use contacts::outbound::gateway::ConnectionGatewayNotifier;use contacts::outbound::repository::DbContactsRepository;use macro_entrypoint::MacroEntrypoint;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use macro_service_urls::ConnectionGatewayUrl;use rate_limit::{RateLimitServiceImpl, RedisRateLimitAdapter};-use secretsmanager_client::SecretManager;use sqlx::postgres::PgPoolOptions;use sqs_worker::SQSWorker;use utoipa::OpenApi;@@ -72,13 +70,9 @@ async fn main() -> anyhow::Result<()> {aws_sdk_secretsmanager::Client::new(¯o_aws_config::get_macro_aws_config().await),);- let internal_api_secret = secretsmanager_client- .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?)- .await?;-let notifier = Some(ConnectionGatewayNotifier::new(- internal_api_secret.as_ref().to_string(),+ config.internal_api_key.to_string(),ConnectionGatewayUrl::new()?.to_string(),).unwrap(),diff --git a/rust/cloud-storage/convert_service/src/api/context.rs b/rust/cloud-storage/convert_service/src/api/context.rsindex 4829eb98a0..9a0460204b 100644--- a/rust/cloud-storage/convert_service/src/api/context.rs+++ b/rust/cloud-storage/convert_service/src/api/context.rs@@ -1,6 +1,5 @@use axum::extract::FromRef;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use remote_env_var::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use s3_client::S3;use std::sync::Arc;@@ -11,6 +10,6 @@ pub struct ApiContext {pub db: sqlx::PgPool,pub s3_client: S3,pub sqs_client: Arc<sqs_client::SQS>,- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub config: Arc<Config>,}diff --git a/rust/cloud-storage/convert_service/src/api/mod.rs b/rust/cloud-storage/convert_service/src/api/mod.rsindex e14a9d498f..bd50b11b1b 100644--- a/rust/cloud-storage/convert_service/src/api/mod.rs+++ b/rust/cloud-storage/convert_service/src/api/mod.rs@@ -1,8 +1,7 @@use anyhow::Context;use axum::Router;use context::ApiContext;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use remote_env_var::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use tower::ServiceBuilder;use tower_http::trace::TraceLayer;use utoipa::OpenApi;@@ -23,7 +22,7 @@ pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {let port = state.config.port;let env = state.config.environment;- let app = api_router(state.internal_auth_key.clone())+ let app = api_router(state.internal_api_key.clone()).with_state(state).layer(cors.clone()).layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))@@ -44,7 +43,7 @@ pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {.context("error starting service")}-fn api_router(internal_api_key: LocalOrRemoteSecret<InternalApiSecretKey>) -> Router<ApiContext> {+fn api_router(internal_api_key: InternalApiKey) -> Router<ApiContext> {Router::new().nest("/internal",Router::new()diff --git a/rust/cloud-storage/convert_service/src/config.rs b/rust/cloud-storage/convert_service/src/config.rsindex b71c3a7b93..7b910cb7a8 100644--- a/rust/cloud-storage/convert_service/src/config.rs+++ b/rust/cloud-storage/convert_service/src/config.rs@@ -4,6 +4,7 @@ use anyhow::Context;use database_env_vars::DatabaseUrl;pub use macro_env::Environment;use macro_env_var::env_vars;+use macro_middleware::auth::internal_access::InternalApiKey;/// The path to the LibreOffice binarypub static LOK_PATH: LazyLock<String> = LazyLock::new(|| {@@ -66,6 +67,9 @@ pub struct Config {/// The environment we are in#[macro_config_default(Environment::new_or_prod())]pub environment: Environment,++ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/convert_service/src/main.rs b/rust/cloud-storage/convert_service/src/main.rsindex b43b5df0b0..90803f6ab9 100644--- a/rust/cloud-storage/convert_service/src/main.rs+++ b/rust/cloud-storage/convert_service/src/main.rs@@ -3,9 +3,7 @@ use crate::api::context::ApiContext;use anyhow::Context;use config::{Config, Environment};use macro_entrypoint::MacroEntrypoint;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use process::runner::run_worker;-use secretsmanager_client::SecretManager;use sqlx::postgres::PgPoolOptions;use std::sync::Arc;@@ -68,14 +66,6 @@ async fn main() -> anyhow::Result<()> {let aws_config = macro_aws_config::get_macro_aws_config().await;- let secretsmanager_client = secretsmanager_client::SecretsManager::new(- aws_sdk_secretsmanager::Client::new(&aws_config),- );-- let internal_auth_key = secretsmanager_client- .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?)- .await?;-let db = PgPoolOptions::new().min_connections(1).max_connections(5)@@ -111,8 +101,8 @@ async fn main() -> anyhow::Result<()> {api::setup_and_serve(ApiContext {db,s3_client,+ internal_api_key: config.internal_api_key.clone(),sqs_client: Arc::new(sqs_client),- internal_auth_key,config: Arc::new(config),}).await?;diff --git a/rust/cloud-storage/document_cognition_service/src/api/context/mod.rs b/rust/cloud-storage/document_cognition_service/src/api/context/mod.rsindex 8eab307a67..eba48a0f10 100644--- a/rust/cloud-storage/document_cognition_service/src/api/context/mod.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/context/mod.rs@@ -18,12 +18,11 @@ use documents::inbound::attachment::DocumentAttachmentService;use email::inbound::attachment::EmailAttachmentService;use entity_access::{domain::service::EntityAccessServiceImpl, outbound::PgAccessRepository};use macro_auth::middleware::decode_jwt::JwtValidationArgs;-use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;use notification::domain::service::SqsNotificationIngress;use notification::outbound::queue::SqsQueue;use notification::outbound::websocket::ConnectionGatewayClient;use search_service_client::SearchServiceClient;-use secretsmanager_client::LocalOrRemoteSecret;use sqlx::PgPool;use static_file::inbound::attachment::StaticFileAttachmentService;use static_file::outbound::CdnStaticFileRepo;@@ -85,7 +84,7 @@ pub struct ApiContext {pub email_service_client_external: Arc<email_service_client::EmailServiceClientExternal>,pub jwt_args: JwtValidationArgs,pub config: Arc<Config>,- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub notification_ingress_service: Arc<NotificationIngressType>,pub connection_repo: Arc<dyn ConnectionRepo>,pub connection_gateway_client: Arc<ConnectionGatewayClient>,diff --git a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs b/rust/cloud-storage/document_cognition_service/src/api/context/test.rsindex 91cf473a95..ac0355ca79 100644--- a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs@@ -371,7 +371,7 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Aremail_service_client_external,jwt_args: JwtValidationArgs::new_testing(),config: Arc::new(Config::new_empty_for_test()),- internal_auth_key: LocalOrRemoteSecret::Local(InternalApiSecretKey::Comptime("testing")),+ internal_api_key: InternalApiKey::Comptime("testing"),notification_ingress_service,connection_repo: MockConnectionRepo::new(),connection_gateway_client: Arc::new(diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rsindex ad032433e8..135dfb6bca 100644--- a/rust/cloud-storage/document_cognition_service/src/config.rs+++ b/rust/cloud-storage/document_cognition_service/src/config.rs@@ -1,6 +1,7 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::{env_vars, maybe_env_vars};+use macro_middleware::auth::internal_access::InternalApiKey;use secretsmanager_client::LocalOrRemoteSecret;use crate::core::constants::DEFAULT_DOCUMENT_BATCH_LIMIT;@@ -81,6 +82,8 @@ pub struct Config {LocalOrRemoteSecret<DocumentStorageServiceCloudfrontSignerPrivateKey>,/// MCP credentials encryption key (base64-encoded, secret name or value)pub mcp_credentials_key_secret_name: LocalOrRemoteSecret<McpCredentialsKeySecretName>,+ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {@@ -135,6 +138,7 @@ impl Config {mcp_credentials_key_secret_name: LocalOrRemoteSecret::Local(McpCredentialsKeySecretName::Comptime("MCP_CREDENTIALS_KEY_SECRET_NAME"),),+ internal_api_key: InternalApiKey::Comptime(""),}}}diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rsindex 1317b2276e..993cb693a5 100644--- a/rust/cloud-storage/document_cognition_service/src/main.rs+++ b/rust/cloud-storage/document_cognition_service/src/main.rs@@ -29,7 +29,6 @@ use frecency::domain::services::FrecencyQueryServiceImpl;use frecency::outbound::postgres::FrecencyPgStorage;use macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_entrypoint::MacroEntrypoint;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use macro_service_urls::{ConnectionGatewayUrl, DocumentCognitionServiceUrl, DocumentStorageServiceUrl, EmailServiceUrl,LexicalServiceUrl, StaticFileServiceUrl, SyncServiceUrl,@@ -103,9 +102,7 @@ async fn main() -> anyhow::Result<()> {.search_event_queue(&config.search_event_queue).ai_projection_queue(&config.ai_projection_queue);- let internal_auth_key = secretsmanager_client::LocalOrRemoteSecret::Local(- InternalApiSecretKey::new().context("failed to create internal auth key")?,- );+ let internal_api_key = config.internal_api_key.to_string();let document_storage_client = DocumentStorageServiceClient::new(config@@ -138,12 +135,12 @@ async fn main() -> anyhow::Result<()> {.context("failed to create jwt validation args")?;let lexical_client = Arc::new(lexical_client::LexicalClient::new(- internal_auth_key.as_ref().to_string(),+ internal_api_key.clone(),LexicalServiceUrl::new()?.to_string(),));let email_service_client = Arc::new(EmailServiceClient::new(- internal_auth_key.as_ref().to_string(),+ internal_api_key.clone(),EmailServiceUrl::new()?.to_string(),));@@ -174,7 +171,7 @@ async fn main() -> anyhow::Result<()> {tracing::info!("initialized connection repo");let connection_gateway_client = Arc::new(ConnectionGatewayClient::new(- internal_auth_key.as_ref().to_string(),+ internal_api_key.clone(),ConnectionGatewayUrl::new()?.to_string(),));@@ -483,8 +480,8 @@ async fn main() -> anyhow::Result<()> {document_storage_client: Arc::new(document_storage_client),search_service_client,jwt_args,+ internal_api_key: config.internal_api_key.clone(),config: Arc::new(config),- internal_auth_key,notification_ingress_service,connection_repo: connection_manager.persistence,connection_gateway_client,diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rsindex b012150a27..96074212c6 100644--- a/rust/cloud-storage/document_storage_service/src/config.rs+++ b/rust/cloud-storage/document_storage_service/src/config.rs@@ -1,6 +1,7 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::{env_vars, maybe_env_vars};+use macro_middleware::auth::internal_access::InternalApiKey;use secretsmanager_client::LocalOrRemoteSecret;pub const DEFAULT_PRESIGNED_URL_EXPIRY_SECONDS: u64 = 900; // 15 minutes@@ -47,7 +48,6 @@ env_vars! {pub struct MetaAccessToken;#[derive(Clone)]pub struct DocumentStorageServiceAuthKey;- pub struct InternalApiSecretKey;}maybe_env_vars! {@@ -108,8 +108,9 @@ pub struct Config {pub meta_pixel_id: MetaPixelId,pub meta_access_token: MetaAccessToken,pub document_storage_service_auth_key: DocumentStorageServiceAuthKey,- pub internal_api_secret_key: LocalOrRemoteSecret<InternalApiSecretKey>,- // pub vars: EnvVars,+ /// The internal api key+ pub internal_api_key: InternalApiKey,+/// The port to listen for HTTP requests on.#[macro_config_default(8080)]pub port: usize,diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex 346768243c..f0e4b44c47 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -201,7 +201,7 @@ async fn main() -> anyhow::Result<()> {let dss_auth_key = DocumentStorageServiceAuthKey::new()?;let conn_gateway_client = ConnectionGatewayClient::new(- config.internal_api_secret_key.as_ref().to_string(),+ config.internal_api_key.to_string(),ConnectionGatewayUrl::new()?.to_string(),);@@ -211,7 +211,7 @@ async fn main() -> anyhow::Result<()> {));let lexical_client = Arc::new(LexicalClient::new(- config.internal_api_secret_key.as_ref().to_string(),+ config.internal_api_key.to_string(),LexicalServiceUrl::new()?.to_string(),));diff --git a/rust/cloud-storage/email_service/src/api/context.rs b/rust/cloud-storage/email_service/src/api/context.rsindex 02a496ee6a..86f651d4d6 100644--- a/rust/cloud-storage/email_service/src/api/context.rs+++ b/rust/cloud-storage/email_service/src/api/context.rs@@ -14,8 +14,7 @@ use email_service::util::redis::RedisClient;use entity_access::{domain::service::EntityAccessServiceImpl, outbound::PgAccessRepository};use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::FrecencyPgStorage};use macro_auth::middleware::decode_jwt::JwtValidationArgs;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use static_file_service_client::StaticFileServiceClient;use std::sync::Arc;use system_properties::{PgSystemPropertiesRepository, SystemPropertiesServiceImpl};@@ -44,7 +43,7 @@ pub(crate) struct ApiContext {pub system_properties_service: Arc<SystemPropertiesServiceImpl<PgSystemPropertiesRepository>>,pub jwt_args: JwtValidationArgs,pub config: Arc<Config>,- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub email_service: EmailRouterState<EmailSvc>,pub entity_access_service: Arc<EmailEntityAccessService>,pub email_thread_state: EmailThreadRouterState<EmailSvc, EmailEntityAccessService>,diff --git a/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs b/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rsindex 23fc99dfed..9c0c265df0 100644--- a/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs+++ b/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs@@ -5,7 +5,6 @@ use email_service::config::Config;use email_service::pubsub::CrmMetadataResolver;use macro_entrypoint::MacroEntrypoint;use macro_env::Environment;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use macro_service_urls::{AuthServiceUrl, ConnectionGatewayUrl, DocumentStorageServiceUrl, StaticFileServiceUrl,};@@ -210,20 +209,18 @@ async fn main() -> anyhow::Result<()> {config.redis_rate_limit_window_secs,);- let internal_auth_key = InternalApiSecretKey::new()?;-let sfs_client = StaticFileServiceClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),StaticFileServiceUrl::new()?.to_string(),);let dss_client = DocumentStorageServiceClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),DocumentStorageServiceUrl::new()?.to_string(),);let connection_gateway_client = connection_gateway_client::client::ConnectionGatewayClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),ConnectionGatewayUrl::new()?.to_string(),);diff --git a/rust/cloud-storage/email_service/src/config.rs b/rust/cloud-storage/email_service/src/config.rsindex 15afd8dd6c..cd86f9476c 100644--- a/rust/cloud-storage/email_service/src/config.rs+++ b/rust/cloud-storage/email_service/src/config.rs@@ -1,6 +1,7 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::env_vars;+use macro_middleware::auth::internal_access::InternalApiKey;use secretsmanager_client::LocalOrRemoteSecret;env_vars! {@@ -191,6 +192,9 @@ pub struct Config {// How long presigned urls should be valid for attachments#[macro_config_default(3600)]pub email_service_presigned_url_ttl_secs: u64,++ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/email_service/src/main.rs b/rust/cloud-storage/email_service/src/main.rsindex 10e46825b2..a5556ad59f 100644--- a/rust/cloud-storage/email_service/src/main.rs+++ b/rust/cloud-storage/email_service/src/main.rs@@ -15,9 +15,7 @@ use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::Fuse macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_entrypoint::MacroEntrypoint;use macro_env::Environment;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use macro_service_urls::{AuthServiceUrl, DocumentStorageServiceUrl, StaticFileServiceUrl};-use secretsmanager_client::LocalOrRemoteSecret;use sqlx::postgres::PgPoolOptions;use static_file_service_client::StaticFileServiceClient;use std::sync::Arc;@@ -100,15 +98,13 @@ async fn main() -> anyhow::Result<()> {config.redis_rate_limit_window_secs,);- let internal_auth_key = InternalApiSecretKey::new()?;-let sfs_client = StaticFileServiceClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),StaticFileServiceUrl::new()?.to_string(),);let dss_client = DocumentStorageServiceClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),DocumentStorageServiceUrl::new()?.to_string(),);@@ -156,6 +152,7 @@ async fn main() -> anyhow::Result<()> {));api::setup_and_serve(ApiContext {db,+ internal_api_key: config.internal_api_key.clone(),config: Arc::new(config),auth_service_client,redis_client,@@ -166,7 +163,6 @@ async fn main() -> anyhow::Result<()> {dss_client: Arc::new(dss_client),system_properties_service,jwt_args,- internal_auth_key: LocalOrRemoteSecret::Local(internal_auth_key),email_service,entity_access_service,email_thread_state,diff --git a/rust/cloud-storage/macro_middleware/src/auth/internal_access.rs b/rust/cloud-storage/macro_middleware/src/auth/internal_access.rsindex cf1b0e3bc9..d948162113 100644--- a/rust/cloud-storage/macro_middleware/src/auth/internal_access.rs+++ b/rust/cloud-storage/macro_middleware/src/auth/internal_access.rs@@ -4,9 +4,8 @@ use axum::{middleware::Next,response::Response,};-use macro_env_var::env_var;+use macro_env_var::env_vars;use model::user::UserContext;-use remote_env_var::LocalOrRemoteSecret;use std::borrow::Cow;/// The header key for the internal api key@@ -15,9 +14,11 @@ static INTERNAL_MACRO_USER_ID_HEADER: &str = "x-internal-macro-user-id";static INTERNAL_MACRO_ORGANIZATION_ID_HEADER: &str = "x-internal-macro-organization-id";static INTERNAL_FUSIONAUTH_USER_ID_HEADER: &str = "x-internal-fusionauth-user-id";-env_var!(+env_vars!(+ /// The internal api secret key for the service.+ /// NOTE: this value may be different depending on the service that is using this middleware.#[derive(Clone)]- pub struct InternalApiSecretKey;+ pub struct InternalApiKey;);/// Sentinel value which represensts that we were able to validate the internal auth key in the header of the request@@ -26,7 +27,7 @@ pub struct ValidInternalKey(());impl<S> FromRequestParts<S> for ValidInternalKeywhere- LocalOrRemoteSecret<InternalApiSecretKey>: FromRef<S>,+ InternalApiKey: FromRef<S>,S: Send + Sync + 'static,{type Rejection = (StatusCode, Cow<'static, str>);@@ -44,7 +45,7 @@ where));};- let expected_key = <LocalOrRemoteSecret<InternalApiSecretKey>>::from_ref(state);+ let expected_key = <InternalApiKey>::from_ref(state);// TODO: this should be constant time eq to prevent DOS attacks(expected_key.as_ref() == auth_token)@@ -55,7 +56,7 @@ whereimpl<S> OptionalFromRequestParts<S> for ValidInternalKeywhere- LocalOrRemoteSecret<InternalApiSecretKey>: FromRef<S>,+ InternalApiKey: FromRef<S>,S: Send + Sync + 'static,{type Rejection = std::convert::Infallible;@@ -74,7 +75,7 @@ where/// Validates that the INTERNAL_API_KEY_HEADER header is/// provided and valid-#[axum::debug_middleware(state = LocalOrRemoteSecret<InternalApiSecretKey>)]+#[axum::debug_middleware(state = InternalApiKey)]pub async fn handler(_valid_internal_key: ValidInternalKey,mut req: Request,diff --git a/rust/cloud-storage/mcp_service/src/config.rs b/rust/cloud-storage/mcp_service/src/config.rsindex dd5ed34aa5..c80cb8c592 100644--- a/rust/cloud-storage/mcp_service/src/config.rs+++ b/rust/cloud-storage/mcp_service/src/config.rs@@ -9,7 +9,7 @@ use anyhow::Context;use database_env_vars::DatabaseUrl;pub use macro_env::Environment;use macro_env_var::env_vars;-pub use macro_middleware::auth::internal_access::InternalApiSecretKey;+pub use macro_middleware::auth::internal_access::InternalApiKey;env_vars! {/// SQS URL for the email scheduled queue, consumed by the AI tools.@@ -89,8 +89,8 @@ pub struct Config {pub google_client_secret_key: GoogleClientSecretKey,pub redis_url: RedisUrl,pub app_base_url: AppBaseUrl,- /// Shared secret for authenticating internal service-to-service calls.- pub internal_api_secret_key: InternalApiSecretKey,+ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/mcp_service/src/context.rs b/rust/cloud-storage/mcp_service/src/context.rsindex 1ee968e27f..9310f18009 100644--- a/rust/cloud-storage/mcp_service/src/context.rs+++ b/rust/cloud-storage/mcp_service/src/context.rs@@ -77,9 +77,6 @@ pub async fn build_context(config: &Config) -> anyhow::Result<McpContext> {.await.context("failed to initialize JWT validation args")?;- let internal_auth_key =- secretsmanager_client::LocalOrRemoteSecret::Local(config.internal_api_secret_key.clone());-let sync_service_auth_key = LocalOrRemoteSecret::new_from_secret_manager(config.sync_service_auth_key.as_ref().to_owned(),&secretsmanager_client,@@ -92,7 +89,6 @@ pub async fn build_context(config: &Config) -> anyhow::Result<McpContext> {&db,&secretsmanager_client,sqs_client,- internal_auth_key.as_ref().to_string(),config.document_storage_service_auth_key.as_ref().to_owned(),sync_service_auth_key.as_ref().to_owned(),)@@ -120,7 +116,6 @@ async fn build_tool_context(db: &PgPool,secretsmanager_client: &secretsmanager_client::SecretsManager,sqs_client: sqs_client::SQS,- internal_auth_key: String,document_storage_service_auth_key: String,sync_service_auth_key: String,) -> anyhow::Result<ToolServiceContext> {@@ -133,12 +128,12 @@ async fn build_tool_context(SearchServiceClient::new(document_storage_service_auth_key, dss_url);let lexical_client = Arc::new(lexical_client::LexicalClient::new(- internal_auth_key.clone(),+ config.internal_api_key.to_string(),lexical_service_url,));let email_service_client = Arc::new(EmailServiceClient::new(- internal_auth_key.clone(),+ config.internal_api_key.to_string(),email_service_url,));diff --git a/rust/cloud-storage/notification_service/src/api/context.rs b/rust/cloud-storage/notification_service/src/api/context.rsindex 7785998b17..ddaf9a3ad8 100644--- a/rust/cloud-storage/notification_service/src/api/context.rs+++ b/rust/cloud-storage/notification_service/src/api/context.rs@@ -1,8 +1,7 @@use crate::config::Config;use axum::extract::FromRef;use macro_auth::middleware::decode_jwt::JwtValidationArgs;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use sqlx::PgPool;use std::sync::Arc;@@ -12,5 +11,5 @@ pub struct ApiContext {pub sns_client: Arc<sns_client::SNS>,pub config: Arc<Config>,pub jwt_args: JwtValidationArgs,- pub internal_secret_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,}diff --git a/rust/cloud-storage/notification_service/src/config.rs b/rust/cloud-storage/notification_service/src/config.rsindex 3c8dcd3934..3580c38720 100644--- a/rust/cloud-storage/notification_service/src/config.rs+++ b/rust/cloud-storage/notification_service/src/config.rs@@ -2,7 +2,7 @@ use anyhow::Context;use database_env_vars::{DatabaseUrl, RedisUri};use macro_env::Environment;use macro_env_var::{env_var, env_vars, maybe_env_var};-use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;use std::sync::LazyLock;// We load this through `macro_config` at startup as part of [`Config`]. This lazy is retained for@@ -58,8 +58,8 @@ pub struct Config {/// The connection URL for the Postgres database this application should use.pub(crate) database_url: DatabaseUrl,- /// Internal API secret key name/value.- pub(crate) internal_api_secret_key: InternalApiSecretKey,+ /// Internal API key.+ pub(crate) internal_api_key: InternalApiKey,/// Secret name/value for digest unsubscribe URL signing.pub(crate) url_signing_hmac: UrlSigningHmac,diff --git a/rust/cloud-storage/notification_service/src/main.rs b/rust/cloud-storage/notification_service/src/main.rsindex 687f7d725d..f22aa90cfb 100644--- a/rust/cloud-storage/notification_service/src/main.rs+++ b/rust/cloud-storage/notification_service/src/main.rs@@ -64,10 +64,6 @@ pub async fn main() -> anyhow::Result<()> {aws_sdk_secretsmanager::Client::new(&aws_config),);- let internal_secret_key = secretsmanager_client- .get_maybe_secret_value(config.environment, config.internal_api_secret_key.clone())- .await?;-let unsubscribe_hmac_secret = secretsmanager_client.get_maybe_secret_value(config.environment, config.url_signing_hmac.clone()).await?;@@ -151,12 +147,12 @@ pub async fn main() -> anyhow::Result<()> {apns_voip_platform_arn: config.sns_apns_voip_platform_arn().to_string(),};let reader_realtime_adapter = WebSocketGatewayAdapter::new(ConnectionGatewayClient::new(- internal_secret_key.as_ref().to_string(),+ config.internal_api_key.as_ref().to_string(),connection_gateway_url.clone(),));let notification_events_realtime_adapter =WebSocketGatewayAdapter::new(ConnectionGatewayClient::new(- internal_secret_key.as_ref().to_string(),+ config.internal_api_key.as_ref().to_string(),connection_gateway_url.clone(),));let notification_events_receiver = PgNotificationEventsReceiver::new(db.clone());@@ -188,7 +184,7 @@ pub async fn main() -> anyhow::Result<()> {::notification::outbound::repository::DbNotificationRepository::new(db.clone());let websocket_adapter = WebSocketGatewayAdapter::new(ConnectionGatewayClient::new(- internal_secret_key.as_ref().to_string(),+ config.internal_api_key.as_ref().to_string(),connection_gateway_url,));@@ -316,11 +312,11 @@ pub async fn main() -> anyhow::Result<()> {api::setup_and_serve(ApiContext {+ internal_api_key: config.internal_api_key.clone(),db,sns_client: Arc::new(sns_client),config: Arc::new(config),jwt_args,- internal_secret_key,},ingress_state,)diff --git a/rust/cloud-storage/scheduled_action/src/bins/service.rs b/rust/cloud-storage/scheduled_action/src/bins/service.rsindex 4f6d60a129..ba4009897b 100644--- a/rust/cloud-storage/scheduled_action/src/bins/service.rs+++ b/rust/cloud-storage/scheduled_action/src/bins/service.rs@@ -56,7 +56,7 @@ async fn main() -> Result<()> {aws_sdk_secretsmanager::Client::new(¯o_aws_config::get_macro_aws_config().await),);let conn_gateway_client = Arc::new(ConnectionGatewayClient::new(- config.internal_api_secret_key.as_ref().to_string(),+ config.internal_api_key.to_string(),ConnectionGatewayUrl::new()?.to_string(),));let live_updates = Arc::new(ConnGatewayLiveUpdates::new(Arc::clone(diff --git a/rust/cloud-storage/scheduled_action/src/config.rs b/rust/cloud-storage/scheduled_action/src/config.rsindex d3b764e75f..f564da7fc9 100644--- a/rust/cloud-storage/scheduled_action/src/config.rs+++ b/rust/cloud-storage/scheduled_action/src/config.rs@@ -14,7 +14,7 @@ use anyhow::Context;use database_env_vars::DatabaseUrl;pub use macro_env::Environment;use macro_env_var::env_vars;-pub use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;env_vars! {/// SQS URL for the notification ingress queue.@@ -61,8 +61,8 @@ pub struct Config {DocumentStorageServiceCloudfrontSignerPublicKeyId,pub document_storage_service_cloudfront_signer_private_key_secret_name:DocumentStorageServiceCloudfrontSignerPrivateKeySecretName,- /// Shared secret for authenticating internal service-to-service calls.- pub internal_api_secret_key: InternalApiSecretKey,+ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/search_processing_service/src/api/context.rs b/rust/cloud-storage/search_processing_service/src/api/context.rsindex 1209804c92..e4d79085ec 100644--- a/rust/cloud-storage/search_processing_service/src/api/context.rs+++ b/rust/cloud-storage/search_processing_service/src/api/context.rs@@ -1,6 +1,5 @@use axum::extract::FromRef;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use std::sync::Arc;use crate::BackfillServiceImpl;@@ -12,7 +11,7 @@ pub(crate) struct ApiContext {pub db: sqlx::Pool<sqlx::Postgres>,pub sqs_client: Arc<sqs_client::SQS>,pub opensearch_client: Arc<opensearch_client::OpensearchClient>,- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,pub config: Arc<Config>,pub backfill_service: Arc<BackfillServiceImpl>,pub backfill_jobs: BackfillJobs,diff --git a/rust/cloud-storage/search_processing_service/src/api/mod.rs b/rust/cloud-storage/search_processing_service/src/api/mod.rsindex 7a89e50062..513c86471d 100644--- a/rust/cloud-storage/search_processing_service/src/api/mod.rs+++ b/rust/cloud-storage/search_processing_service/src/api/mod.rs@@ -1,8 +1,7 @@use anyhow::Context;use axum::Router;use context::ApiContext;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use tower::ServiceBuilder;use tower_http::trace::TraceLayer;use utoipa::OpenApi;@@ -22,7 +21,7 @@ pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {let port = state.config.port;let env = state.config.environment;let backfill_jobs = state.backfill_jobs.clone();- let app = api_router(state.internal_auth_key.clone())+ let app = api_router(state.internal_api_key.clone()).with_state(state).layer(cors.clone()).layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))@@ -81,7 +80,7 @@ async fn shutdown_signal(backfill_jobs: crate::domain::jobs::BackfillJobs) {backfill_jobs.cancel_all_local();}-fn api_router(internal_secret: LocalOrRemoteSecret<InternalApiSecretKey>) -> Router<ApiContext> {+fn api_router(internal_secret: InternalApiKey) -> Router<ApiContext> {Router::new().nest("/internal",internal::router().layer(diff --git a/rust/cloud-storage/search_processing_service/src/config.rs b/rust/cloud-storage/search_processing_service/src/config.rsindex 8aa438e090..a46ea181f9 100644--- a/rust/cloud-storage/search_processing_service/src/config.rs+++ b/rust/cloud-storage/search_processing_service/src/config.rs@@ -1,6 +1,7 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::{env_vars, maybe_env_vars};+use macro_middleware::auth::internal_access::InternalApiKey;use macro_service_urls::LexicalServiceUrl;env_vars! {@@ -137,6 +138,9 @@ pub struct Config {/// TTL applied to the `expires_at` attribute on each job record. Acts as/// the GC mechanism — DynamoDB removes items shortly after this elapses.pub backfill_job_ttl_seconds: BackfillJobTtlSeconds,++ /// The internal api key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/search_processing_service/src/main.rs b/rust/cloud-storage/search_processing_service/src/main.rsindex e71f82635f..4c3e81b93b 100644--- a/rust/cloud-storage/search_processing_service/src/main.rs+++ b/rust/cloud-storage/search_processing_service/src/main.rs@@ -12,10 +12,8 @@ use anyhow::Context;use config::{Config, Environment};use lexical_client::LexicalClient;use macro_entrypoint::MacroEntrypoint;-use macro_middleware::auth::internal_access::InternalApiSecretKey;use opensearch_client::OpensearchClient;use rust_embed::RustEmbed;-use secretsmanager_client::LocalOrRemoteSecret;use sqlx::PgPool;use sqlx::postgres::PgPoolOptions;@@ -107,8 +105,6 @@ async fn main() -> anyhow::Result<()> {return Err(e);}- let internal_auth_key = LocalOrRemoteSecret::Local(InternalApiSecretKey::new()?);-// Backfills run against the read-replica when available so they don't// contend with writes on the primary. Queue workers always read from the// primary because replica lag would cause them to miss rows they are@@ -143,7 +139,7 @@ async fn main() -> anyhow::Result<()> {}let lexical_client = LexicalClient::new(- internal_auth_key.as_ref().to_string(),+ config.internal_api_key.to_string(),config.lexical_service_url.clone(),);@@ -179,9 +175,9 @@ async fn main() -> anyhow::Result<()> {api::setup_and_serve(ApiContext {db,+ internal_api_key: config.internal_api_key.clone(),sqs_client,opensearch_client: Arc::new(opensearch_client),- internal_auth_key,config: Arc::new(config),backfill_service,backfill_jobs,diff --git a/rust/cloud-storage/search_service/src/config.rs b/rust/cloud-storage/search_service/src/config.rsdeleted file mode 100644index 4e589a2243..0000000000--- a/rust/cloud-storage/search_service/src/config.rs+++ /dev/null@@ -1,72 +0,0 @@-use anyhow::Context;-pub use macro_env::Environment;-use macro_env_var::{env_vars, maybe_env_vars};-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;--env_vars! {- struct DatabaseUrl;- struct OpensearchUrl;- struct OpensearchUsername;- struct OpensearchPassword;-}--maybe_env_vars! {- struct Port;-}--pub struct Config {- /// The port to listen for HTTP requests on.- pub port: usize,-- /// The environment we are in- pub environment: Environment,- /// The connection URL for the Postgres database this application should use.- pub database_url: String,- /// The URL for the Opensearch instance- pub opensearch_url: String,- /// The username for the Opensearch instance- pub opensearch_username: String,- /// The password for the Opensearch instance- pub opensearch_password: String,-- /// The internal auth key- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,-}--impl Config {- pub fn from_env() -> anyhow::Result<Self> {- let port = Port::new()- .map(|port| port.parse::<usize>().context("should be valid port number"))- .transpose()?- .unwrap_or(8080);-- let environment = Environment::new_or_prod();-- let database_url = DatabaseUrl::new()- .context("DATABASE_URL must be provided")?- .to_string();-- let opensearch_url = OpensearchUrl::new()- .context("OPENSEARCH_URL must be provided")?- .to_string();- let opensearch_username = OpensearchUsername::new()- .context("OPENSEARCH_USERNAME must be provided")?- .to_string();- let opensearch_password = OpensearchPassword::new()- .context("OPENSEARCH_PASSWORD must be provided")?- .to_string();-- let internal_auth_key = LocalOrRemoteSecret::Local(InternalApiSecretKey::new()?);-- Ok(Config {- port,- environment,- database_url,- opensearch_url,- opensearch_username,- opensearch_password,- internal_auth_key,- })- }-}diff --git a/rust/cloud-storage/search_service/src/lib.rs b/rust/cloud-storage/search_service/src/lib.rsindex 9129eaa2b4..9e2c0671a1 100644--- a/rust/cloud-storage/search_service/src/lib.rs+++ b/rust/cloud-storage/search_service/src/lib.rs@@ -1,7 +1,6 @@//! Search Service Library - exposes API routes for integration into other servicespub mod api;-pub mod config;// Re-exports for consumerspub use api::context::SearchHandlerState;diff --git a/rust/cloud-storage/static_file_service/src/api/context.rs b/rust/cloud-storage/static_file_service/src/api/context.rsindex 2e3ebb3231..d391e809da 100644--- a/rust/cloud-storage/static_file_service/src/api/context.rs+++ b/rust/cloud-storage/static_file_service/src/api/context.rs@@ -3,8 +3,7 @@ use crate::service::dynamodb::client::DynamodbClient;use crate::service::s3::client::S3Client;use aws_sdk_sqs::Client;use axum::extract::FromRef;-use macro_middleware::auth::internal_access::InternalApiSecretKey;-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::InternalApiKey;use std::sync::Arc;#[derive(Clone, FromRef)]@@ -13,5 +12,5 @@ pub struct AppState {pub storage_client: Arc<S3Client>,pub sqs_client: Client,pub config: Arc<Config>,- pub internal_api_secret: LocalOrRemoteSecret<InternalApiSecretKey>,+ pub internal_api_key: InternalApiKey,}diff --git a/rust/cloud-storage/static_file_service/src/api/mod.rs b/rust/cloud-storage/static_file_service/src/api/mod.rsindex f4a16b5754..76c8fe7b3d 100644--- a/rust/cloud-storage/static_file_service/src/api/mod.rs+++ b/rust/cloud-storage/static_file_service/src/api/mod.rs@@ -12,8 +12,7 @@ use anyhow::Context;use axum::Router;use axum::extract::DefaultBodyLimit;use macro_auth::middleware::decode_jwt::JwtValidationArgs;-use macro_middleware::auth::internal_access::{InternalApiSecretKey, ValidInternalKey};-use secretsmanager_client::LocalOrRemoteSecret;+use macro_middleware::auth::internal_access::ValidInternalKey;use std::sync::Arc;use tower::ServiceBuilder;use tower_http::limit::RequestBodyLimitLayer;@@ -25,7 +24,6 @@ static MAX_REQUEST_SIZE: usize = 4096;pub async fn setup_and_serve(config: Config,jwt_validation_args: JwtValidationArgs,- internal_api_secret: LocalOrRemoteSecret<InternalApiSecretKey>,) -> anyhow::Result<()> {let cors = macro_cors::cors_layer();@@ -50,8 +48,8 @@ pub async fn setup_and_serve(metadata_client,storage_client: Arc::new(storage_client),sqs_client,+ internal_api_key: config.internal_api_key.clone(),config: Arc::new(config),- internal_api_secret,};let state_clone = state.clone();diff --git a/rust/cloud-storage/static_file_service/src/config.rs b/rust/cloud-storage/static_file_service/src/config.rsindex 651d1eb6fe..5a3d2a721f 100644--- a/rust/cloud-storage/static_file_service/src/config.rs+++ b/rust/cloud-storage/static_file_service/src/config.rs@@ -1,9 +1,8 @@use anyhow::Context;pub use macro_env::Environment;use macro_env_var::env_vars;-use macro_middleware::auth::internal_access::InternalApiSecretKey;+use macro_middleware::auth::internal_access::InternalApiKey;use macro_service_urls::StaticFileServiceUrl;-use secretsmanager_client::LocalOrRemoteSecret;env_vars! {pub struct StaticFileServiceDynamodbTableName;@@ -29,8 +28,8 @@ pub struct Config {pub static_file_service_url: String,/// s3 upload notification queuepub static_file_service_s3_event_queue_url: StaticFileServiceS3EventQueueUrl,- /// Internal API secret key- pub internal_api_secret_key: LocalOrRemoteSecret<InternalApiSecretKey>,+ /// Internal API key+ pub internal_api_key: InternalApiKey,}impl Config {diff --git a/rust/cloud-storage/static_file_service/src/main.rs b/rust/cloud-storage/static_file_service/src/main.rsindex 7ed19e71bb..340303e775 100644--- a/rust/cloud-storage/static_file_service/src/main.rs+++ b/rust/cloud-storage/static_file_service/src/main.rs@@ -12,24 +12,17 @@ mod service;async fn main() -> anyhow::Result<()> {MacroEntrypoint::default().init();- let config = config::Config::from_env().context("missing environment variables")?;-let aws_config = macro_aws_config::get_macro_aws_config().await;let secretsmanager_client = secretsmanager_client::SecretsManager::new(aws_sdk_secretsmanager::Client::new(&aws_config),);- let environment = config.environment;- let config = config- .resolve_remote_secrets(environment, &secretsmanager_client)- .await- .context("failed to resolve config secrets")?;- let internal_api_secret = config.internal_api_secret_key.clone();+ let config = config::Config::from_env().context("missing environment variables")?;let jwt_validation_args =JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client).await?;- api::setup_and_serve(config, jwt_validation_args, internal_api_secret).await?;+ api::setup_and_serve(config, jwt_validation_args).await?;Ok(())}