-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KBS: add aliyun KMS backend support for KBS storage
Signed-off-by: Xynnn007 <[email protected]>
- Loading branch information
Showing
8 changed files
with
444 additions
and
47 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2024 by Alibaba. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::{Repository, ResourceDesc}; | ||
use anyhow::{Context, Result}; | ||
use kms::{plugins::aliyun::AliyunKmsClient, Annotations, Getter}; | ||
use log::info; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct AliyunKmsBackendConfig { | ||
client_key: String, | ||
kms_instance_id: String, | ||
password: String, | ||
cert_pem: String, | ||
} | ||
|
||
pub struct AliyunKmsBackend { | ||
client: AliyunKmsClient, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Repository for AliyunKmsBackend { | ||
async fn read_secret_resource(&mut self, resource_desc: ResourceDesc) -> Result<Vec<u8>> { | ||
info!( | ||
"Use aliyun KMS backend. Ignore {}/{}", | ||
resource_desc.repository_name, resource_desc.resource_type | ||
); | ||
let name = resource_desc.resource_tag; | ||
let resource_byte = self | ||
.client | ||
.get_secret(&name, &Annotations::default()) | ||
.await | ||
.context("failed to get resource from aliyun KMS")?; | ||
Ok(resource_byte) | ||
} | ||
|
||
async fn write_secret_resource( | ||
&mut self, | ||
_resource_desc: ResourceDesc, | ||
_data: &[u8], | ||
) -> Result<()> { | ||
todo!("Does not support!") | ||
} | ||
} | ||
|
||
impl AliyunKmsBackend { | ||
pub fn new(repo_desc: &AliyunKmsBackendConfig) -> Result<Self> { | ||
let client = AliyunKmsClient::new( | ||
&repo_desc.client_key, | ||
&repo_desc.kms_instance_id, | ||
&repo_desc.password, | ||
&repo_desc.cert_pem, | ||
) | ||
.context("create aliyun KMS backend")?; | ||
Ok(Self { client }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters