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(infra) local fusionauth pulumi (#1003)

Will Hutchinsonb99fd00481c9
diff --git a/infra/bun.lock b/infra/bun.lock
index 6b18b84a3d..38ce2b88c1 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -12,6 +12,7 @@
"@pulumi/docker-build": "^0.0.15",
"@pulumi/pulumi": "^3.209.0",
"@pulumi/tls": "*",
+ "dotenv": "^17.2.3",
"minimist": "^1.2.8",
},
"devDependencies": {
@@ -118,6 +119,13 @@
"name": "fusion-auth",
"version": "0.0.0",
},
+ "stacks/fusionauth-instance": {
+ "name": "fusionauth-instance-stack",
+ "version": "0.0.0",
+ "dependencies": {
+ "pulumi-fusionauth": "6.0.2",
+ },
+ },
"stacks/link-sharing": {
"name": "link-sharing-stack",
"version": "0.0.0",
@@ -616,6 +624,8 @@
"document-text-extractor-stack": ["document-text-extractor-stack@workspace:stacks/document-text-extractor"],
+ "dotenv": ["[email protected]", "", {}, "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w=="],
+
"eastasianwidth": ["[email protected]", "", {}, "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA=="],
"email-service-stack": ["email-service-stack@workspace:stacks/email-service"],
@@ -656,6 +666,8 @@
"fusion-auth": ["fusion-auth@workspace:stacks/fusion-auth"],
+ "fusionauth-instance-stack": ["fusionauth-instance-stack@workspace:stacks/fusionauth-instance"],
+
"get-caller-file": ["[email protected]", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="],
"get-stream": ["[email protected]", "", {}, "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg=="],
@@ -860,6 +872,8 @@
"protobufjs": ["[email protected]", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw=="],
+ "pulumi-fusionauth": ["[email protected]", "", { "dependencies": { "@pulumi/pulumi": "^3.0.0" } }, "sha512-9By39HUEnap5kCasy7a1ELXEDDeWvBqBY4h7rS/knWUWemoMuaVYaF4YH/qGOR85Gw6AdLRzP6WFqfU7m6j/kw=="],
+
"pump": ["[email protected]", "", { "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw=="],
"quick-lru": ["[email protected]", "", {}, "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA=="],
diff --git a/infra/package.json b/infra/package.json
index 105fc557c9..1b843483ca 100644
--- a/infra/package.json
+++ b/infra/package.json
@@ -26,6 +26,7 @@
"@pulumi/docker-build": "^0.0.15",
"@pulumi/pulumi": "^3.209.0",
"@pulumi/tls": "*",
+ "dotenv": "^17.2.3",
"minimist": "^1.2.8"
},
"resolutions": {
diff --git a/infra/stacks/fusion-auth/database.ts b/infra/stacks/fusion-auth/database.ts
index 888cc80f7e..66c180bdb9 100644
--- a/infra/stacks/fusion-auth/database.ts
+++ b/infra/stacks/fusion-auth/database.ts
@@ -104,7 +104,7 @@ export class Database extends pulumi.ComponentResource {
{
identifier: `${name}-${stack}`,
engine: 'postgres',
- engineVersion: '16.2',
+ engineVersion: '16.8',
instanceClass,
storageType: 'gp3',
allocatedStorage,
diff --git a/infra/stacks/fusion-auth/fusionauth-service.ts b/infra/stacks/fusion-auth/fusionauth-service.ts
index 2fa28394d4..1f8d066977 100644
--- a/infra/stacks/fusion-auth/fusionauth-service.ts
+++ b/infra/stacks/fusion-auth/fusionauth-service.ts
@@ -133,7 +133,10 @@ export class FusionAuthService extends pulumi.ComponentResource {
containers: {
service: {
name: BASE_NAME,
- image: 'fusionauth/fusionauth-app:1.54.0',
+ image:
+ stack === 'prod'
+ ? 'fusionauth/fusionauth-app:1.54.0'
+ : 'fusionauth/fusionauth-app:1.62.0',
cpu: stack === 'prod' ? 2048 : 2048,
memory: stack === 'prod' ? 4096 : 4096,
environment: containerEnvVars,
diff --git a/infra/stacks/fusionauth-instance/.gitignore b/infra/stacks/fusionauth-instance/.gitignore
new file mode 100644
index 0000000000..7e0ecd70a2
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/.gitignore
@@ -0,0 +1 @@
+!templates/*.js
diff --git a/infra/stacks/fusionauth-instance/Pulumi.dev.yaml b/infra/stacks/fusionauth-instance/Pulumi.dev.yaml
new file mode 100644
index 0000000000..63bf020ae5
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/Pulumi.dev.yaml
@@ -0,0 +1,16 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ fusionauth-instance:authentication-service-domain: https://auth-service-dev.macro.com
+ fusionauth-instance:authentication-service-internal-secret-key: authentication-service-internal-api-key-dev
+ fusionauth-instance:fusionauth-license-key-secret-key: fusionauth-license-key-dev
+ fusionauth-instance:fusionauth-default-tenant-id: 5e13f524-8d32-0454-81f8-061936256aa4
+ fusionauth-instance:fusionauth-client-id: eb75fe7a-0ef1-4186-96d9-cc62cfb1d10c
+ fusionauth-instance:fusionauth-client-secret-key: fusionauth-client-secret-dev
+ fusionauth-instance:fusionauth-signing-key-id: aea64fc1-84f6-89ab-fb7c-08a21556263e
+ fusionauth-instance:smtp-user-secret-key: smtp-user
+ fusionauth-instance:fusionauth-issuer: fusionauth-dev.macro.com
+ fusionauth-instance:default-from-email: [email protected]
+ fusionauth:host: https://fusionauth-dev.macro.com
+ fusionauth:apiKey:
+ secure: AAABAIM7Z+lcjIsSyrKS7sxBEGnbCPXNwe8R/bdTmkD0smcFHyo3wvX/8fhf4tY2rqeU29bp82LXHlxYFP6rLCJE4ZbKjguYAI6J510bQl20LPsrmT+wTA==
diff --git a/infra/stacks/fusionauth-instance/Pulumi.local.yaml b/infra/stacks/fusionauth-instance/Pulumi.local.yaml
new file mode 100644
index 0000000000..d295e25a8e
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/Pulumi.local.yaml
@@ -0,0 +1,10 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ fusionauth-instance:authentication-service-domain: http://localhost:8084
+ fusionauth-instance:fusionauth-license-key-secret-key: fusionauth-license-key-dev
+ fusionauth-instance:smtp-user-secret-key: smtp-user
+ fusionauth-instance:fusionauth-issuer: local.macro.com
+ fusionauth-instance:default-from-email: [email protected]
+ fusionauth:host: http://localhost:9011
+ fusionauth:apiKey: bf69486b-4733-4954-a44e-2e1b5f2c8a91
diff --git a/infra/stacks/fusionauth-instance/Pulumi.yaml b/infra/stacks/fusionauth-instance/Pulumi.yaml
new file mode 100644
index 0000000000..d872db0604
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/Pulumi.yaml
@@ -0,0 +1,3 @@
+name: fusionauth-instance
+runtime: nodejs
+description: Macro Fusion Auth Instance Configuration
diff --git a/infra/stacks/fusionauth-instance/README.md b/infra/stacks/fusionauth-instance/README.md
new file mode 100644
index 0000000000..ab573c1ef3
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/README.md
@@ -0,0 +1,45 @@
+# FusionAuth Instance Stack
+
+This pulumi stack contains everything you need to be able to setup a "macro compliant" fusionauth instance.
+
+Ideal for local development.
+
+# Prerequisites
+
+The following are required tools you need to have setup ahead of time:
+
+`docker` and `docker-compose`
+`pulumi`
+`aws-cli`
+`just`
+
+# Usage
+**Important** do not use `macro-inc/` prefix when you make your fusionauth-instance local stack. This is meant to be stored on __your__ pulumi account only (local to you) not on the organization.
+
+## Deploy Local Fusionauth Instance
+
+Download your .env file used to create the local fusionauth stack:
+
+```bash
+just setup_fusionauth_env
+```
+
+This is used in the docker-compose automatically.
+
+Now run `just start_fusionauth` to create the local fusionauth instance. Through the [./kickstart/kickstart.json](kickstart) file, we automatically create an admin user and admin api key to use.
+
+```
+password: macroIsGreat!
+api-key: bf69486b-4733-4954-a44e-2e1b5f2c8a91
+```
+
+Now you can run the following to get things in sync and ready to start your local dev journey
+
+```bash
+just instantiate_fusionauth
+```
+
+# TODO
+- [ ] configure idps
+- [ ] sync prod with pulumi stack
diff --git a/infra/stacks/fusionauth-instance/constants.ts b/infra/stacks/fusionauth-instance/constants.ts
new file mode 100644
index 0000000000..a349713d74
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/constants.ts
@@ -0,0 +1,85 @@
+import { config, stack } from '../../packages/shared';
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { Provider } from 'pulumi-fusionauth';
+
+// The id of the default tenant
+export const DEFAULT_FUSIONAUTH_TENANT_ID =
+ stack === 'local'
+ ? undefined
+ : config.require('fusionauth-default-tenant-id');
+
+// The fusionauth issuer on the tenant
+export const FUSIONAUTH_ISSUER = config.require('fusionauth-issuer');
+
+// The pre-existing application id
+// This is only predefined fro existing infra (dev and prod)
+export const FUSIONAUTH_APPLICATION_CLIENT_ID =
+ stack === 'local' ? undefined : config.require('fusionauth-client-id');
+
+export const FUSIONAUTH_SIGNING_KEY_ID =
+ stack === 'local' ? undefined : config.require('fusionauth-signing-key-id');
+
+// The potential pre-defined client secret for the fusionauth application
+// This is only predefined for existing infra (dev and prod)
+export const FUSIONAUTH_CLIENT_SECRET =
+ stack === 'local'
+ ? undefined
+ : aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require('fusionauth-client-secret-key'),
+ })
+ .apply((secret) => secret.secretString);
+
+// The auth service url
+export const AUTHENTICATION_SERVICE_DOMAIN = config.require(
+ 'authentication-service-domain'
+);
+
+if (AUTHENTICATION_SERVICE_DOMAIN.endsWith('/')) {
+ throw new Error(
+ 'Cannot have authentication service domain end with trailing /'
+ );
+}
+
+// The auth service internal secret
+export const AUTHENTICATION_SERVICE_INTERNAL_SECRET = config.get(
+ 'authentication-service-internal-secret-key'
+)
+ ? aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require('authentication-service-internal-secret-key'),
+ })
+ .apply((secret) => secret.secretString)
+ : 'local';
+
+// Fusionauth license key grabbed from aws secrets manager
+export const FUSIONAUTH_LICENSE_KEY = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require('fusionauth-license-key-secret-key'),
+ })
+ .apply((secret) => secret.secretString);
+
+// SMTP credentials grabbed by aws secrets manager
+// Stored as {username: "", password: ""}
+export const SMTP_CREDENTIALS = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require('smtp-user-secret-key'),
+ })
+ .apply(
+ (secret) =>
+ JSON.parse(secret.secretString) as { username: string; password: string }
+ );
+
+// This is required when importing the pre-existing fusionauth tenant into the configuration
+const fusionauthConfig = new pulumi.Config('fusionauth');
+const fusionauthHost = fusionauthConfig.require('host');
+const fusionauthApiKey =
+ stack === 'local'
+ ? fusionauthConfig.requireSecret('apiKey')
+ : fusionauthConfig.requireSecret('apiKey');
+
+export const fusionAuthProvider = new Provider('fusion-auth-provider', {
+ host: fusionauthHost,
+ apiKey: fusionauthApiKey,
+});
diff --git a/infra/stacks/fusionauth-instance/defaultTenant.ts b/infra/stacks/fusionauth-instance/defaultTenant.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/infra/stacks/fusionauth-instance/docker-compose.yml b/infra/stacks/fusionauth-instance/docker-compose.yml
new file mode 100644
index 0000000000..4cf18d3769
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/docker-compose.yml
@@ -0,0 +1,76 @@
+services:
+ db:
+ image: postgres:16.0-bookworm
+ environment:
+ PGDATA: /var/lib/postgresql/data/pgdata
+ POSTGRES_USER: ${POSTGRES_USER}
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
+ healthcheck:
+ test: [ "CMD-SHELL", "pg_isready -U postgres" ]
+ interval: 5s
+ timeout: 5s
+ retries: 5
+ volumes:
+ - db_data:/var/lib/postgresql/data
+
+ fusionauth:
+ image: fusionauth/fusionauth-app:latest
+ depends_on:
+ db:
+ condition: service_healthy
+ search:
+ condition: service_healthy
+ environment:
+ DATABASE_URL: jdbc:postgresql://db:5432/fusionauth
+ DATABASE_ROOT_USERNAME: ${POSTGRES_USER}
+ DATABASE_ROOT_PASSWORD: ${POSTGRES_PASSWORD}
+ DATABASE_USERNAME: ${DATABASE_USER}
+ DATABASE_PASSWORD: ${DATABASE_PASSWORD}
+ FUSIONAUTH_APP_KICKSTART_FILE: ${FUSIONAUTH_APP_KICKSTART_FILE}
+ FUSIONAUTH_APP_MEMORY: ${FUSIONAUTH_APP_MEMORY}
+ FUSIONAUTH_APP_RUNTIME_MODE: ${FUSIONAUTH_APP_RUNTIME_MODE}
+ FUSIONAUTH_APP_URL: http://fusionauth:9011
+ SEARCH_SERVERS: http://search:9200
+ SEARCH_TYPE: ${FUSIONAUTH_SEARCH_TYPE}
+ healthcheck:
+ test: curl --silent --fail http://localhost:9011/api/status -o /dev/null -w "%{http_code}"
+ interval: 5s
+ timeout: 5s
+ retries: 5
+ ports:
+ - 9011:9011
+ volumes:
+ - fusionauth_config:/usr/local/fusionauth/config
+ - ${FUSIONAUTH_LOCAL_KICKSTART_DIRECTORY}:/usr/local/fusionauth/kickstart
+ - ${FUSIONAUTH_LOCAL_PLUGIN_DIRECTORY}:/usr/local/fusionauth/plugins
+
+ search:
+ image: opensearchproject/opensearch:2.11.0
+ environment:
+ cluster.name: fusionauth
+ discovery.type: single-node
+ node.name: search
+ plugins.security.disabled: true
+ bootstrap.memory_lock: true
+ OPENSEARCH_JAVA_OPTS: ${OPENSEARCH_JAVA_OPTS}
+ healthcheck:
+ interval: 10s
+ retries: 80
+ test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:9200/
+ ulimits:
+ memlock:
+ soft: -1
+ hard: -1
+ nofile:
+ soft: 65536
+ hard: 65536
+ ports:
+ - 9200:9200 # REST API
+ - 9600:9600 # Performance Analyzer
+ volumes:
+ - search_data:/usr/share/opensearch/data
+
+volumes:
+ db_data:
+ fusionauth_config:
+ search_data:
diff --git a/infra/stacks/fusionauth-instance/index.ts b/infra/stacks/fusionauth-instance/index.ts
new file mode 100644
index 0000000000..f1bd5f9ac0
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/index.ts
@@ -0,0 +1,292 @@
+import {
+ FusionAuthApplication,
+ FusionAuthEMail,
+ FusionAuthKey,
+ FusionAuthLambda,
+ FusionAuthReactor,
+ FusionAuthSystemConfiguration,
+ FusionAuthTenant,
+ FusionAuthWebhook,
+} from 'pulumi-fusionauth';
+import * as pulumi from '@pulumi/pulumi';
+import * as fs from 'fs';
+import { config, stack } from '../../packages/shared';
+
+import 'dotenv/config';
+import {
+ AUTHENTICATION_SERVICE_INTERNAL_SECRET,
+ AUTHENTICATION_SERVICE_DOMAIN,
+ DEFAULT_FUSIONAUTH_TENANT_ID,
+ FUSIONAUTH_APPLICATION_CLIENT_ID,
+ FUSIONAUTH_CLIENT_SECRET,
+ FUSIONAUTH_ISSUER,
+ FUSIONAUTH_SIGNING_KEY_ID,
+ fusionAuthProvider,
+ FUSIONAUTH_LICENSE_KEY,
+ SMTP_CREDENTIALS,
+} from './constants';
+import { ALLOWED_ORIGINS } from './origins';
+
+// The main fusionauth provider, this will be passed around when creating various components
+
+// Give access to premium features
+new FusionAuthReactor(
+ 'reactor',
+ {
+ licenseId: pulumi.interpolate`${FUSIONAUTH_LICENSE_KEY}`,
+ },
+ { provider: fusionAuthProvider }
+);
+
+// CORS configuration
+new FusionAuthSystemConfiguration(
+ 'system-config',
+ {
+ corsConfiguration: {
+ allowedOrigins: ['https://appleid.apple.com'],
+ allowedMethods: ['POST'],
+ allowCredentials: true,
+ enabled: true,
+ preflightMaxAgeInSeconds: 1800,
+ },
+ },
+ { provider: fusionAuthProvider }
+);
+
+// Passwordless login email template
+const passwordlessEmailTemplate = new FusionAuthEMail(
+ 'passwordless-email-template',
+ {
+ name: 'Passwordless Login',
+ defaultSubject: 'Log into Macro',
+ defaultHtmlTemplate: fs.readFileSync(
+ './templates/passwordless_email_template.html',
+ 'utf-8'
+ ),
+ defaultTextTemplate: 'Your login code is: ${code}',
+ defaultFromName: 'Macro',
+ },
+ { provider: fusionAuthProvider }
+);
+
+// Email verification template
+const emailVerificationTemplate = new FusionAuthEMail(
+ 'email-verification-template',
+ {
+ name: 'Email Verification',
+ defaultSubject: 'Verify your Macro email',
+ defaultHtmlTemplate: fs
+ .readFileSync('./templates/email_verification_template.html', 'utf-8')
+ .replaceAll('{{AUTH_SERVICE_URL}}', AUTHENTICATION_SERVICE_DOMAIN),
+ defaultTextTemplate:
+ 'Please verify your email by visiting: ${verificationId}',
+ defaultFromName: 'Macro',
+ },
+ { provider: fusionAuthProvider }
+);
+
+// Webhooks
+new FusionAuthWebhook(
+ 'create-user-webhook',
+ {
+ description: 'Create User Webhook',
+ connectTimeout: 1000,
+ readTimeout: 2000,
+ url: `${AUTHENTICATION_SERVICE_DOMAIN}/webhooks/user`,
+ global: true,
+ eventsEnabled: {
+ userCreate: true,
+ userCreateComplete: true,
+ userEmailVerified: true,
+ },
+ headers: {
+ 'x-internal-auth-key': pulumi.interpolate`${AUTHENTICATION_SERVICE_INTERNAL_SECRET}`,
+ },
+ },
+ { provider: fusionAuthProvider }
+);
+
+new FusionAuthWebhook(
+ 'delete-user-webhook',
+ {
+ description: 'Delete User Webhook',
+ connectTimeout: 1000,
+ readTimeout: 2000,
+ url: `${AUTHENTICATION_SERVICE_DOMAIN}/webhooks/user/delete`,
+ global: true,
+ eventsEnabled: {
+ userDelete: true,
+ },
+ headers: {
+ 'x-internal-auth-key': pulumi.interpolate`${AUTHENTICATION_SERVICE_INTERNAL_SECRET}`,
+ },
+ },
+ { provider: fusionAuthProvider }
+);
+
+// Default tenant with email configuration
+const defaultTenant = new FusionAuthTenant(
+ 'default-tenant',
+ {
+ tenantId: DEFAULT_FUSIONAUTH_TENANT_ID,
+ name: 'Default Tenant - DO NOT TOUCH',
+ issuer: FUSIONAUTH_ISSUER,
+ emailConfiguration: {
+ host: 'email-smtp.us-east-1.amazonaws.com',
+ port: 587,
+ username: SMTP_CREDENTIALS.username,
+ password: SMTP_CREDENTIALS.password,
+ security: 'TLS',
+ defaultFromEmail: config.require('default-from-email'),
+ defaultFromName: 'Macro',
+ implicitEmailVerificationAllowed: true,
+ passwordlessEmailTemplateId: passwordlessEmailTemplate.id,
+ // Email Verification
+ verifyEmail: true,
+ verifyEmailWhenChanged: true,
+ verificationEmailTemplateId: emailVerificationTemplate.id,
+ verificationStrategy: 'ClickableLink',
+ },
+ // Delete unverified users
+ userDeletePolicy: {
+ unverifiedEnabled: true,
+ unverifiedNumberOfDaysToRetain: 30,
+ },
+ eventConfigurations: [
+ {
+ enabled: true,
+ event: 'user.create',
+ transactionType: 'AbsoluteMajority',
+ },
+ {
+ enabled: true,
+ event: 'user.create.complete',
+ transactionType: 'None',
+ },
+ {
+ enabled: true,
+ event: 'user.delete.complete',
+ transactionType: 'None',
+ },
+ {
+ enabled: true,
+ event: 'user.email.verified',
+ transactionType: 'AbsoluteMajority',
+ },
+ ],
+ externalIdentifierConfiguration: {
+ passwordlessLoginGenerator: {
+ length: 6,
+ type: 'randomDigits',
+ },
+ },
+ },
+ { provider: fusionAuthProvider }
+);
+
+// Lambda
+const populateLambdaBody = pulumi
+ .output(AUTHENTICATION_SERVICE_INTERNAL_SECRET)
+ .apply((secret) =>
+ fs
+ .readFileSync('./templates/populate_jwt.js', 'utf-8')
+ .replaceAll('{{AUTH_SERVICE_URL}}', AUTHENTICATION_SERVICE_DOMAIN)
+ .replaceAll('{{INTERNAL_SECRET}}', secret)
+ );
+
+const populateJwtLambda = new FusionAuthLambda(
+ 'populate-jwt-lambda',
+ {
+ lambdaId: 'a7f3e8d2-4b91-4c5a-9e6f-1a2b3c4d5e6f', // had to give a manual uuid so the application lambdaConfiguration works
+ name: 'populate_macro_jwt',
+ type: 'JWTPopulate',
+ debug: stack === 'local',
+ body: pulumi.interpolate`${populateLambdaBody}`,
+ },
+ { provider: fusionAuthProvider }
+);
+
+export const populateJwtLambdaId = populateJwtLambda.lambdaId;
+
+// Custom signing key for application
+const signingKey = new FusionAuthKey(
+ 'jwt-signing-key',
+ {
+ keyId: FUSIONAUTH_SIGNING_KEY_ID,
+ algorithm: 'HS256',
+ name: 'JWT Signing Key',
+ },
+ { provider: fusionAuthProvider }
+);
+
+const macroApplication = new FusionAuthApplication(
+ 'macro-application',
+ {
+ name: 'Macro',
+ tenantId: defaultTenant.tenantId,
+ applicationId: FUSIONAUTH_APPLICATION_CLIENT_ID,
+ authenticationTokenConfigurationEnabled: false,
+ loginConfiguration: {
+ allowTokenRefresh: true,
+ requireAuthentication: true,
+ generateRefreshTokens: true,
+ },
+ passwordlessConfigurationEnabled: true,
+ lambdaConfiguration: {
+ accessTokenPopulateId: populateJwtLambda.lambdaId,
+ },
+ jwtConfiguration: {
+ enabled: true,
+ // signing key id for access token
+ accessTokenId: signingKey.keyId,
+ // signing key id for id token
+ idTokenKeyId: signingKey.keyId,
+ ttlSeconds: 3600,
+ refreshTokenExpirationPolicy: 'SlidingWindow',
+ refreshTokenTtlMinutes: 43200,
+ },
+ oauthConfiguration: {
+ clientId: FUSIONAUTH_APPLICATION_CLIENT_ID,
+ clientSecret:
+ FUSIONAUTH_CLIENT_SECRET &&
+ pulumi.interpolate`${FUSIONAUTH_CLIENT_SECRET}`,
+ generateRefreshTokens: true,
+ clientAuthenticationPolicy: 'Required',
+ proofKeyForCodeExchangePolicy: 'NotRequired',
+ scopeHandlingPolicy: 'Compatibility',
+ unknownScopePolicy: 'Remove',
+ authorizedUrlValidationPolicy: 'ExactMatch',
+ authorizedRedirectUrls: [
+ `${AUTHENTICATION_SERVICE_DOMAIN}/oauth/redirect`,
+ ],
+ authorizedOriginUrls: ALLOWED_ORIGINS(),
+ logoutBehavior: 'AllApplications',
+ enabledGrants: ['authorization_code', 'implicit', 'refresh_token'],
+ relationship: 'FirstParty',
+ providedScopePolicies: [
+ {
+ address: {
+ enabled: false,
+ required: false,
+ },
+ email: {
+ enabled: true,
+ required: false,
+ },
+ phone: {
+ enabled: false,
+ required: false,
+ },
+ profile: {
+ enabled: true,
+ required: false,
+ },
+ },
+ ],
+ },
+ },
+ { provider: fusionAuthProvider }
+);
+
+export const macroApplicationClientId =
+ macroApplication.oauthConfiguration.clientId;
diff --git a/infra/stacks/fusionauth-instance/justfile b/infra/stacks/fusionauth-instance/justfile
new file mode 100644
index 0000000000..9cfe07c984
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/justfile
@@ -0,0 +1,11 @@
+setup_fusionauth_env:
+ curl -o .env https://raw.githubusercontent.com/FusionAuth/fusionauth-containers/452efcac5c60f6a3a734947b1a8eefaae6f811fa/docker/fusionauth/.env
+
+start_fusionauth:
+ docker-compose up
+
+destroy_fusionauth:
+ docker-compose down -v
+
+instantiate_fusionauth:
+ pulumi up --stack local
diff --git a/infra/stacks/fusionauth-instance/kickstart/kickstart.json b/infra/stacks/fusionauth-instance/kickstart/kickstart.json
new file mode 100644
index 0000000000..e894dfee96
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/kickstart/kickstart.json
@@ -0,0 +1,24 @@
+{
+ "apiKeys": [
+ {
+ "key": "bf69486b-4733-4954-a44e-2e1b5f2c8a91",
+ "description": "Local Development API Key"
+ }
+ ],
+ "requests": [
+ {
+ "method": "POST",
+ "url": "/api/user/registration",
+ "body": {
+ "user": {
+ "email": "[email protected]",
+ "password": "macroIsGreat!"
+ },
+ "registration": {
+ "applicationId": "3c219e58-ed0e-4b18-ad48-f4f92793ae32",
+ "roles": ["admin"]
+ }
+ }
+ }
+ ]
+}
diff --git a/infra/stacks/fusionauth-instance/origins.ts b/infra/stacks/fusionauth-instance/origins.ts
new file mode 100644
index 0000000000..e4bd685908
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/origins.ts
@@ -0,0 +1,37 @@
+import { stack } from '../../packages/shared';
+import { AUTHENTICATION_SERVICE_DOMAIN } from './constants';
+
+/**
+ * Creates an array of allowed origins for the fusionauth application depending on stack
+ */
+export const ALLOWED_ORIGINS = () => {
+ const allowedOrigins = [AUTHENTICATION_SERVICE_DOMAIN];
+ switch (stack) {
+ case 'local':
+ return [
+ ...allowedOrigins,
+ 'http://localhost:3000',
+ 'http://localhost:5173',
+ ];
+ case 'dev':
+ return [
+ ...allowedOrigins,
+ 'http://localhost:3000',
+ 'https://dev.macro.com',
+ 'http://localhost:8084',
+ 'http://localhost:5173',
+ 'https://dashboarddev.macro.com',
+ ];
+ case 'prod':
+ return [
+ ...allowedOrigins,
+ 'https://macro.com',
+ 'https://dashboard.macro.com',
+ 'https://staging.macro.com',
+ 'https://www.macro.com',
+ 'https://pdf.macro.com',
+ ];
+ }
+
+ throw new Error('invalid stack');
+};
diff --git a/infra/stacks/fusionauth-instance/package.json b/infra/stacks/fusionauth-instance/package.json
new file mode 100644
index 0000000000..11f3687dd3
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "fusionauth-instance-stack",
+ "version": "0.0.0",
+ "private": true,
+ "license": "MIT",
+ "main": "index.ts",
+ "dependencies": {
+ "pulumi-fusionauth": "6.0.2"
+ }
+}
diff --git a/infra/stacks/fusionauth-instance/templates/email_verification_template.html b/infra/stacks/fusionauth-instance/templates/email_verification_template.html
new file mode 100644
index 0000000000..0b23646858
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/templates/email_verification_template.html
@@ -0,0 +1,212 @@
+[#setting url_escaping_charset="UTF-8"]
+<!DOCTYPE html>
+<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="x-apple-disable-message-reformatting" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta
+ name="format-detection"
+ content="telephone=no, date=no, address=no, email=no"
+ />
+ <meta name="color-scheme" content="light dark" />
+ <meta name="supported-color-schemes" content="light dark" />
+ <title>Macro Email Verification</title>
+ <style>
+ body {
+ margin: 0;
+ padding: 0;
+ width: 100% !important;
+ background-color: #f9fafb !important;
+ }
+ .email-container {
+ width: 100%;
+ max-width: 640px;
+ margin: 0 auto;
+ background-color: #f9fafb;
+ }
+ .content-block {
+ background-color: #ffffff;
+ border-radius: 8px;
+ padding: 56px 40px;
+ margin: 0 16px;
+ outline: 1px solid #f3f4f6;
+ }
+ .code-display {
+ margin: 56px auto;
+ width: calc(100% - 64px);
+ max-width: 400px;
+ border-radius: 12px;
+ background-color: #f3f4f6;
+ padding: 32px;
+ text-align: center;
+ font-size: 48px;
+ letter-spacing: 0.2em;
+ color: #374151;
+ font-family: monospace;
+ border: 1px solid #e5e7eb;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+ box-sizing: border-box;
+ }
+
+ /* Button Styles */
+ .button-container {
+ text-align: center;
+ margin: 40px 0;
+ }
+
+ .button {
+ display: inline-block;
+ background-color: #3b82f6;
+ color: #ffffff !important;
+ text-decoration: none !important;
+ padding: 16px 32px;
+ border-radius: 8px;
+ font-size: 16px;
+ font-weight: 600;
+ text-align: center;
+ border: none;
+ cursor: pointer;
+ transition: background-color 0.2s ease;
+ box-shadow: 0 2px 4px rgba(59, 130, 246, 0.15);
+ min-width: 120px;
+ }
+
+ .button:hover {
+ background-color: #2563eb !important;
+ text-decoration: none !important;
+ }
+
+ .button:active {
+ background-color: #1d4ed8 !important;
+ transform: translateY(1px);
+ }
+
+ /* Fallback for email clients that don't support CSS3 */
+ .button-fallback {
+ background-color: #3b82f6;
+ border-radius: 8px;
+ text-align: center;
+ }
+
+ .button-fallback a {
+ display: block;
+ color: #ffffff !important;
+ text-decoration: none !important;
+ padding: 16px 32px;
+ font-size: 16px;
+ font-weight: 600;
+ }
+
+ @media (max-width: 425px) {
+ .content-block {
+ padding: 32px 16px;
+ margin: 0 8px;
+ }
+
+ .code-display {
+ width: calc(100% - 32px);
+ margin: 32px auto;
+ padding: 24px 16px;
+ font-size: 32px;
+ }
+
+ .button {
+ padding: 14px 24px;
+ font-size: 15px;
+ }
+ }
+ </style>
+ </head>
+ <body>
+ <div
+ role="article"
+ aria-roledescription="email"
+ aria-label="Macro Access Code"
+ lang="en"
+ >
+ <table
+ class="email-container"
+ cellpadding="0"
+ cellspacing="0"
+ role="presentation"
+ >
+ <tr>
+ <td align="center" style="padding: 56px 0 32px">
+ <a href="https://macro.com">
+ <img
+ src="https://coparse-release-artifact-storage-bucket.s3.amazonaws.com/logos/logo.png"
+ width="200"
+ alt="Macro"
+ style="border: 0; max-width: 100%"
+ />
+ </a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div class="content-block">
+ <h1
+ style="
+ margin: 0 0 16px;
+ text-align: center;
+ font-size: 36px;
+ font-weight: 600;
+ color: #374151;
+ "
+ >
+ Verify your email
+ </h1>
+ <p
+ style="
+ margin: 0 0 40px;
+ text-align: center;
+ font-size: 16px;
+ color: #6b7280;
+ "
+ >
+ Click the button below to verify your email address.
+ </p>
+
+ <!-- Primary Button (Modern CSS) -->
+ <div class="button-container">
+ <a href="{{AUTH_SERVICE_URL}}/email/verify/fusionauth/${verificationId}" class="button">
+ Verify
+ </a>
+ </div>
+
+ <!-- Fallback Button (Table-based for older email clients) -->
+ <!--[if mso]>
+ <table cellpadding="0" cellspacing="0" role="presentation" style="margin: 40px auto;">
+ <tr>
+ <td class="button-fallback">
+ <a href="{{AUTH_SERVICE_URL}}/email/verify/fusionauth/${verificationId}" style="color: #ffffff !important; text-decoration: none !important; display: block; padding: 16px 32px; font-size: 16px; font-weight: 600;">
+ Verify
+ </a>
+ </td>
+ </tr>
+ </table>
+ <![endif]-->
+
+ <p style="text-align: center; font-size: 16px; color: #6b7280; margin: 40px 0 0;">
+ If you didn't request this, you can safely ignore this email.
+ </p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td style="padding: 48px 0; text-align: center">
+ <p style="margin: 0; font-size: 14px; color: #9ca3af">
+ Questions? Email us at
+ <a
+ href="mailto:[email protected]"
+ style="color: #6b7280; font-weight: 500; text-decoration: none"
+ >
+ </p>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </body>
+</html>
diff --git a/infra/stacks/fusionauth-instance/templates/passwordless_email_template.html b/infra/stacks/fusionauth-instance/templates/passwordless_email_template.html
new file mode 100644
index 0000000000..2f4fe81132
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/templates/passwordless_email_template.html
@@ -0,0 +1,144 @@
+[#setting url_escaping_charset="UTF-8"]
+<!DOCTYPE html>
+<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="x-apple-disable-message-reformatting" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta
+ name="format-detection"
+ content="telephone=no, date=no, address=no, email=no"
+ />
+ <meta name="color-scheme" content="light dark" />
+ <meta name="supported-color-schemes" content="light dark" />
+ <title>Macro Access Code</title>
+ <style>
+ body {
+ margin: 0;
+ padding: 0;
+ width: 100% !important;
+ background-color: #f9fafb !important;
+ }
+
+ .email-container {
+ width: 100%;
+ max-width: 640px;
+ margin: 0 auto;
+ background-color: #f9fafb;
+ }
+
+ .content-block {
+ background-color: #ffffff;
+ border-radius: 8px;
+ padding: 56px 40px;
+ margin: 0 16px;
+ outline: 1px solid #f3f4f6;
+ }
+
+ .code-display {
+ margin: 56px auto;
+ width: calc(100% - 64px);
+ max-width: 400px;
+ border-radius: 12px;
+ background-color: #f3f4f6;
+ padding: 32px;
+ text-align: center;
+ font-size: 48px;
+ letter-spacing: 0.2em;
+ color: #374151;
+ font-family: monospace;
+ border: 1px solid #e5e7eb;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+ box-sizing: border-box;
+ }
+
+ @media (max-width: 425px) {
+ .content-block {
+ padding: 32px 16px;
+ margin: 0 8px;
+ }
+
+ .code-display {
+ width: calc(100% - 32px);
+ margin: 32px auto;
+ padding: 24px 16px;
+ font-size: 32px;
+ }
+ }
+ </style>
+ </head>
+
+ <body>
+ <div
+ role="article"
+ aria-roledescription="email"
+ aria-label="Macro Access Code"
+ lang="en"
+ >
+ <table
+ class="email-container"
+ cellpadding="0"
+ cellspacing="0"
+ role="presentation"
+ >
+ <tr>
+ <td align="center" style="padding: 56px 0 32px">
+ <a href="https://macro.com">
+ <img
+ src="https://coparse-release-artifact-storage-bucket.s3.amazonaws.com/logos/logo.png"
+ width="200"
+ alt="Macro"
+ style="border: 0; max-width: 100%"
+ />
+ </a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div class="content-block">
+ <h1
+ style="
+ margin: 0 0 16px;
+ text-align: center;
+ font-size: 36px;
+ font-weight: 600;
+ color: #374151;
+ "
+ >
+ Login to Macro
+ </h1>
+ <p
+ style="
+ margin: 0;
+ text-align: center;
+ font-size: 16px;
+ color: #6b7280;
+ "
+ >
+ Enter the code below to login.
+ </p>
+ <div class="code-display">
+ ${code}
+ </div>
+ <p style="text-align: center; font-size: 16px; color: #6b7280">
+ If you didn't request this, you can safely ignore this email.
+ </p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td style="padding: 48px 0; text-align: center">
+ <p style="margin: 0; font-size: 14px; color: #9ca3af">
+ Questions? Email us at
+ <a
+ href="mailto:[email protected]"
+ style="color: #6b7280; font-weight: 500; text-decoration: none"
+ >
+ </p>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </body>
+</html>
diff --git a/infra/stacks/fusionauth-instance/templates/populate_jwt.js b/infra/stacks/fusionauth-instance/templates/populate_jwt.js
new file mode 100644
index 0000000000..ecabfcdf13
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/templates/populate_jwt.js
@@ -0,0 +1,31 @@
+// Using the user and registration parameters add additional values to the jwt object.
+function populate(jwt, user, _registration) {
+ jwt.fusion_user_id = user.id;
+ jwt.email = user.email;
+
+ var response = fetch('{{AUTH_SERVICE_URL}}/webhooks/user/jwt', {
+ method: 'POST',
+ headers: {
+ 'x-internal-auth-key': '{{INTERNAL_SECRET}}',
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ email: user.email
+ })
+ });
+
+ if (response.status === 200) {
+ var jsonResponse = JSON.parse(response.body);
+ jwt.macro_user_id = jsonResponse.user_id;
+
+ if (jsonResponse.root_macro_id) {
+ jwt.root_macro_id = jsonResponse.root_macro_id;
+ }
+
+ if(jsonResponse.organization_id){
+ jwt.macro_organization_id = jsonResponse.organization_id;
+ }
+ } else {
+ throw new Error('unable to get user info for jwt');
+ }
+}
diff --git a/infra/stacks/fusionauth-instance/tsconfig.json b/infra/stacks/fusionauth-instance/tsconfig.json
new file mode 100644
index 0000000000..4082f16a5d
--- /dev/null
+++ b/infra/stacks/fusionauth-instance/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.json"
+}
diff --git a/infra/stacks/web-app-preview/index.ts b/infra/stacks/web-app-preview/index.ts
index 441751f65e..fa2c896b2b 100644
--- a/infra/stacks/web-app-preview/index.ts
+++ b/infra/stacks/web-app-preview/index.ts
@@ -1,9 +1,6 @@
import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
-import {
- BASE_DOMAIN,
- stack,
-} from '../../packages/shared/src';
+import { BASE_DOMAIN, stack } from '../../packages/shared/src';
const BASE_NAME = 'preview-deploy';
@@ -30,16 +27,13 @@ const previewCert = new aws.acm.Certificate(
const zone = aws.route53.getZoneOutput({ name: BASE_DOMAIN });
// Create DNS validation record
-const certValidation = new aws.route53.Record(
- `${BASE_NAME}-cert-validation`,
- {
- name: previewCert.domainValidationOptions[0].resourceRecordName,
- type: previewCert.domainValidationOptions[0].resourceRecordType,
- zoneId: zone.zoneId,
- records: [previewCert.domainValidationOptions[0].resourceRecordValue],
- ttl: 60,
- }
-);
+const certValidation = new aws.route53.Record(`${BASE_NAME}-cert-validation`, {
+ name: previewCert.domainValidationOptions[0].resourceRecordName,
+ type: previewCert.domainValidationOptions[0].resourceRecordType,
+ zoneId: zone.zoneId,
+ records: [previewCert.domainValidationOptions[0].resourceRecordValue],
+ ttl: 60,
+});
// Wait for certificate validation
const certValidated = new aws.acm.CertificateValidation(
@@ -127,26 +121,28 @@ const viewerRequestLambda = new aws.lambda.Function(
}
);
-
const bucketRegionalDomainName = pulumi.interpolate`${previewBucket.bucket}.s3.us-east-1.amazonaws.com`;
-const cachePolicy = new aws.cloudfront.CachePolicy(`${BASE_NAME}-cache-policy`, {
- name: `${BASE_NAME}-cache-policy-${stack}`,
- defaultTtl: 60, // 1 minute default
- minTtl: 0,
- maxTtl: 86400, // 1 day max
- parametersInCacheKeyAndForwardedToOrigin: {
- cookiesConfig: {
- cookieBehavior: 'none',
- },
- headersConfig: {
- headerBehavior: 'none',
- },
- queryStringsConfig: {
- queryStringBehavior: 'none',
+const cachePolicy = new aws.cloudfront.CachePolicy(
+ `${BASE_NAME}-cache-policy`,
+ {
+ name: `${BASE_NAME}-cache-policy-${stack}`,
+ defaultTtl: 60, // 1 minute default
+ minTtl: 0,
+ maxTtl: 86400, // 1 day max
+ parametersInCacheKeyAndForwardedToOrigin: {
+ cookiesConfig: {
+ cookieBehavior: 'none',
+ },
+ headersConfig: {
+ headerBehavior: 'none',
+ },
+ queryStringsConfig: {
+ queryStringBehavior: 'none',
+ },
},
- },
-});
+ }
+);
const responseHeadersPolicy = new aws.cloudfront.ResponseHeadersPolicy(
`${BASE_NAME}-response-headers-policy`,