theodore-brucker/zig-azure-keyvault-client
Azure KeyVault client written in Zig
A lightweight, secure Azure Key Vault client written in Zig. This project provides a simple interface for interacting with Azure Key Vault, implementing secure token handling and key vault operations. The demo here uses an empty sandbox Azure tenant spun up for the testing of this tool.
git clone https://github.com/yourusername/zig-azure-keyvault.git
cd zig-azure-keyvault
zig build
Create a configuration with your Azure credentials:
const client_id = "your-client-id";
const client_secret = "your-client-secret";
const tenant_id = "your-tenant-id";
const vault_name = "your-vault-name";
const api_version = "7.3";
const std = @import("std");
const azure_auth = @import("azure_auth.zig");
const keyvault = @import("azure_keyvault.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();
// Get OAuth token
var token = try azure_auth.getOAuthToken(allocator, client_id, client_secret, tenant_id);
defer token.deinit();
// List secrets
const secret_list = try keyvault.list_secrets(allocator, token.secure_token, vault_name, api_version);
defer secret_list.deinit(allocator);
// Get a specific secret
const secret = try keyvault.get_secret(allocator, token.secure_token, vault_name, "my-secret", api_version);
defer secret.deinit(allocator);
}
azure_auth.getOAuthToken
Securely obtains an OAuth token from Azure Active Directory.
keyvault.list_secrets
Lists all secrets in the specified vault.
keyvault.get_secret
Retrieves a specific secret by name.
keyvault.set_secret
Sets a secret value in the vault.
The library uses Zig's error union type system to handle various error conditions:
pub const KeyVaultError = error{
RequestFailed,
InvalidResponse,
SecretNotFound,
AuthenticationFailed,
InvalidRequest,
};
Error handling example:
const secret = keyvault.get_secret(allocator, token.secure_token, vault_name, "missing-secret", api_version) catch |err| {
switch (err) {
KeyVaultError.SecretNotFound => {
// Handle missing secret
},
KeyVaultError.AuthenticationFailed => {
// Handle authentication failure
},
else => {
// Handle other errors
},
}
};
Token Security
Memory Safety
Best Practices
Known Limitations
A React-based demo UI is included in the ui
directory. This is for demonstration purposes only and should not be used in production without proper security review and implementation.
MIT License - See LICENSE file for details.
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This is a proof of concept implementation. While care has been taken to implement security best practices, it has not undergone a security audit and should be reviewed thoroughly before use in production environments.