Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(vault): route HyperswitchVault calls through an optional egress proxy (#13434)
Shankar Singh Cacb21b142413
diff --git a/crates/external_services/src/grpc_client/unified_connector_service.rs b/crates/external_services/src/grpc_client/unified_connector_service.rsindex 797fc90444..05dd46ac95 100644--- a/crates/external_services/src/grpc_client/unified_connector_service.rs+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs@@ -262,6 +262,11 @@ pub struct HyperswitchVaultMetadata {pub vault_endpoint: Url,/// Authentication data for the vault connectorpub vault_auth_data: VaultConnectorAuth,+ /// Optional egress proxy URL (e.g. Squid). Absent for in-cluster deployments. Unlike+ /// VGS's MITM proxy, this is a plain CONNECT-tunnel proxy, so no CA certificate is+ /// needed here.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub proxy_url: Option<Url>,}/// Failure to build the Unified Connector Service client from configuration.diff --git a/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault.rs b/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault.rsindex 414dc2d366..050cd1a500 100644--- a/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault.rs+++ b/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault.rs@@ -36,6 +36,7 @@ use hyperswitch_interfaces::{ConnectorValidation,},configs::Connectors,+ consts::USER_AGENT,errors,events::connector_api_logs::ConnectorEvent,types::{self, Response},@@ -193,6 +194,10 @@ whereheaders::X_PROFILE_ID.to_string(),auth.profile_id.expose().into_masked(),),+ (+ headers::USER_AGENT.to_string(),+ USER_AGENT.to_string().into(),+ ),];Ok(header)}diff --git a/crates/injector/src/injector.rs b/crates/injector/src/injector.rsindex e50510318c..85425ed219 100644--- a/crates/injector/src/injector.rs+++ b/crates/injector/src/injector.rs@@ -923,6 +923,12 @@ pub mod core {"x-profile-id".to_string(),hyperswitch_masking::Maskable::Masked(vault_auth.profile_id.clone()),),+ (+ "User-Agent".to_string(),+ hyperswitch_masking::Maskable::new_normal(+ "Hyperswitch-Backend-Server".to_string(),+ ),+ ),];let request_builder = RequestBuilder::new()@@ -931,6 +937,7 @@ pub mod core {.headers(vault_headers).set_body(RequestContent::Json(Box::new(vault_proxy_request)));+ let config = &request.connection_config;let http_request = request_builder.build();let vault_endpoint_host = vault_endpoint.host_str().unwrap_or("unknown").to_string();@@ -942,7 +949,13 @@ pub mod core {),);- let response = send_request(&Proxy::default(), http_request).await?;+ let proxy = Proxy::from_optional_url(+ config+ .proxy_url+ .clone()+ .or_else(|| config.backup_proxy_url.clone()),+ );+ let response = send_request(&proxy, http_request).await?;response.into_injector_response().awaitdiff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rsindex c2552a3c77..c6977a0071 100644--- a/crates/router/src/core/payment_methods/transformers.rs+++ b/crates/router/src/core/payment_methods/transformers.rs@@ -29,6 +29,8 @@ use hyperswitch_domain_models::payment_methods::{#[cfg(feature = "v2")]use hyperswitch_domain_models::{payment_method_data, sdk_auth::SdkAuthorization};#[cfg(feature = "v1")]+use hyperswitch_interfaces::consts::USER_AGENT;+#[cfg(feature = "v1")]use hyperswitch_masking::Mask;use hyperswitch_masking::{ExposeInterface, PeekInterface};use josekit::jwe;@@ -2248,6 +2250,9 @@ struct VaultTokenDetailsResponse {/// targets `connectors.hyperswitch_vault.base_url` (which already includes the `/v2` prefix) and is/// authenticated as the merchant using the external vault connector account's credentials/// (`api-key` + profile id) — not the pay server's internal API key.+///+/// Traffic to the vault is routed through the router-wide `[proxy]` config (e.g. a Squid+/// egress proxy required by self-hosted / non-PCI deployments), if configured.#[cfg(feature = "v1")]pub async fn get_permanent_pm_id_from_temporary_token(state: &routes::SessionState,@@ -2275,6 +2280,10 @@ pub async fn get_permanent_pm_id_from_temporary_token(headers::X_PROFILE_ID.to_string(),vault_profile_id.expose().into_masked(),),+ (+ headers::USER_AGENT.to_string(),+ USER_AGENT.to_string().into(),+ ),]).build();diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex 395e2c7ae4..7eefce8a7d 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -1799,6 +1799,7 @@ pub async fn call_unified_connector_service_pre_authenticate_proxy(unified_connector_service::build_unified_connector_service_external_vault_proxy_metadata_v1(external_vault_merchant_connector_account,&state.conf.connectors,+ &state.conf.proxy,).change_context(interface_errors::ConnectorError::RequestEncodingFailed).attach_printable("Failed to construct external vault proxy metadata")?;diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rsindex d5ada11e83..b85664d1e0 100644--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs@@ -953,6 +953,7 @@ pub async fn call_unified_connector_service_authenticate_proxy(ucs_core::build_unified_connector_service_external_vault_proxy_metadata_v1(external_vault_merchant_connector_account,&state.conf.connectors,+ &state.conf.proxy,).change_context(interface_errors::ConnectorError::RequestEncodingFailed).attach_printable("Failed to construct external vault proxy metadata")?;@@ -1202,6 +1203,7 @@ pub async fn call_unified_connector_service_post_authenticate_proxy(ucs_core::build_unified_connector_service_external_vault_proxy_metadata_v1(external_vault_merchant_connector_account,&state.conf.connectors,+ &state.conf.proxy,).change_context(interface_errors::ConnectorError::RequestEncodingFailed).attach_printable("Failed to construct external vault proxy metadata")?;diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rsindex 228093b1e1..1a67db272a 100644--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs@@ -434,6 +434,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>unified_connector_service::build_unified_connector_service_external_vault_proxy_metadata(external_vault_merchant_connector_account,&state.conf.connectors,+ &state.conf.proxy,).change_context(ApiErrorResponse::InternalServerError).attach_printable("Failed to construct external vault proxy metadata")?;@@ -547,6 +548,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>unified_connector_service::build_unified_connector_service_external_vault_proxy_metadata_v1(external_vault_merchant_connector_account.clone(),&state.conf.connectors,+ &state.conf.proxy,).change_context(ApiErrorResponse::InternalServerError).attach_printable("Failed to construct external vault proxy metadata")?;diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rsindex bb2154e333..19b5f54832 100644--- a/crates/router/src/core/unified_connector_service.rs+++ b/crates/router/src/core/unified_connector_service.rs@@ -2845,6 +2845,7 @@ pub fn parse_merchant_payout_reference_id(id: &str) -> Option<id_type::PayoutRefpub fn build_unified_connector_service_external_vault_proxy_metadata_v1(external_vault_merchant_connector_account: MerchantConnectorAccountType,connectors: &hyperswitch_domain_models::connector_endpoints::Connectors,+ proxy: &hyperswitch_interfaces::types::Proxy,) -> CustomResult<String, UnifiedConnectorServiceError> {let connector_name = external_vault_merchant_connector_account.get_connector_name()@@ -2911,6 +2912,22 @@ pub fn build_unified_connector_service_external_vault_proxy_metadata_v1(}};+ // HyperswitchVault's egress proxy is a deployment-wide concern (reaching the+ // SaaS vault from a network with no direct internet access), not a per-merchant+ // one like VGS's MITM proxy — so it's sourced from the router's own [proxy]+ // config rather than per-MCA metadata.+ let proxy_url = proxy+ .https_url+ .as_ref()+ .or(proxy.http_url.as_ref())+ .map(|url| {+ url.parse::<url::Url>()+ .map(common_utils::types::Url::wrap)+ .change_context(UnifiedConnectorServiceError::ParsingFailed)+ .attach_printable("Failed to parse configured proxy URL")+ })+ .transpose()?;+external_services::grpc_client::unified_connector_service::ExternalVaultProxyConfig {vault_connector_type:external_services::grpc_client::unified_connector_service::VaultConnectorType::Transformation,@@ -2922,6 +2939,7 @@ pub fn build_unified_connector_service_external_vault_proxy_metadata_v1(api_key,profile_id,},+ proxy_url,},),}@@ -2946,6 +2964,7 @@ pub fn build_unified_connector_service_external_vault_proxy_metadata_v1(pub fn build_unified_connector_service_external_vault_proxy_metadata(external_vault_merchant_connector_account: MerchantConnectorAccountTypeDetails,connectors: &hyperswitch_domain_models::connector_endpoints::Connectors,+ proxy: &hyperswitch_interfaces::types::Proxy,) -> CustomResult<String, UnifiedConnectorServiceError> {let connector = external_vault_merchant_connector_account.get_connector_name();@@ -3008,6 +3027,22 @@ pub fn build_unified_connector_service_external_vault_proxy_metadata(}};+ // HyperswitchVault's egress proxy is a deployment-wide concern (reaching the+ // SaaS vault from a network with no direct internet access), not a per-merchant+ // one like VGS's MITM proxy — so it's sourced from the router's own [proxy]+ // config rather than per-MCA metadata.+ let proxy_url = proxy+ .https_url+ .as_ref()+ .or(proxy.http_url.as_ref())+ .map(|url| {+ url.parse::<url::Url>()+ .map(common_utils::types::Url::wrap)+ .change_context(UnifiedConnectorServiceError::ParsingFailed)+ .attach_printable("Failed to parse configured proxy URL")+ })+ .transpose()?;+external_services::grpc_client::unified_connector_service::ExternalVaultProxyConfig {vault_connector_type:external_services::grpc_client::unified_connector_service::VaultConnectorType::Transformation,@@ -3019,6 +3054,7 @@ pub fn build_unified_connector_service_external_vault_proxy_metadata(api_key,profile_id,},+ proxy_url,},),}