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.

fix(auth): read Cursor KMS key from process env (#5933)

Wolf Mermelsteina03ff153e8d5
diff --git a/services/authentication_service/src/config.rs b/services/authentication_service/src/config.rs
index 96998a2ab6..432baed463 100644
--- a/services/authentication_service/src/config.rs
+++ b/services/authentication_service/src/config.rs
@@ -48,7 +48,9 @@ maybe_env_vars! {
/// definition rather than Doppler, and the Doppler config validator
/// deserializes this struct from Doppler alone — a required field it
/// cannot see fails CI. The service still refuses to start without it;
- /// see `cursor_api_key_kms_key_id`.
+ /// see [`Config::cursor_api_key_kms_key_id`], which also reads the
+ /// process environment because `MacroConfig` does not fall back to it
+ /// when `APP_SECRETS_JSON` is present.
pub struct CursorApiKeyKmsKeyId;
pub struct GaMeasurementId;
pub struct GaApiSecret;
@@ -173,9 +175,16 @@ impl Config {
/// feature of the settings surface, and a service that cannot encrypt one
/// should fail at startup rather than at the first user who tries.
pub(crate) fn cursor_api_key_kms_key_id(&self) -> anyhow::Result<String> {
- nonblank_value(self.cursor_api_key_kms_key_id.value())
- .map(str::to_owned)
- .context("CURSOR_API_KEY_KMS_KEY_ID is required")
+ // `MacroConfig` will not see a Pulumi-injected process env var once
+ // Doppler's `APP_SECRETS_JSON` is present. Re-read through the env-var
+ // type, which does fall back to process env.
+ let from_process_env = CursorApiKeyKmsKeyId::new();
+ resolve_cursor_api_key_kms_key_id(
+ &self.cursor_api_key_kms_key_id,
+ from_process_env
+ .as_ref()
+ .and_then(CursorApiKeyKmsKeyId::value),
+ )
}
/// Resolves Microsoft credentials, enforcing that all values are configured together.
@@ -223,5 +232,20 @@ fn nonblank_value(value: Option<&str>) -> Option<&str> {
value.filter(|value| !value.trim().is_empty())
}
+/// Pulumi injects `CURSOR_API_KEY_KMS_KEY_ID` as a container env var, not
+/// through Doppler. ECS always has `APP_SECRETS_JSON`, and `MacroConfig` will
+/// not look at process env once that blob is present, so the field on `Config`
+/// is unset in deployed environments. `CursorApiKeyKmsKeyId::new()` still
+/// falls back to process env, which is what `process_env` is.
+fn resolve_cursor_api_key_kms_key_id(
+ configured: &CursorApiKeyKmsKeyId,
+ process_env: Option<&str>,
+) -> anyhow::Result<String> {
+ nonblank_value(configured.value())
+ .or_else(|| nonblank_value(process_env))
+ .map(str::to_owned)
+ .context("CURSOR_API_KEY_KMS_KEY_ID is required")
+}
+
#[cfg(test)]
mod test;
diff --git a/services/authentication_service/src/config/test.rs b/services/authentication_service/src/config/test.rs
index 7b3149dbbc..483e9bb831 100644
--- a/services/authentication_service/src/config/test.rs
+++ b/services/authentication_service/src/config/test.rs
@@ -139,3 +139,46 @@ fn microsoft_token_kms_key_id(value: Option<&'static str>) -> MicrosoftTokenKmsK
None => MicrosoftTokenKmsKeyId::new_unset(),
}
}
+
+#[test]
+fn cursor_kms_key_from_config_field() {
+ let configured = CursorApiKeyKmsKeyId::new_testing("arn:aws:kms:from-config");
+ assert_eq!(
+ resolve_cursor_api_key_kms_key_id(&configured, None).unwrap(),
+ "arn:aws:kms:from-config"
+ );
+}
+
+#[test]
+fn cursor_kms_key_from_process_env_when_config_unset() {
+ let configured = CursorApiKeyKmsKeyId::new_unset();
+ assert_eq!(
+ resolve_cursor_api_key_kms_key_id(&configured, Some("arn:aws:kms:from-env")).unwrap(),
+ "arn:aws:kms:from-env"
+ );
+}
+
+#[test]
+fn cursor_kms_key_prefers_config_over_process_env() {
+ let configured = CursorApiKeyKmsKeyId::new_testing("arn:aws:kms:from-config");
+ assert_eq!(
+ resolve_cursor_api_key_kms_key_id(&configured, Some("arn:aws:kms:from-env")).unwrap(),
+ "arn:aws:kms:from-config"
+ );
+}
+
+#[test]
+fn cursor_kms_key_blank_config_falls_back_to_process_env() {
+ let configured = CursorApiKeyKmsKeyId::new_testing(" ");
+ assert_eq!(
+ resolve_cursor_api_key_kms_key_id(&configured, Some("arn:aws:kms:from-env")).unwrap(),
+ "arn:aws:kms:from-env"
+ );
+}
+
+#[test]
+fn cursor_kms_key_required_when_both_absent() {
+ let configured = CursorApiKeyKmsKeyId::new_unset();
+ let error = resolve_cursor_api_key_kms_key_id(&configured, None).unwrap_err();
+ assert!(error.to_string().contains("CURSOR_API_KEY_KMS_KEY_ID"));
+}