-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[SQL] Support versionless key in server key, server encryption protector and database create/update #28666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[SQL] Support versionless key in server key, server encryption protector and database create/update #28666
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,7 +30,9 @@ class TdeKeyHelper | |||||||||||||
/// <summary> | ||||||||||||||
/// Creates the SQL Server Key Name from an Azure Key Vault KeyId | ||||||||||||||
/// Throws an exception if the provided KeyId is malformed. | ||||||||||||||
/// An example of a well formed Azure Key Vault KeyId is: https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901 | ||||||||||||||
/// Examples of well formed Azure Key Vault KeyIds are: | ||||||||||||||
/// https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901 (versioned) | ||||||||||||||
/// https://YourVaultName.vault.azure.net/keys/YourKeyName (versionless) | ||||||||||||||
/// </summary> | ||||||||||||||
/// <param name="keyId">The full Azure Key Vault KeyId</param> | ||||||||||||||
/// <returns>The Server Key Name for the provided KeyId</returns> | ||||||||||||||
|
@@ -41,8 +43,8 @@ public static string CreateServerKeyNameFromKeyId(string keyId) | |||||||||||||
return ServerKeyType.ServiceManaged.ToString(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Validate that the url is a keyvault url and has a key and version | ||||||||||||||
Regex r = new Regex(@"https://(.)+\.(managedhsm.azure.net|managedhsm-preview.azure.net|vault.azure.net|vault-int.azure-int.net|vault.azure.cn|managedhsm.azure.cn|vault.usgovcloudapi.net|managedhsm.usgovcloudapi.net|vault.microsoftazure.de|managedhsm.microsoftazure.de|vault.cloudapi.eaglex.ic.gov|vault.cloudapi.microsoft.scloud)(:443)?\/keys/[^\/]+\/[0-9a-zA-Z]+$", RegexOptions.IgnoreCase); | ||||||||||||||
// Validate that the url is a keyvault url and has a key with an optional version | ||||||||||||||
Regex r = new Regex(@"^https://(.)+\.(managedhsm\.azure\.net|managedhsm-preview\.azure\.net|vault\.azure\.net|vault-int\.azure-int\.net|vault\.azure\.cn|managedhsm\.azure\.cn|vault\.usgovcloudapi\.net|managedhsm\.usgovcloudapi\.net|vault\.microsoftazure\.de|managedhsm\.microsoftazure\.de|vault\.cloudapi\.eaglex\.ic\.gov|vault\.cloudapi\.microsoft\.scloud|mdep\.azure\.net)(:443)?/keys/[^/]+(/([0-9a-zA-Z]+))?/?$", RegexOptions.IgnoreCase); | ||||||||||||||
if (!r.IsMatch(keyId)) | ||||||||||||||
{ | ||||||||||||||
// Throw an error here, since we don't want to use a non keyvault url | ||||||||||||||
|
@@ -53,10 +55,17 @@ public static string CreateServerKeyNameFromKeyId(string keyId) | |||||||||||||
var uri = new Uri(keyId); | ||||||||||||||
|
||||||||||||||
string vault = uri.Host.Split('.').First(); | ||||||||||||||
string key = uri.Segments[2].TrimEnd('/'); | ||||||||||||||
string version = uri.Segments.Last(); | ||||||||||||||
string[] pathSegments = uri.AbsolutePath.Trim('/').Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential IndexOutOfRangeException if
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
string key = pathSegments[1]; | ||||||||||||||
bool hasVersion = pathSegments.Length >= 3 && !string.IsNullOrEmpty(pathSegments[2]); | ||||||||||||||
|
||||||||||||||
return String.Format("{0}_{1}_{2}", vault, key, version); | ||||||||||||||
if (hasVersion) | ||||||||||||||
{ | ||||||||||||||
string version = pathSegments[2]; | ||||||||||||||
return String.Format("{0}_{1}_{2}", vault, key, version); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return String.Format("{0}_{1}", vault, key); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.