Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: expiry seconds env var for macro api token (#1030)

gbirman4440242c31ee
diff --git a/infra/stacks/authentication-service/Pulumi.dev.yaml b/infra/stacks/authentication-service/Pulumi.dev.yaml
index fa0c5fe84c..0cc52586a0 100644
--- a/infra/stacks/authentication-service/Pulumi.dev.yaml
+++ b/infra/stacks/authentication-service/Pulumi.dev.yaml
@@ -14,5 +14,6 @@ config:
authentication-service:google_client_id: google-client-id-dev
authentication-service:google_client_secret_key: google-client-secret-dev
authentication-service:macro_api_token_private_secret_key: macro-api-token-private-key-dev
+ authentication-service:macro_api_token_expiry_seconds: 3600
authentication-service:stripe_webhook_secret_key: stripe-webhook-secret-dev
authentication-service:stripe_price_id: stripe-price-id-dev
diff --git a/infra/stacks/authentication-service/Pulumi.prod.yaml b/infra/stacks/authentication-service/Pulumi.prod.yaml
index 4dce1c118b..ef2ba24c59 100644
--- a/infra/stacks/authentication-service/Pulumi.prod.yaml
+++ b/infra/stacks/authentication-service/Pulumi.prod.yaml
@@ -14,5 +14,6 @@ config:
authentication-service:google_client_id: google-client-id-prod
authentication-service:google_client_secret_key: google-client-secret-prod
authentication-service:macro_api_token_private_secret_key: macro-api-token-private-key-prod
+ authentication-service:macro_api_token_expiry_seconds: 3600
authentication-service:stripe_webhook_secret_key: stripe-webhook-secret-prod
authentication-service:stripe_price_id: stripe-price-id-prod
diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts
index 549a04c186..770cf6febd 100644
--- a/infra/stacks/authentication-service/index.ts
+++ b/infra/stacks/authentication-service/index.ts
@@ -101,6 +101,10 @@ const stripePriceIdArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: STRIPE_PRICE_ID_KEY })
.apply((secret) => secret.arn);
+const MACRO_API_TOKEN_EXPIRY_SECONDS = config.require(
+ `macro_api_token_expiry_seconds`
+);
+
const MACRO_API_TOKEN_PRIVATE_SECRET_KEY = config.require(
`macro_api_token_private_secret_key`
);
@@ -268,6 +272,10 @@ const service = new AuthenticationService('authentication-service', {
name: 'MACRO_API_TOKEN_PRIVATE_SECRET_KEY',
value: pulumi.interpolate`${macroApiTokenSecretPrivateKeyArn}`,
},
+ {
+ name: 'MACRO_API_TOKEN_EXPIRY_SECONDS',
+ value: MACRO_API_TOKEN_EXPIRY_SECONDS,
+ },
{
name: 'STRIPE_WEBHOOK_SECRET_KEY',
value: pulumi.interpolate`${stripeWebhookSecretKeyArn}`,
diff --git a/rust/cloud-storage/authentication_service/src/api/context.rs b/rust/cloud-storage/authentication_service/src/api/context.rs
index f17e7527eb..8f14bd78a1 100644
--- a/rust/cloud-storage/authentication_service/src/api/context.rs
+++ b/rust/cloud-storage/authentication_service/src/api/context.rs
@@ -61,12 +61,19 @@ env_var! {
pub struct MacroApiTokenPrivateSecretKey;
}
+env_var! {
+ #[derive(Clone)]
+ pub struct MacroApiTokenExpirySeconds;
+}
+
#[derive(Clone)]
pub struct MacroApiTokenContext {
/// The issuer of the macro-api-token
pub issuer: MacroApiTokenIssuer,
/// The macro api token private key used to sign macro-api tokens
pub macro_api_token_private_key: LocalOrRemoteSecret<MacroApiTokenPrivateSecretKey>,
+ /// The token expiry duration in seconds
+ pub expiry_seconds: usize,
}
#[derive(Clone)]
diff --git a/rust/cloud-storage/authentication_service/src/api/jwt/macro_api_token.rs b/rust/cloud-storage/authentication_service/src/api/jwt/macro_api_token.rs
index 9075c4f3c7..401f7bdec8 100644
--- a/rust/cloud-storage/authentication_service/src/api/jwt/macro_api_token.rs
+++ b/rust/cloud-storage/authentication_service/src/api/jwt/macro_api_token.rs
@@ -96,6 +96,7 @@ pub async fn handler(
.macro_api_token_private_key
.as_ref()
.to_string(),
+ expiry_seconds: macro_api_token_context.expiry_seconds,
})
.map_err(|e| {
tracing::error!(error=?e, "unable to encode macro-api-token");
diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs
index 044582790c..51ffba49a6 100644
--- a/rust/cloud-storage/authentication_service/src/main.rs
+++ b/rust/cloud-storage/authentication_service/src/main.rs
@@ -21,8 +21,8 @@ use teams::{
};
use crate::api::context::{
- ApiContext, MacroApiTokenContext, MacroApiTokenIssuer, MacroApiTokenPrivateSecretKey,
- StripeWebhookSecretKey,
+ ApiContext, MacroApiTokenContext, MacroApiTokenExpirySeconds, MacroApiTokenIssuer,
+ MacroApiTokenPrivateSecretKey, StripeWebhookSecretKey,
};
use std::sync::Arc;
@@ -227,6 +227,10 @@ async fn main() -> anyhow::Result<()> {
token_context: MacroApiTokenContext {
issuer: MacroApiTokenIssuer::new()?,
macro_api_token_private_key,
+ expiry_seconds: MacroApiTokenExpirySeconds::new()?
+ .as_ref()
+ .parse()
+ .context("failed to parse MACRO_API_TOKEN_EXPIRY_SECONDS as usize")?,
},
internal_api_key,
stripe_webhook_secret,
diff --git a/rust/cloud-storage/macro_auth/src/macro_api_token.rs b/rust/cloud-storage/macro_auth/src/macro_api_token.rs
index b6c6af89c8..7952fd3bba 100644
--- a/rust/cloud-storage/macro_auth/src/macro_api_token.rs
+++ b/rust/cloud-storage/macro_auth/src/macro_api_token.rs
@@ -30,6 +30,8 @@ pub struct EncodeMacroApiTokenArgs {
pub issuer: String,
/// The private key used to sign the token
pub private_key: String,
+ /// The token expiry duration in seconds
+ pub expiry_seconds: usize,
}
#[tracing::instrument(skip(args))]
@@ -40,7 +42,7 @@ pub fn encode_macro_api_token(args: EncodeMacroApiTokenArgs) -> anyhow::Result<S
.as_secs() as usize;
let claims = MacroApiToken {
- exp: now + 3600, // Token expires in 1 hour
+ exp: now + args.expiry_seconds,
iss: args.issuer.clone(),
fusion_user_id: args.fusionauth_id.clone(),
macro_user_id: args.macro_user_id.clone(),