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.

refactor: move internal api key (#4913)

Will Hutchinsonfc90faaf849c
diff --git a/Cargo.lock b/Cargo.lock
index 8edc26f88d..6249f1db7c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3180,6 +3180,7 @@ dependencies = [
"futures",
"http-body-util",
"lambda_client",
+ "macro_auth",
"macro_aws_config",
"macro_config",
"macro_cors",
@@ -12389,6 +12390,7 @@ dependencies = [
"futures",
"http-body-util",
"lexical_client",
+ "macro_auth",
"macro_aws_config",
"macro_config",
"macro_cors",
diff --git a/crates/macro_auth/src/internal_api_key.rs b/crates/macro_auth/src/internal_api_key.rs
new file mode 100644
index 0000000000..4b7c50bc11
--- /dev/null
+++ b/crates/macro_auth/src/internal_api_key.rs
@@ -0,0 +1,8 @@
+use macro_env_var::env_vars;
+
+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 InternalApiKey;
+);
diff --git a/crates/macro_auth/src/lib.rs b/crates/macro_auth/src/lib.rs
index 8e84f072f5..dd41678992 100644
--- a/crates/macro_auth/src/lib.rs
+++ b/crates/macro_auth/src/lib.rs
@@ -1,7 +1,10 @@
pub mod constant;
pub mod error;
pub mod headers;
+mod internal_api_key;
pub mod macro_api_token;
pub mod middleware;
+pub use internal_api_key::InternalApiKey;
+
pub type Result<T, E = error::MacroAuthError> = std::result::Result<T, E>;
diff --git a/crates/macro_auth/tests/internal_api_key.rs b/crates/macro_auth/tests/internal_api_key.rs
new file mode 100644
index 0000000000..4c59971016
--- /dev/null
+++ b/crates/macro_auth/tests/internal_api_key.rs
@@ -0,0 +1,10 @@
+use macro_auth::InternalApiKey;
+
+#[test]
+fn internal_api_key_supports_comptime_clone_and_as_ref() {
+ let internal_api_key = InternalApiKey::Comptime("testing");
+ let cloned_internal_api_key = internal_api_key.clone();
+
+ assert_eq!(internal_api_key.as_ref(), "testing");
+ assert_eq!(cloned_internal_api_key.as_ref(), "testing");
+}
diff --git a/crates/macro_middleware/src/auth/internal_access.rs b/crates/macro_middleware/src/auth/internal_access.rs
index d948162113..e11c0eb73f 100644
--- a/crates/macro_middleware/src/auth/internal_access.rs
+++ b/crates/macro_middleware/src/auth/internal_access.rs
@@ -4,7 +4,7 @@ use axum::{
middleware::Next,
response::Response,
};
-use macro_env_var::env_vars;
+use macro_auth::InternalApiKey;
use model::user::UserContext;
use std::borrow::Cow;
@@ -14,13 +14,6 @@ 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_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 InternalApiKey;
-);
-
/// Sentinel value which represensts that we were able to validate the internal auth key in the header of the request
#[derive(Debug)]
pub struct ValidInternalKey(());
diff --git a/services/authentication_service/src/api/context.rs b/services/authentication_service/src/api/context.rs
index ab40ec7cf2..d8967bae56 100644
--- a/services/authentication_service/src/api/context.rs
+++ b/services/authentication_service/src/api/context.rs
@@ -11,11 +11,10 @@ use github::outbound::github_auth_client::GithubAuthImpl;
use github::outbound::github_oauth_client::GithubOauthImpl;
use github::outbound::pg_github_repo::PgGithubRepo;
use loops_client::LoopsClient;
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
+use macro_auth::{InternalApiKey, 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::InternalApiKey;
use native_app_service::{domain::service::NativeAppServiceImpl, outbound::DefaultBundleFetcher};
use notification::outbound::queue::SqsQueue;
use notification::{
diff --git a/services/authentication_service/src/config.rs b/services/authentication_service/src/config.rs
index ad11e82c4d..c0260b9936 100644
--- a/services/authentication_service/src/config.rs
+++ b/services/authentication_service/src/config.rs
@@ -2,9 +2,9 @@ use std::sync::LazyLock;
use anyhow::Context;
use database_env_vars::{DatabaseUrl, RedisUri};
+use macro_auth::InternalApiKey;
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.rs
pub static BASE_URL: LazyLock<String> = LazyLock::new(|| {
diff --git a/services/connection_gateway/src/config.rs b/services/connection_gateway/src/config.rs
index bc4b5b7f18..1e9473e994 100644
--- a/services/connection_gateway/src/config.rs
+++ b/services/connection_gateway/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-use macro_middleware::auth::internal_access::InternalApiKey;
use secretsmanager_client::LocalOrRemoteSecret;
env_vars! {
diff --git a/services/connection_gateway/src/context.rs b/services/connection_gateway/src/context.rs
index c0521f72a2..d1acc5f3a6 100644
--- a/services/connection_gateway/src/context.rs
+++ b/services/connection_gateway/src/context.rs
@@ -6,8 +6,7 @@ use frecency::{
outbound::postgres::FrecencyPgStorage,
};
use last_online_tracker::inbound::LastOnlineWorker;
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::{InternalApiKey, middleware::decode_jwt::JwtValidationArgs};
use redis::{RedisError, aio::MultiplexedConnection};
use std::sync::Arc;
use stream::domain::StreamManager;
diff --git a/services/contacts_service/src/config.rs b/services/contacts_service/src/config.rs
index 9fba844d42..5a10ecfc0b 100644
--- a/services/contacts_service/src/config.rs
+++ b/services/contacts_service/src/config.rs
@@ -1,8 +1,8 @@
use anyhow::Context;
use database_env_vars::{DatabaseUrl, RedisUri};
+use macro_auth::InternalApiKey;
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;
diff --git a/services/convert_service/Cargo.toml b/services/convert_service/Cargo.toml
index ae7418022c..651c6d7977 100644
--- a/services/convert_service/Cargo.toml
+++ b/services/convert_service/Cargo.toml
@@ -26,6 +26,7 @@ doppler-config = { workspace = true }
futures = { workspace = true }
http-body-util = { workspace = true }
lambda_client = { path = "../../crates/lambda_client" }
+macro_auth = { path = "../../crates/macro_auth" }
macro_aws_config = { path = "../../crates/macro_aws_config", features = ["s3"] }
macro_cors = { path = "../../crates/macro_cors" }
macro_config = { path = "../../crates/macro_config" }
diff --git a/services/convert_service/src/api/context.rs b/services/convert_service/src/api/context.rs
index 9a0460204b..0423d28d13 100644
--- a/services/convert_service/src/api/context.rs
+++ b/services/convert_service/src/api/context.rs
@@ -1,5 +1,5 @@
use axum::extract::FromRef;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::InternalApiKey;
use s3_client::S3;
use std::sync::Arc;
diff --git a/services/convert_service/src/api/mod.rs b/services/convert_service/src/api/mod.rs
index bd50b11b1b..5c0c352a73 100644
--- a/services/convert_service/src/api/mod.rs
+++ b/services/convert_service/src/api/mod.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
use axum::Router;
use context::ApiContext;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::InternalApiKey;
use tower::ServiceBuilder;
use tower_http::trace::TraceLayer;
use utoipa::OpenApi;
diff --git a/services/convert_service/src/config.rs b/services/convert_service/src/config.rs
index 9c8c3551a0..6781ff15e1 100644
--- a/services/convert_service/src/config.rs
+++ b/services/convert_service/src/config.rs
@@ -2,9 +2,9 @@ use std::sync::LazyLock;
use anyhow::Context;
use database_env_vars::DatabaseUrl;
+use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-use macro_middleware::auth::internal_access::InternalApiKey;
/// The path to the LibreOffice binary
pub static LOK_PATH: LazyLock<String> = LazyLock::new(|| {
diff --git a/services/document_cognition_service/src/api/context/mod.rs b/services/document_cognition_service/src/api/context/mod.rs
index 2bcc845dd1..16a84c31fc 100644
--- a/services/document_cognition_service/src/api/context/mod.rs
+++ b/services/document_cognition_service/src/api/context/mod.rs
@@ -17,8 +17,7 @@ use document_storage_service_client::DocumentStorageServiceClient;
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::InternalApiKey;
+use macro_auth::{InternalApiKey, middleware::decode_jwt::JwtValidationArgs};
use notification::domain::service::SqsNotificationIngress;
use notification::outbound::queue::SqsQueue;
use notification::outbound::websocket::ConnectionGatewayClient;
diff --git a/services/document_cognition_service/src/config.rs b/services/document_cognition_service/src/config.rs
index 4eecaf8b63..f23dad4560 100644
--- a/services/document_cognition_service/src/config.rs
+++ b/services/document_cognition_service/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
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::AiEditingWorkerUrl;
use secretsmanager_client::LocalOrRemoteSecret;
diff --git a/services/document_storage_service/src/config.rs b/services/document_storage_service/src/config.rs
index 7e7a3c45bf..f3e6e16dfe 100644
--- a/services/document_storage_service/src/config.rs
+++ b/services/document_storage_service/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
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
diff --git a/services/email_service/src/api/context.rs b/services/email_service/src/api/context.rs
index 93b016ab8a..350ceaee10 100644
--- a/services/email_service/src/api/context.rs
+++ b/services/email_service/src/api/context.rs
@@ -14,9 +14,9 @@ use email_service::util::redis::RedisClient;
use entity_access::{domain::service::EntityAccessServiceImpl, outbound::PgAccessRepository};
use entity_access_management::domain::service::EntityAccessManagementServiceImpl;
use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::FrecencyPgStorage};
+use macro_auth::InternalApiKey;
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_event_broker::{KafkaEventPublisher, MacroEventBrokerService};
-use macro_middleware::auth::internal_access::InternalApiKey;
use static_file_service_client::StaticFileServiceClient;
use std::sync::Arc;
use system_properties::{PgSystemPropertiesRepository, SystemPropertiesServiceImpl};
diff --git a/services/email_service/src/config.rs b/services/email_service/src/config.rs
index 7f9360ab31..f1709224cb 100644
--- a/services/email_service/src/config.rs
+++ b/services/email_service/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-use macro_middleware::auth::internal_access::InternalApiKey;
use secretsmanager_client::LocalOrRemoteSecret;
env_vars! {
diff --git a/services/mcp_service/src/config.rs b/services/mcp_service/src/config.rs
index 611059801d..68edc1875c 100644
--- a/services/mcp_service/src/config.rs
+++ b/services/mcp_service/src/config.rs
@@ -7,9 +7,9 @@
use anyhow::Context;
use database_env_vars::DatabaseUrl;
+pub use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-pub use macro_middleware::auth::internal_access::InternalApiKey;
env_vars! {
/// Auth key used by the document storage / search / lexical clients.
diff --git a/services/notification_service/src/api/context.rs b/services/notification_service/src/api/context.rs
index ddaf9a3ad8..a5f9d72cd7 100644
--- a/services/notification_service/src/api/context.rs
+++ b/services/notification_service/src/api/context.rs
@@ -1,7 +1,6 @@
use crate::config::Config;
use axum::extract::FromRef;
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::{InternalApiKey, middleware::decode_jwt::JwtValidationArgs};
use sqlx::PgPool;
use std::sync::Arc;
diff --git a/services/notification_service/src/config.rs b/services/notification_service/src/config.rs
index cdbc22bf13..fa6c6c6910 100644
--- a/services/notification_service/src/config.rs
+++ b/services/notification_service/src/config.rs
@@ -1,8 +1,8 @@
use anyhow::Context;
use database_env_vars::{DatabaseUrl, RedisUri};
+use macro_auth::InternalApiKey;
use macro_env::Environment;
use macro_env_var::{env_var, env_vars, maybe_env_var};
-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
diff --git a/services/scheduled_action/src/config.rs b/services/scheduled_action/src/config.rs
index 401e3a49dc..ec5d19a0e6 100644
--- a/services/scheduled_action/src/config.rs
+++ b/services/scheduled_action/src/config.rs
@@ -12,9 +12,9 @@
use anyhow::Context;
use database_env_vars::DatabaseUrl;
+use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-use macro_middleware::auth::internal_access::InternalApiKey;
env_vars! {
/// Auth key used by the document storage / search / lexical clients.
diff --git a/services/search_processing_service/Cargo.toml b/services/search_processing_service/Cargo.toml
index 0937533991..345e667e89 100644
--- a/services/search_processing_service/Cargo.toml
+++ b/services/search_processing_service/Cargo.toml
@@ -33,6 +33,7 @@ email_db_client = { path = "../../crates/email_db_client" }
futures = { workspace = true }
http-body-util = { workspace = true }
lexical_client = { path = "../../crates/lexical_client" }
+macro_auth = { path = "../../crates/macro_auth" }
macro_aws_config = { path = "../../crates/macro_aws_config", features = ["s3"] }
macro_cors = { path = "../../crates/macro_cors" }
macro_config = { path = "../../crates/macro_config" }
diff --git a/services/search_processing_service/src/api/context.rs b/services/search_processing_service/src/api/context.rs
index e4d79085ec..d2eed276de 100644
--- a/services/search_processing_service/src/api/context.rs
+++ b/services/search_processing_service/src/api/context.rs
@@ -1,5 +1,5 @@
use axum::extract::FromRef;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::InternalApiKey;
use std::sync::Arc;
use crate::BackfillServiceImpl;
diff --git a/services/search_processing_service/src/api/mod.rs b/services/search_processing_service/src/api/mod.rs
index 513c86471d..edfe7b7629 100644
--- a/services/search_processing_service/src/api/mod.rs
+++ b/services/search_processing_service/src/api/mod.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
use axum::Router;
use context::ApiContext;
-use macro_middleware::auth::internal_access::InternalApiKey;
+use macro_auth::InternalApiKey;
use tower::ServiceBuilder;
use tower_http::trace::TraceLayer;
use utoipa::OpenApi;
diff --git a/services/search_processing_service/src/config.rs b/services/search_processing_service/src/config.rs
index 335a8728d8..d3213ba210 100644
--- a/services/search_processing_service/src/config.rs
+++ b/services/search_processing_service/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
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! {
diff --git a/services/static_file_service/src/api/context.rs b/services/static_file_service/src/api/context.rs
index d391e809da..0aa3d88681 100644
--- a/services/static_file_service/src/api/context.rs
+++ b/services/static_file_service/src/api/context.rs
@@ -3,7 +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::InternalApiKey;
+use macro_auth::InternalApiKey;
use std::sync::Arc;
#[derive(Clone, FromRef)]
diff --git a/services/static_file_service/src/config.rs b/services/static_file_service/src/config.rs
index d934e38e1b..4eeafb7bfe 100644
--- a/services/static_file_service/src/config.rs
+++ b/services/static_file_service/src/config.rs
@@ -1,7 +1,7 @@
use anyhow::Context;
+use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::env_vars;
-use macro_middleware::auth::internal_access::InternalApiKey;
use macro_service_urls::StaticFileServiceUrl;
env_vars! {