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(external_services): add GCP Cloud KMS as a secrets/encryption manager backend (#13834)
Harshvardhan Bahukhandi9d3a9dfc824a
diff --git a/Cargo.lock b/Cargo.lockindex a61ed3999b..a498a76048 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -193,7 +193,7 @@ dependencies = ["rustls-pki-types","tokio 1.48.0","tokio-rustls 0.23.4",- "tokio-rustls 0.25.0",+ "tokio-rustls 0.26.2","tokio-util","tracing","webpki-roots 0.22.6",@@ -3573,6 +3573,7 @@ dependencies = ["deja","dyn-clone","error-stack 0.4.1",+ "google-cloud-kms","hex","http 0.2.12","http-body 1.0.1",@@ -4127,6 +4128,92 @@ dependencies = ["scroll",]+[[package]]+name = "google-cloud-auth"+version = "0.17.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e57a13fbacc5e9c41ded3ad8d0373175a6b7a6ad430d99e89d314ac121b7ab06"+dependencies = [+ "async-trait",+ "base64 0.21.7",+ "google-cloud-metadata",+ "google-cloud-token",+ "home",+ "jsonwebtoken",+ "reqwest 0.12.7",+ "serde",+ "serde_json",+ "thiserror 1.0.69",+ "time 0.3.41",+ "tokio 1.48.0",+ "tracing",+ "urlencoding",+]++[[package]]+name = "google-cloud-gax"+version = "0.19.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "de13e62d7e0ffc3eb40a0113ddf753cf6ec741be739164442b08893db4f9bfca"+dependencies = [+ "google-cloud-token",+ "http 1.3.1",+ "thiserror 1.0.69",+ "tokio 1.48.0",+ "tokio-retry2",+ "tonic 0.12.3",+ "tower 0.4.13",+ "tracing",+]++[[package]]+name = "google-cloud-googleapis"+version = "0.16.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "886aa8ec755382a1fdf4651f6e6ec01f2f3bf49f2cb0f068b9a74cafd574a715"+dependencies = [+ "prost 0.13.5",+ "prost-types 0.13.5",+ "tonic 0.12.3",+]++[[package]]+name = "google-cloud-kms"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8e8842723521d34b9bf43305c84fd469c4d1858c42a630e1cb8c0d9c53781551"+dependencies = [+ "google-cloud-auth",+ "google-cloud-gax",+ "google-cloud-googleapis",+ "google-cloud-token",+ "prost-types 0.13.5",+ "serde",+ "serde_json",+ "thiserror 1.0.69",+ "tracing",+]++[[package]]+name = "google-cloud-metadata"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d901aeb453fd80e51d64df4ee005014f6cf39f2d736dd64f7239c132d9d39a6a"+dependencies = [+ "reqwest 0.12.7",+ "thiserror 1.0.69",+ "tokio 1.48.0",+]++[[package]]+name = "google-cloud-token"+version = "0.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f49c12ba8b21d128a2ce8585955246977fbce4415f680ebf9199b6f9d6d725f"+dependencies = [+ "async-trait",+]+[[package]]name = "graphviz-rust"version = "0.6.6"@@ -8378,7 +8465,7 @@ dependencies = ["rust-i18n","rust_decimal","rustc-hash 1.1.0",- "rustls 0.22.4",+ "rustls 0.23.27","rustls-pemfile 2.1.3","scheduler","serde",@@ -8685,20 +8772,6 @@ dependencies = ["sct",]-[[package]]-name = "rustls"-version = "0.22.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432"-dependencies = [- "log 0.4.27",- "ring 0.17.14",- "rustls-pki-types",- "rustls-webpki 0.102.8",- "subtle",- "zeroize",-]-[[package]]name = "rustls"version = "0.23.27"@@ -8706,6 +8779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321"dependencies = ["aws-lc-rs",+ "log 0.4.27","once_cell","ring 0.17.14","rustls-pki-types",@@ -8776,17 +8850,6 @@ dependencies = ["untrusted 0.9.0",]-[[package]]-name = "rustls-webpki"-version = "0.102.8"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"-dependencies = [- "ring 0.17.14",- "rustls-pki-types",- "untrusted 0.9.0",-]-[[package]]name = "rustls-webpki"version = "0.103.3"@@ -10676,6 +10739,16 @@ dependencies = ["tokio-sync",]+[[package]]+name = "tokio-retry2"+version = "0.5.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3a0a122635e32bd827df297f311ca5e0292636bbd82f67ff84a4bedeab06dbeb"+dependencies = [+ "pin-project",+ "tokio 1.48.0",+]+[[package]]name = "tokio-rustls"version = "0.23.4"@@ -10697,17 +10770,6 @@ dependencies = ["tokio 1.48.0",]-[[package]]-name = "tokio-rustls"-version = "0.25.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f"-dependencies = [- "rustls 0.22.4",- "rustls-pki-types",- "tokio 1.48.0",-]-[[package]]name = "tokio-rustls"version = "0.26.2"@@ -10916,6 +10978,7 @@ dependencies = ["axum 0.7.5","base64 0.22.1","bytes 1.10.1",+ "flate2","h2 0.4.8","http 1.3.1","http-body 1.0.1",@@ -10926,13 +10989,16 @@ dependencies = ["percent-encoding 2.3.1","pin-project","prost 0.13.5",+ "rustls-pemfile 2.1.3","socket2 0.5.10","tokio 1.48.0",+ "tokio-rustls 0.26.2","tokio-stream","tower 0.4.13","tower-layer","tower-service","tracing",+ "webpki-roots 0.26.11",][[package]]diff --git a/config/config.example.toml b/config/config.example.tomlindex fece980b75..ea017b230c 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -1323,19 +1323,35 @@ region = "us-east-1" # The AWS region used by the AWS S3 for file storagebucket_name = "bucket1" # The AWS S3 bucket name for file storage[secrets_management]-secrets_manager = "aws_kms" # Secrets manager client to be used+secrets_manager = "aws_kms" # Secrets manager client to be used (no_encryption | aws_kms | hashicorp_vault | gcp_kms)+# Required only if `secrets_manager` above is set to "aws_kms"[secrets_management.aws_kms]key_id = "kms_key_id" # The AWS key ID used by the KMS SDK for decrypting data.region = "kms_region" # The AWS region used by the KMS SDK for decrypting data.+# Required only if `secrets_manager` above is set to "gcp_kms"+[secrets_management.gcp_kms]+project_id = "gcp_project_id"+location_id = "gcp_kms_location_id" # e.g. "global", "us-east1"+key_ring_id = "gcp_kms_key_ring_id"+key_id = "gcp_kms_key_id"+[encryption_management]-encryption_manager = "aws_kms" # Encryption manager client to be used+encryption_manager = "aws_kms" # Encryption manager client to be used (no_encryption | aws_kms | gcp_kms)+# Required only if `encryption_manager` above is set to "aws_kms"[encryption_management.aws_kms]key_id = "kms_key_id" # The AWS key ID used by the KMS SDK for decrypting data.region = "kms_region" # The AWS region used by the KMS SDK for decrypting data.+# Required only if `encryption_manager` above is set to "gcp_kms"+[encryption_management.gcp_kms]+project_id = "gcp_project_id"+location_id = "gcp_kms_location_id"+key_ring_id = "gcp_kms_key_ring_id"+key_id = "gcp_kms_key_id"+[crm]crm_manager = "hubspot_proxy" # Crm manager client to be useddiff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex 3d3b770774..7952110686 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -361,19 +361,35 @@ private_key = "/path/to/private_key.pem"certificate = "/path/to/certificate.pem"[secrets_management]-secrets_manager = "aws_kms" # Secrets manager client to be used+secrets_manager = "aws_kms" # Secrets manager client to be used (no_encryption | aws_kms | hashicorp_vault | gcp_kms)+# Required only if `secrets_manager` above is set to "aws_kms"[secrets_management.aws_kms]key_id = "kms_key_id" # The AWS key ID used by the KMS SDK for decrypting data.region = "kms_region" # The AWS region used by the KMS SDK for decrypting data.+# Required only if `secrets_manager` above is set to "gcp_kms"+[secrets_management.gcp_kms]+project_id = "gcp_project_id"+location_id = "gcp_kms_location_id" # e.g. "global", "us-east1"+key_ring_id = "gcp_kms_key_ring_id"+key_id = "gcp_kms_key_id"+[encryption_management]-encryption_manager = "aws_kms" # Encryption manager client to be used+encryption_manager = "aws_kms" # Encryption manager client to be used (no_encryption | aws_kms | gcp_kms)+# Required only if `encryption_manager` above is set to "aws_kms"[encryption_management.aws_kms]key_id = "kms_key_id" # The AWS key ID used by the KMS SDK for decrypting data.region = "kms_region" # The AWS region used by the KMS SDK for decrypting data.+# Required only if `encryption_manager` above is set to "gcp_kms"+[encryption_management.gcp_kms]+project_id = "gcp_project_id"+location_id = "gcp_kms_location_id"+key_ring_id = "gcp_kms_key_ring_id"+key_id = "gcp_kms_key_id"+[crm]crm_manager = "hubspot_proxy" # Crm manager client to be useddiff --git a/crates/drainer/Cargo.toml b/crates/drainer/Cargo.tomlindex be4e5481bc..7ae6619011 100644--- a/crates/drainer/Cargo.toml+++ b/crates/drainer/Cargo.toml@@ -9,7 +9,7 @@ license.workspace = true[features]default = ["redis-rs"]-release = ["vergen", "external_services/aws_kms"]+release = ["vergen", "external_services/aws_kms", "external_services/gcp_kms"]vergen = ["router_env/vergen"]v1 = ["diesel_models/v1", "external_services/v1", "hyperswitch_interfaces/v1", "common_utils/v1", "storage_impl/v1", "storage_impl/olap"]v2 = ["diesel_models/v2", "external_services/v2", "hyperswitch_interfaces/v2", "common_utils/v2", "storage_impl/v2"]diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.tomlindex e2f416c78d..23d8d8b5be 100644--- a/crates/external_services/Cargo.toml+++ b/crates/external_services/Cargo.toml@@ -11,6 +11,7 @@ license.workspace = trueaws_kms = ["dep:aws-config", "dep:aws-sdk-kms"]email = ["dep:aws-config"]aws_s3 = ["dep:aws-config", "dep:aws-sdk-s3"]+gcp_kms = ["dep:google-cloud-kms"]hashicorp-vault = ["dep:vaultrs"]superposition = ["dep:open-feature",@@ -62,6 +63,7 @@ aws-smithy-runtime-api = { version = "1.7", features = ["client"] }aws-smithy-types = "1.3.1"base64 = "0.22.1"dyn-clone = "1.0.19"+google-cloud-kms = { version = "0.6.0", optional = true }deja = { git = "https://github.com/juspay/deja", rev = "337181ebfd74b7e571a63a9cce515ff3c9309db7", optional = true, default-features = false }error-stack = "0.4.1"hex = "0.4.3"diff --git a/crates/external_services/src/gcp_kms.rs b/crates/external_services/src/gcp_kms.rsnew file mode 100644index 0000000000..512d56b42c--- /dev/null+++ b/crates/external_services/src/gcp_kms.rs@@ -0,0 +1,5 @@+//! Interactions with the GCP Cloud KMS SDK++pub mod core;++pub mod implementers;diff --git a/crates/external_services/src/gcp_kms/core.rs b/crates/external_services/src/gcp_kms/core.rsnew file mode 100644index 0000000000..7b9cf08506--- /dev/null+++ b/crates/external_services/src/gcp_kms/core.rs@@ -0,0 +1,271 @@+//! Interactions with the GCP Cloud KMS SDK++use std::time::Instant;++use base64::Engine;+use common_utils::errors::CustomResult;+use error_stack::ResultExt;+use google_cloud_kms::{+ client::{Client, ClientConfig},+ grpc::kms::v1::{DecryptRequest, EncryptRequest},+};+use router_env::logger;++use crate::{consts, metrics};++/// Configuration parameters required for constructing a [`GcpKmsClient`].+#[derive(Clone, Debug, Default, serde::Deserialize)]+#[serde(default)]+pub struct GcpKmsConfig {+ /// The GCP project ID that owns the KMS key ring.+ pub project_id: String,++ /// The location ID (e.g. `"global"`, `"us-east1"`) of the KMS key ring.+ pub location_id: String,++ /// The ID of the KMS key ring.+ pub key_ring_id: String,++ /// The ID of the KMS key used to encrypt or decrypt data.+ pub key_id: String,+}++impl GcpKmsConfig {+ /// Verifies that the [`GcpKmsConfig`] is valid.+ pub fn validate(&self) -> Result<(), &'static str> {+ use common_utils::{ext_traits::ConfigExt, fp_utils::when};++ when(self.project_id.is_default_or_empty(), || {+ Err("GCP KMS project ID must not be empty")+ })?;++ when(self.location_id.is_default_or_empty(), || {+ Err("GCP KMS location ID must not be empty")+ })?;++ when(self.key_ring_id.is_default_or_empty(), || {+ Err("GCP KMS key ring ID must not be empty")+ })?;++ when(self.key_id.is_default_or_empty(), || {+ Err("GCP KMS key ID must not be empty")+ })+ }+}++/// Client for GCP Cloud KMS operations.+#[derive(Clone, Debug)]+pub struct GcpKmsClient {+ inner_client: Client,+ key_name: String,+}++impl GcpKmsClient {+ /// Constructs a new GCP KMS client with ambient credentials, targeting the KMS key+ /// identified by the provided [`GcpKmsConfig`].+ pub async fn new(config: &GcpKmsConfig) -> CustomResult<Self, GcpKmsError> {+ let client_config = ClientConfig::default()+ .with_auth()+ .await+ .change_context(GcpKmsError::ClientCreationFailed)?;+ let inner_client = Client::new(client_config)+ .await+ .change_context(GcpKmsError::ClientCreationFailed)?;+ Ok(Self {+ inner_client,+ key_name: format!(+ "projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}",+ config.project_id, config.location_id, config.key_ring_id, config.key_id+ ),+ })+ }++ /// Decrypts base64-encoded ciphertext via GCP Cloud KMS.+ pub async fn decrypt(&self, data: impl AsRef<[u8]>) -> CustomResult<String, GcpKmsError> {+ let start = Instant::now();+ let ciphertext = consts::BASE64_ENGINE+ .decode(data)+ .change_context(GcpKmsError::Base64DecodingFailed)?;++ let request = DecryptRequest {+ name: self.key_name.clone(),+ ciphertext,+ additional_authenticated_data: Vec::new(),+ ciphertext_crc32c: None,+ additional_authenticated_data_crc32c: None,+ };++ let response = self+ .inner_client+ .decrypt(request, None)+ .await+ .inspect_err(|error| {+ logger::error!(gcp_kms_error=?error, "Failed to GCP KMS decrypt data");+ metrics::GCP_KMS_DECRYPTION_FAILURES.add(1, &[]);+ })+ .change_context(GcpKmsError::DecryptionFailed)?;++ let output = String::from_utf8(response.plaintext)+ .change_context(GcpKmsError::Utf8DecodingFailed)?;++ let time_taken = start.elapsed();+ metrics::GCP_KMS_DECRYPT_TIME.record(time_taken.as_secs_f64(), &[]);++ Ok(output)+ }++ /// Encrypts data via GCP Cloud KMS, returning base64-encoded ciphertext.+ pub async fn encrypt(&self, data: impl AsRef<[u8]>) -> CustomResult<String, GcpKmsError> {+ let start = Instant::now();++ let request = EncryptRequest {+ name: self.key_name.clone(),+ plaintext: data.as_ref().to_vec(),+ additional_authenticated_data: Vec::new(),+ plaintext_crc32c: None,+ additional_authenticated_data_crc32c: None,+ };++ let response = self+ .inner_client+ .encrypt(request, None)+ .await+ .inspect_err(|error| {+ logger::error!(gcp_kms_error=?error, "Failed to GCP KMS encrypt data");+ metrics::GCP_KMS_ENCRYPTION_FAILURES.add(1, &[]);+ })+ .change_context(GcpKmsError::EncryptionFailed)?;++ let output = consts::BASE64_ENGINE.encode(response.ciphertext);++ let time_taken = start.elapsed();+ metrics::GCP_KMS_ENCRYPT_TIME.record(time_taken.as_secs_f64(), &[]);++ Ok(output)+ }+}++/// Errors that could occur during GCP KMS operations.+#[derive(Debug, thiserror::Error)]+pub enum GcpKmsError {+ /// An error occurred when base64 decoding the input data.+ #[error("Failed to base64 decode input data")]+ Base64DecodingFailed,++ /// An error occurred when GCP KMS decrypting the input data.+ #[error("Failed to GCP KMS decrypt input data")]+ DecryptionFailed,++ /// An error occurred when GCP KMS encrypting the input data.+ #[error("Failed to GCP KMS encrypt input data")]+ EncryptionFailed,++ /// An error occurred UTF-8 decoding the GCP KMS decrypted output.+ #[error("Failed UTF-8 decode of GCP KMS decrypted output")]+ Utf8DecodingFailed,++ /// An error occurred when creating the GCP KMS client.+ #[error("Failed to create GCP KMS client")]+ ClientCreationFailed,+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn validate_fails_when_project_id_is_empty() {+ let config = GcpKmsConfig {+ project_id: String::new(),+ location_id: "global".to_string(),+ key_ring_id: "key-ring".to_string(),+ key_id: "key".to_string(),+ };+ assert!(config.validate().is_err());+ }++ #[test]+ fn validate_fails_when_location_id_is_empty() {+ let config = GcpKmsConfig {+ project_id: "project".to_string(),+ location_id: String::new(),+ key_ring_id: "key-ring".to_string(),+ key_id: "key".to_string(),+ };+ assert!(config.validate().is_err());+ }++ #[test]+ fn validate_fails_when_key_ring_id_is_empty() {+ let config = GcpKmsConfig {+ project_id: "project".to_string(),+ location_id: "global".to_string(),+ key_ring_id: String::new(),+ key_id: "key".to_string(),+ };+ assert!(config.validate().is_err());+ }++ #[test]+ fn validate_fails_when_key_id_is_empty() {+ let config = GcpKmsConfig {+ project_id: "project".to_string(),+ location_id: "global".to_string(),+ key_ring_id: "key-ring".to_string(),+ key_id: String::new(),+ };+ assert!(config.validate().is_err());+ }++ #[test]+ fn validate_succeeds_when_all_fields_are_populated() {+ let config = GcpKmsConfig {+ project_id: "project".to_string(),+ location_id: "global".to_string(),+ key_ring_id: "key-ring".to_string(),+ key_id: "key".to_string(),+ };+ assert!(config.validate().is_ok());+ }++ #[tokio::test]+ async fn check_gcp_kms_encrypt() {+ let config = GcpKmsConfig {+ project_id: "YOUR GCP PROJECT ID".to_string(),+ location_id: "YOUR GCP KMS LOCATION ID".to_string(),+ key_ring_id: "YOUR GCP KMS KEY RING ID".to_string(),+ key_id: "YOUR GCP KMS KEY ID".to_string(),+ };++ let data = "hello".to_string();+ let gcp_kms_encrypted_fingerprint = GcpKmsClient::new(&config)+ .await+ .expect("gcp kms client creation failed")+ .encrypt(data.as_bytes())+ .await+ .expect("gcp kms encryption failed");++ println!("{gcp_kms_encrypted_fingerprint}");+ }++ #[tokio::test]+ async fn check_gcp_kms_decrypt() {+ let config = GcpKmsConfig {+ project_id: "YOUR GCP PROJECT ID".to_string(),+ location_id: "YOUR GCP KMS LOCATION ID".to_string(),+ key_ring_id: "YOUR GCP KMS KEY RING ID".to_string(),+ key_id: "YOUR GCP KMS KEY ID".to_string(),+ };++ // Should decrypt to hello+ let data = "GCP KMS ENCRYPTED CIPHER".to_string();+ let gcp_kms_decrypted_fingerprint = GcpKmsClient::new(&config)+ .await+ .expect("gcp kms client creation failed")+ .decrypt(data.as_bytes())+ .await+ .expect("gcp kms decryption failed");++ println!("{gcp_kms_decrypted_fingerprint}");+ }+}diff --git a/crates/external_services/src/gcp_kms/implementers.rs b/crates/external_services/src/gcp_kms/implementers.rsnew file mode 100644index 0000000000..4823ea0bb4--- /dev/null+++ b/crates/external_services/src/gcp_kms/implementers.rs@@ -0,0 +1,41 @@+//! Trait implementations for gcp kms client++use common_utils::errors::CustomResult;+use error_stack::ResultExt;+use hyperswitch_interfaces::{+ encryption_interface::{EncryptionError, EncryptionManagementInterface},+ secrets_interface::{SecretManagementInterface, SecretsManagementError},+};+use hyperswitch_masking::{PeekInterface, Secret};++use crate::gcp_kms::core::GcpKmsClient;++#[async_trait::async_trait]+impl EncryptionManagementInterface for GcpKmsClient {+ async fn encrypt(&self, input: &[u8]) -> CustomResult<Vec<u8>, EncryptionError> {+ self.encrypt(input)+ .await+ .change_context(EncryptionError::EncryptionFailed)+ .map(|val| val.into_bytes())+ }++ async fn decrypt(&self, input: &[u8]) -> CustomResult<Vec<u8>, EncryptionError> {+ self.decrypt(input)+ .await+ .change_context(EncryptionError::DecryptionFailed)+ .map(|val| val.into_bytes())+ }+}++#[async_trait::async_trait]+impl SecretManagementInterface for GcpKmsClient {+ async fn get_secret(+ &self,+ input: Secret<String>,+ ) -> CustomResult<Secret<String>, SecretsManagementError> {+ self.decrypt(input.peek())+ .await+ .change_context(SecretsManagementError::FetchSecretFailed)+ .map(Into::into)+ }+}diff --git a/crates/external_services/src/lib.rs b/crates/external_services/src/lib.rsindex 83c39fb863..b3d873d0c2 100644--- a/crates/external_services/src/lib.rs+++ b/crates/external_services/src/lib.rs@@ -9,6 +9,8 @@ pub mod crm;#[cfg(feature = "email")]pub mod email;pub mod file_storage;+#[cfg(feature = "gcp_kms")]+pub mod gcp_kms;/// Building grpc clients to communicate with the serverpub mod grpc_client;#[cfg(feature = "hashicorp-vault")]@@ -66,7 +68,7 @@ pub mod consts {pub(crate) const DEFAULT_UCS_REQUEST_TIMEOUT_SECS: u64 = 35;/// General purpose base64 engine- #[cfg(feature = "aws_kms")]+ #[cfg(any(feature = "aws_kms", feature = "gcp_kms"))]pub(crate) const BASE64_ENGINE: base64::engine::GeneralPurpose =base64::engine::general_purpose::STANDARD;@@ -114,7 +116,7 @@ pub mod consts {}/// Metrics for interactions with external systems.-#[cfg(feature = "aws_kms")]+#[cfg(any(feature = "aws_kms", feature = "gcp_kms"))]pub mod metrics {use router_env::{counter_metric, global_meter, histogram_metric_f64};@@ -129,6 +131,16 @@ pub mod metrics {histogram_metric_f64!(AWS_KMS_DECRYPT_TIME, GLOBAL_METER); // Histogram for AWS KMS decryption time (in sec)#[cfg(feature = "aws_kms")]histogram_metric_f64!(AWS_KMS_ENCRYPT_TIME, GLOBAL_METER); // Histogram for AWS KMS encryption time (in sec)++ #[cfg(feature = "gcp_kms")]+ counter_metric!(GCP_KMS_DECRYPTION_FAILURES, GLOBAL_METER); // No. of GCP KMS Decryption failures+ #[cfg(feature = "gcp_kms")]+ counter_metric!(GCP_KMS_ENCRYPTION_FAILURES, GLOBAL_METER); // No. of GCP KMS Encryption failures++ #[cfg(feature = "gcp_kms")]+ histogram_metric_f64!(GCP_KMS_DECRYPT_TIME, GLOBAL_METER); // Histogram for GCP KMS decryption time (in sec)+ #[cfg(feature = "gcp_kms")]+ histogram_metric_f64!(GCP_KMS_ENCRYPT_TIME, GLOBAL_METER); // Histogram for GCP KMS encryption time (in sec)}/// Metrics for config-related operationsdiff --git a/crates/external_services/src/managers/encryption_management.rs b/crates/external_services/src/managers/encryption_management.rsindex e89c5947f9..b76bcc58a5 100644--- a/crates/external_services/src/managers/encryption_management.rs+++ b/crates/external_services/src/managers/encryption_management.rs@@ -3,12 +3,16 @@use std::sync::Arc;use common_utils::errors::CustomResult;+#[cfg(feature = "gcp_kms")]+use error_stack::ResultExt;use hyperswitch_interfaces::encryption_interface::{EncryptionError, EncryptionManagementInterface,};#[cfg(feature = "aws_kms")]use crate::aws_kms;+#[cfg(feature = "gcp_kms")]+use crate::gcp_kms;use crate::no_encryption::core::NoEncryption;/// Enum representing configuration options for encryption management.@@ -23,6 +27,13 @@ pub enum EncryptionManagementConfig {aws_kms: aws_kms::core::AwsKmsConfig,},+ /// GCP Cloud KMS configuration+ #[cfg(feature = "gcp_kms")]+ GcpKms {+ /// GCP KMS config+ gcp_kms: gcp_kms::core::GcpKmsConfig,+ },+/// Variant representing no encryption#[default]NoEncryption,@@ -43,6 +54,9 @@ impl EncryptionManagementConfig {})}+ #[cfg(feature = "gcp_kms")]+ Self::GcpKms { gcp_kms } => gcp_kms.validate(),+Self::NoEncryption => Ok(()),}}@@ -55,6 +69,14 @@ impl EncryptionManagementConfig {#[cfg(feature = "aws_kms")]Self::AwsKms { aws_kms } => Arc::new(aws_kms::core::AwsKmsClient::new(aws_kms).await),+ #[cfg(feature = "gcp_kms")]+ Self::GcpKms { gcp_kms } => Arc::new(+ gcp_kms::core::GcpKmsClient::new(gcp_kms)+ .await+ .change_context(EncryptionError::EncryptionFailed)+ .attach_printable("Failed to create GCP KMS client")?,+ ),+Self::NoEncryption => Arc::new(NoEncryption),})}diff --git a/crates/external_services/src/managers/secrets_management.rs b/crates/external_services/src/managers/secrets_management.rsindex 7b27e74bf3..3af62a5f5f 100644--- a/crates/external_services/src/managers/secrets_management.rs+++ b/crates/external_services/src/managers/secrets_management.rs@@ -1,7 +1,7 @@//! Secrets management util moduleuse common_utils::errors::CustomResult;-#[cfg(feature = "hashicorp-vault")]+#[cfg(any(feature = "hashicorp-vault", feature = "gcp_kms"))]use error_stack::ResultExt;use hyperswitch_interfaces::secrets_interface::{SecretManagementInterface, SecretsManagementError,@@ -9,6 +9,8 @@ use hyperswitch_interfaces::secrets_interface::{#[cfg(feature = "aws_kms")]use crate::aws_kms;+#[cfg(feature = "gcp_kms")]+use crate::gcp_kms;#[cfg(feature = "hashicorp-vault")]use crate::hashicorp_vault;use crate::no_encryption::core::NoEncryption;@@ -25,6 +27,13 @@ pub enum SecretsManagementConfig {aws_kms: aws_kms::core::AwsKmsConfig,},+ /// GCP Cloud KMS configuration+ #[cfg(feature = "gcp_kms")]+ GcpKms {+ /// GCP KMS config+ gcp_kms: gcp_kms::core::GcpKmsConfig,+ },+/// HashiCorp-Vault configuration#[cfg(feature = "hashicorp-vault")]HashiCorpVault {@@ -43,6 +52,8 @@ impl SecretsManagementConfig {match self {#[cfg(feature = "aws_kms")]Self::AwsKms { aws_kms } => aws_kms.validate(),+ #[cfg(feature = "gcp_kms")]+ Self::GcpKms { gcp_kms } => gcp_kms.validate(),#[cfg(feature = "hashicorp-vault")]Self::HashiCorpVault { hc_vault } => hc_vault.validate(),Self::NoEncryption => Ok(()),@@ -58,6 +69,11 @@ impl SecretsManagementConfig {Self::AwsKms { aws_kms } => {Ok(Box::new(aws_kms::core::AwsKmsClient::new(aws_kms).await))}+ #[cfg(feature = "gcp_kms")]+ Self::GcpKms { gcp_kms } => gcp_kms::core::GcpKmsClient::new(gcp_kms)+ .await+ .change_context(SecretsManagementError::ClientCreationFailed)+ .map(|inner| -> Box<dyn SecretManagementInterface> { Box::new(inner) }),#[cfg(feature = "hashicorp-vault")]Self::HashiCorpVault { hc_vault } => {hashicorp_vault::core::HashiCorpVault::new(hc_vault)diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex ed61bc1657..ed87e82972 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -33,7 +33,7 @@ olap = ["api_models/olap","dep:analytics",]-tls = ["actix-web/rustls-0_22"]+tls = ["actix-web/rustls-0_23"]email = ["external_services/email", "scheduler/email", "olap"]# keymanager_create, keymanager_mtls, encryption_service should not be removed or added to default feature. Once this features were enabled it can't be disabled as these are breaking changes.keymanager_create = []@@ -58,6 +58,7 @@ frm = ["hyperswitch_interfaces/frm",]stripe = []+gcp_kms = ["external_services/gcp_kms"]release = ["stripe","email",@@ -65,6 +66,7 @@ release = ["kv_store","vergen","external_services/aws_kms",+ "gcp_kms","external_services/aws_s3","keymanager_mtls","keymanager_create",@@ -243,7 +245,11 @@ rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaffunified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.08.24.0", package = "rust-grpc-client" }unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", tag = "2026.08.24.0", package = "ucs_cards" }rustc-hash = "1.1.0"-rustls = "0.22"+rustls = { version = "0.23", default-features = false, features = [+ "aws-lc-rs",+ "std",+ "tls12",+] }rustls-pemfile = "2"serde = { version = "1.0.219", features = ["derive"] }serde_json = "1.0.140"diff --git a/crates/router/src/bin/router.rs b/crates/router/src/bin/router.rsindex 7d27d74f7c..19a5300e40 100644--- a/crates/router/src/bin/router.rs+++ b/crates/router/src/bin/router.rs@@ -8,6 +8,15 @@ use router::{#[tokio::main]async fn main() -> ApplicationResult<()> {+ // GCP Cloud KMS pulls in tonic, which requests the `ring` rustls backend — the only+ // thing here that disagrees with the `aws-lc-rs` backend every AWS SDK crate already+ // uses. rustls won't guess between two backends, so pick one explicitly.+ #[cfg(feature = "gcp_kms")]+ #[allow(clippy::expect_used)]+ rustls::crypto::aws_lc_rs::default_provider()+ .install_default()+ .expect("Failed to install default rustls CryptoProvider");+// get commandline config before initializing configlet cmd_line = <CmdLineConf as clap::Parser>::parse();diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rsindex 34c57e142e..11e8cc7860 100644--- a/crates/router/src/lib.rs+++ b/crates/router/src/lib.rs@@ -461,7 +461,7 @@ pub async fn start_server(})?;server_builder- .bind_rustls_0_22(+ .bind_rustls_0_23((tls_conf.host.unwrap_or(server.host).as_str(), tls_conf.port),config,)?