Skip to content

Commit 8c35e6e

Browse files
committed
fix(azkv): handle whitespace in Azure Key Vault URLs
### Problem: The Azure Key Vault key parser would fail when URLs contained leading or trailing whitespace, which commonly occurs when using YAML Block Scalar syntax. ```yaml creation_rules: - azure_keyvault: >- https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90, https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e ``` This resulted in the error: ```bash "could not parse " https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e" into a valid Azure Key Vault MasterKey" ``` ### Fix: - Added `strings.TrimSpace()` to clean the URL before parsing in `NewMasterKeyFromURL()` - Added test case to verify handling of URLs with leading/trailing spaces Signed-off-by: Vasily Marnopolsky <sept0r.com@gmail.com>
1 parent 7880ef4 commit 8c35e6e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

azkv/keysource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
7676
// NewMasterKeyFromURL takes an Azure Key Vault key URL, and returns a new
7777
// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
7878
func NewMasterKeyFromURL(url string) (*MasterKey, error) {
79+
url = strings.TrimSpace(url)
7980
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
8081
parts := re.FindStringSubmatch(url)
8182
if parts == nil || len(parts) < 3 {

azkv/keysource_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ func TestMasterKeysFromURLs(t *testing.T) {
8888
},
8989
},
9090
},
91+
{
92+
name: "multiple URLs with leading and trailing spaces",
93+
urls: " https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90 , https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e ",
94+
expectKeyCount: 2,
95+
expectKeys: []MasterKey{
96+
{
97+
VaultURL: "https://test.vault.azure.net",
98+
Name: "test-key",
99+
Version: "a2a690a4fcc04166b739da342a912c90",
100+
},
101+
{
102+
VaultURL: "https://test2.vault.azure.net",
103+
Name: "another-test-key",
104+
Version: "cf0021e8b743453bae758e7fbf71b60e",
105+
},
106+
},
107+
},
91108
{
92109
name: "multiple URLs, one malformed",
93110
urls: "https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90,https://test.vault.azure.net/no-keys-here/test-key/a2a690a4fcc04166b739da342a912c90",

0 commit comments

Comments
 (0)