microsoft / microsoft/aspire

AddKey support for Azure Key Vault integration

Open
#13,717 1 comment 0 reactions 0 assignees View on GitHub
area-integrations azure azure-keyvault
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I would like to be able to add a Key resource to an Azure Key Vault resource, similar to the existing AddSecret method. This would be so that I could pass a reference to the Key URI to other resources like an API. An example use case is for a system-level signing key. We currently deploy this key via Bicep outside of Aspire, so this should be able to be translated into deployment support, even though I don't currently use that in Aspire.

Since I don't use deploy mode, my primary goal of having this issue is so that it would be available in the [Azure Key Vault Emulator](https://github.com/james-gould/azure-keyvault-emulator), which would have to support this functionality as well once this sub-resource is in place.

Even though my use case is for the local emulator, I'd imagine that many people could benefit from deploy mode support for deploying keys (and the configuration references to them) this way as well.

### Describe the solution you'd like

## Example proposed usage (with emulator)

```c#
var keyVault = builder
.AddAzureKeyVault("keyvault")
.RunAsEmulator(new KeyVaultEmulatorOptions { Persist = true });

var signingKey = keyVault.AddKey("mysigningkey",
keyType: KeyVaultKeyType.Rsa,
keySize: 4096, // or curve for EC
);

// Alternative API 1: strongly-typed key options to remove incompatible combinations
var signingKey = keyVault.AddKey("mysigningkey",
new KeyVaultRsaKeyOptions(keySize: 4096)
// or: new KeyVaultEllipticCurveKeyOptions(curve: KeyVaultEllipticCurve.P256)
);

// Alternative API 2: per-key-type methods for brevity
var signingKey = keyVault.AddRsaKey("mysigningkey", keySize: 4096);
// or: keyVault.AddEllipticCurveKey("mysigningkey", curve: KeyVaultEllipticCurve.P256);

// ... usage in some resource:
.WithReference(signingKey)

// ... or:
.WithEnvironment("KeyVault__SigningKeyUri", signingKey) // resolves at runtime to the key URI
```

## Alternatives considered

See alternative API options above.

I also considered whether this was an emulator-only concern and thus whether this feature request should be filed in that project instead. I realized that this might have value to publish-mode users, in addition to being available for the emulator to use, so it seemed to make the most sense to have this support be on the Key Vault integration API first.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.