mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 11:56:38 +00:00
fix(kms): restore configure and decrypt compatibility
This commit is contained in:
+33
-12
@@ -110,6 +110,7 @@ pub struct ConfigureVaultTransitKmsRequest {
|
|||||||
#[serde(tag = "backend_type")]
|
#[serde(tag = "backend_type")]
|
||||||
pub enum ConfigureKmsRequest {
|
pub enum ConfigureKmsRequest {
|
||||||
/// Configure with Local backend
|
/// Configure with Local backend
|
||||||
|
#[serde(alias = "local", alias = "Local")]
|
||||||
Local(ConfigureLocalKmsRequest),
|
Local(ConfigureLocalKmsRequest),
|
||||||
/// Configure with Vault KV v2 + Transit backend
|
/// Configure with Vault KV v2 + Transit backend
|
||||||
#[serde(
|
#[serde(
|
||||||
@@ -121,6 +122,11 @@ pub enum ConfigureKmsRequest {
|
|||||||
)]
|
)]
|
||||||
VaultKv2(ConfigureVaultKmsRequest),
|
VaultKv2(ConfigureVaultKmsRequest),
|
||||||
/// Configure with Vault Transit backend
|
/// Configure with Vault Transit backend
|
||||||
|
#[serde(
|
||||||
|
rename = "VaultTransit",
|
||||||
|
alias = "vault-transit",
|
||||||
|
alias = "vault_transit"
|
||||||
|
)]
|
||||||
VaultTransit(ConfigureVaultTransitKmsRequest),
|
VaultTransit(ConfigureVaultTransitKmsRequest),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,24 +459,39 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_vault_transit_configure_request() {
|
fn test_deserialize_vault_transit_configure_request() {
|
||||||
|
let cases = ["VaultTransit", "vault-transit", "vault_transit"];
|
||||||
|
for raw_backend in cases {
|
||||||
|
let raw = serde_json::json!({
|
||||||
|
"backend_type": raw_backend,
|
||||||
|
"address": "http://127.0.0.1:8200",
|
||||||
|
"auth_method": {
|
||||||
|
"Token": {
|
||||||
|
"token": "dev-root-token"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mount_path": "transit",
|
||||||
|
"default_key_id": "rustfs-master-key"
|
||||||
|
});
|
||||||
|
let request: ConfigureKmsRequest =
|
||||||
|
serde_json::from_value(raw).expect("vault-transit request should deserialize");
|
||||||
|
let config = request.to_kms_config();
|
||||||
|
assert_eq!(config.backend, KmsBackend::VaultTransit);
|
||||||
|
let vault = config.vault_transit_config().expect("vault-transit config should be present");
|
||||||
|
assert_eq!(vault.mount_path, "transit");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_deserialize_local_configure_request() {
|
||||||
let raw = serde_json::json!({
|
let raw = serde_json::json!({
|
||||||
"backend_type": "VaultTransit",
|
"backend_type": "local",
|
||||||
"address": "http://127.0.0.1:8200",
|
"key_dir": "./target/kms-key-dir"
|
||||||
"auth_method": {
|
|
||||||
"Token": {
|
|
||||||
"token": "dev-root-token"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mount_path": "transit",
|
|
||||||
"default_key_id": "rustfs-master-key"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let request: ConfigureKmsRequest = serde_json::from_value(raw).expect("vault-transit request should deserialize");
|
let request: ConfigureKmsRequest = serde_json::from_value(raw).expect("vault-transit request should deserialize");
|
||||||
let config = request.to_kms_config();
|
let config = request.to_kms_config();
|
||||||
|
|
||||||
assert_eq!(config.backend, KmsBackend::VaultTransit);
|
assert_eq!(config.backend, KmsBackend::Local);
|
||||||
let vault = config.vault_transit_config().expect("vault-transit config should be present");
|
|
||||||
assert_eq!(vault.mount_path, "transit");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -535,7 +535,7 @@ impl KmsBackend for VaultTransitKmsBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn decrypt(&self, request: DecryptRequest) -> Result<DecryptResponse> {
|
async fn decrypt(&self, request: DecryptRequest) -> Result<DecryptResponse> {
|
||||||
let envelope = DataKeyEnvelope::deserialize(&request.ciphertext_blob)?;
|
let envelope: DataKeyEnvelope = serde_json::from_slice(&request.ciphertext)?;
|
||||||
let plaintext = self.client.decrypt(&request, None).await?;
|
let plaintext = self.client.decrypt(&request, None).await?;
|
||||||
Ok(DecryptResponse {
|
Ok(DecryptResponse {
|
||||||
plaintext,
|
plaintext,
|
||||||
|
|||||||
Reference in New Issue
Block a user