Skip to content

Commit 33fa800

Browse files
authored
Initial Key Vault certificates crate (#2432)
* Initial Key Vault certificates crate Resolves #2365 * Update READMEs for PR feedback * Fix build breaks * Fix spelling Missed one, it seems.
1 parent 15b7d27 commit 33fa800

File tree

36 files changed

+3396
-52
lines changed

36 files changed

+3396
-52
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"sdk/cosmos/azure_data_cosmos",
1212
"sdk/identity/azure_identity",
1313
"sdk/eventhubs/azure_messaging_eventhubs",
14+
"sdk/keyvault/azure_security_keyvault_certificates",
1415
"sdk/keyvault/azure_security_keyvault_keys",
1516
"sdk/keyvault/azure_security_keyvault_secrets",
1617
"sdk/template/azure_template_core",

sdk/core/azure_core_test/src/proxy/sanitizers.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ use std::{
1313
iter::{once, Once},
1414
};
1515

16+
/// Sanitizes `$..id`.
17+
pub const SANITIZE_BODY_ID: &str = "AZSDK3430";
18+
19+
/// Sanitizes `$..etag`.
20+
pub const SANITIZE_BODY_ETAG: &str = "AZSDK3490";
21+
22+
/// Sanitizes `$..name`.
23+
pub const SANITIZE_BODY_NAME: &str = "AZSDK3493";
24+
1625
/// Default sanitizers to remove.
17-
// See <https://github.com/Azure/azure-sdk-for-net/blob/eedbc408d565fbc5cbca96222807c737ae53605e/sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs#L123>.
26+
// See <https://github.com/Azure/azure-sdk-tools/blob/528e97f7de3a97375beaf7b85e1334df013c8290/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDictionary.cs>.
1827
pub const DEFAULT_SANITIZERS_TO_REMOVE: &[&str; 2] = &[
19-
"AZSDK3430", // $..id
20-
"AZSDK3490", // $..etag
28+
SANITIZE_BODY_ID, // $..id
29+
SANITIZE_BODY_ETAG, // $..etag
2130
];
2231

2332
/// Default sanitization replacement value, "Sanitized";

sdk/keyvault/.dict.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ ciphertext
44
ckmaeskeywrap
55
ckmaeskeywrappad
66
ckmrsaaeskeywrap
7+
deletedcertificates
8+
deleteissuers
79
deletedkeys
810
deletedsecrets
11+
diffie
912
echsm
13+
ekus
1014
fips
15+
getissuers
16+
innererror
1117
keyout
18+
managecontacts
19+
manageissuers
1220
newkey
1321
oaep
1422
purgeable
@@ -21,5 +29,7 @@ rsassa
2129
rsnull
2230
secg
2331
secp
32+
setissuers
2433
unwrapkey
34+
upns
2535
wrapkey

sdk/keyvault/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
44
"TagPrefix": "rust/keyvault",
5-
"Tag": "rust/keyvault_5166c190c1"
5+
"Tag": "rust/keyvault_4acaa30551"
66
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Release History
2+
3+
## 0.1.0 (Unreleased)
4+
5+
### Features Added
6+
7+
- Initial public release.
8+
- Built on Azure Key Vault service version 7.6-preview.2.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "azure_security_keyvault_certificates"
3+
version = "0.1.0"
4+
description = "Rust wrappers around Microsoft Azure REST APIs - Azure Key Vault Certificates"
5+
readme = "README.md"
6+
authors.workspace = true
7+
edition.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
homepage = "https://github.com/azure/azure-sdk-for-rust"
12+
documentation = "https://docs.rs/azure_security_keyvault_certificates"
13+
keywords = ["sdk", "azure", "keyvault", "security", "certificates"]
14+
categories = ["api-bindings"]
15+
16+
[dependencies]
17+
azure_core = { workspace = true }
18+
futures = { workspace = true }
19+
serde = { workspace = true, features = ["derive"] }
20+
serde_json = { workspace = true }
21+
time = { workspace = true }
22+
tokio = { workspace = true }
23+
typespec_client_core = { workspace = true, features = ["derive"] }
24+
25+
[dev-dependencies]
26+
azure_core_test = { workspace = true, features = [
27+
"tracing",
28+
] }
29+
azure_identity.workspace = true
30+
azure_security_keyvault_keys = { path = "../azure_security_keyvault_keys" }
31+
azure_security_keyvault_test = { path = "../azure_security_keyvault_test" }
32+
rand.workspace = true
33+
tokio.workspace = true
34+
35+
[build-dependencies]
36+
rustc_version.workspace = true
37+
38+
[lints]
39+
workspace = true
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Azure Key Vault certificates client library for Rust
2+
3+
Azure Key Vault is a cloud service that provides secure storage of certificates for encrypting your data. Multiple certificates, and multiple versions of the same certificate, can be kept in the Azure Key Vault.
4+
5+
The Azure Key Vault certificates client library allows you to securely store and control the access to certificates. This library offers operations to create, import, retrieve the public key, update, delete, purge, backup, restore, and list the certificates and its versions.
6+
7+
[Source code] | [Package (crates.io)] | [API reference documentation] | [Product documentation]
8+
9+
## Getting started
10+
11+
### Install the package
12+
13+
Install the Azure Key Vault certificates client library for Rust with [Cargo]:
14+
15+
```sh
16+
cargo add azure_security_keyvault_certificates
17+
```
18+
19+
### Prerequisites
20+
21+
* An [Azure subscription].
22+
* An existing Azure Key Vault. If you need to create an Azure Key Vault, you can use the Azure Portal or [Azure CLI].
23+
* Authorization to an existing Azure Key Vault using either [RBAC] (recommended) or [access control].
24+
25+
If you use the Azure CLI, replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names:
26+
27+
```azurecli
28+
az keyvault create --resource-group <your-resource-group-name> --name <your-key-vault-name>
29+
```
30+
31+
### Install dependencies
32+
33+
Add the following crates to your project:
34+
35+
```sh
36+
cargo add azure_identity tokio
37+
```
38+
39+
### Authenticate the client
40+
41+
In order to interact with the Azure Key Vault service, you'll need to create an instance of the `CertificateClient`. You need a **vault url**, which you may see as "DNS Name" in the portal, and credentials to instantiate a client object.
42+
43+
The example shown below uses a `DefaultAzureCredential`, which is appropriate for local development environments. We recommend using a managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity] documentation.
44+
45+
The `DefaultAzureCredential` will automatically pick up on an Azure CLI authentication. Ensure you are logged in with the Azure CLI:
46+
47+
```azurecli
48+
az login
49+
```
50+
51+
Instantiate a `DefaultAzureCredential` to pass to the client. The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.
52+
53+
## Key concepts
54+
55+
### CertificateBundle
56+
57+
A Azure Key Vault certificate public key. The private key is never included when retrieving a `CertificateBundle`.
58+
59+
### CertificateClient
60+
61+
The `CertificateClient` provides asynchronous operations for working with Key Vault certificates.
62+
63+
### Thread safety
64+
65+
We guarantee that all client instance methods are thread-safe and independent of each other. This ensures that the recommendation of reusing client instances is always safe, even across threads.
66+
67+
## Examples
68+
69+
> TODO
70+
71+
## Troubleshooting
72+
73+
### General
74+
75+
When you interact with the Azure Key Vault certificates client library using the Rust SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API] requests.
76+
77+
For example, if you try to retrieve a key that doesn't exist in your Azure Key Vault, a `404` error is returned, indicating `Not Found`.
78+
79+
```rust no_run
80+
use azure_identity::DefaultAzureCredential;
81+
use azure_security_keyvault_certificates::CertificateClient;
82+
83+
#[tokio::main]
84+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
85+
let credential = DefaultAzureCredential::new()?;
86+
let client = CertificateClient::new(
87+
"https://<my-vault>.vault.azure.net/",
88+
credential.clone(),
89+
None,
90+
)?;
91+
92+
match client.get_certificate("certificate-name".into(), "".into(), None).await {
93+
Ok(response) => println!("Certificate: {:#?}", response.into_body().await?.x509_thumbprint),
94+
Err(err) => println!("Error: {:#?}", err.into_inner()?),
95+
}
96+
97+
Ok(())
98+
}
99+
```
100+
101+
You will notice that additional information is logged, like the Client Request ID of the operation.
102+
103+
```text
104+
Error: HttpError {
105+
status: NotFound,
106+
details: ErrorDetails {
107+
code: Some(
108+
"CertificateNotFound",
109+
),
110+
message: Some(
111+
"A certificate with (name/id) certificate-name was not found in this key vault. If you recently deleted this certificate you may be able to recover it using the correct recovery command. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125182",
112+
),
113+
},
114+
..
115+
}
116+
```
117+
118+
## Contributing
119+
120+
See the [CONTRIBUTING.md] for details on building, testing, and contributing to these libraries.
121+
122+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://opensource.microsoft.com/cla/>.
123+
124+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
125+
126+
This project has adopted the [Microsoft Open Source Code of Conduct]. For more information see the [Code of Conduct FAQ] or contact <[email protected]> with any additional questions or comments.
127+
128+
<!-- LINKS -->
129+
[API reference documentation]: https://docs.rs/azure_security_keyvault_certificates/latest/azure_security_keyvault_certificates
130+
[Azure CLI]: https://learn.microsoft.com/cli/azure
131+
[Azure subscription]: https://azure.microsoft.com/free/
132+
[Azure Identity]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/identity/azure_identity
133+
[Microsoft Open Source Code of Conduct]: https://opensource.microsoft.com/codeofconduct/
134+
[Product documentation]: https://learn.microsoft.com/azure/key-vault/
135+
[REST API]: https://learn.microsoft.com/rest/api/keyvault/
136+
[Cargo]: https://crates.io/
137+
[Package (crates.io)]: https://crates.io/crates/azure_security_keyvault_certificates
138+
[Source code]: https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/keyvault/azure_security_keyvault_certificates/src
139+
[CONTRIBUTING.md]: https://github.com/Azure/azure-sdk-for-rust/blob/main/CONTRIBUTING.md
140+
[Code of Conduct FAQ]: https://opensource.microsoft.com/codeofconduct/faq/
141+
[access control]: https://learn.microsoft.com/azure/key-vault/general/assign-access-policy
142+
[RBAC]: https://learn.microsoft.com/azure/key-vault/general/rbac-guide

0 commit comments

Comments
 (0)