Skip to content

Commit

Permalink
fix: fixes azurekms.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhundere committed Nov 21, 2024
1 parent fb457ed commit 867fd39
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ func initKMS(ctx context.Context, config KMSConfig) (apiv1.KeyManager, error) {
}
return cloudkms.New(ctx, opts)
case "azurekms":
opts.URI = fmt.Sprintf("azurekms:///%s?vault-name=%s&tenant-id=%s",
config.KeyID,
config.Options["vault-name"],
config.Options["tenant-id"])
opts.URI = fmt.Sprintf("azurekms://%s.vault.azure.net/keys/%s",
config.Options["vault-name"], config.KeyID)
if config.Options["tenant-id"] != "" {
opts.URI += fmt.Sprintf("?tenant-id=%s", config.Options["tenant-id"])
}
return azurekms.New(ctx, opts)
default:
return nil, fmt.Errorf("unsupported KMS type: %s", config.Type)
Expand All @@ -166,9 +167,15 @@ func createCertificates(km apiv1.KeyManager, rootTemplatePath, intermediateTempl
return fmt.Errorf("error parsing root template: %w", err)
}

// Generate root key pair
rootKeyName := "sigstore-key"
if kmsType == "azurekms" {
// Format: azurekms:vault=vault-name;name=key-name
rootKeyName = fmt.Sprintf("azurekms:vault=%s;name=%s",
kmsVaultName, rootKeyName)
}

rootKey, err := km.CreateKey(&apiv1.CreateKeyRequest{
Name: "root-key",
Name: rootKeyName,
SignatureAlgorithm: apiv1.ECDSAWithSHA256,
})
if err != nil {
Expand All @@ -194,8 +201,16 @@ func createCertificates(km apiv1.KeyManager, rootTemplatePath, intermediateTempl
return fmt.Errorf("error parsing intermediate template: %w", err)
}

// Update intermediate key naming for Azure KMS
intermediateKeyName := "sigstore-key-intermediate"
if kmsType == "azurekms" {
// Format: azurekms:vault=vault-name;name=key-name
intermediateKeyName = fmt.Sprintf("azurekms:vault=%s;name=%s",
kmsVaultName, intermediateKeyName)
}

intermediateKey, err := km.CreateKey(&apiv1.CreateKeyRequest{
Name: "intermediate-key",
Name: intermediateKeyName,
SignatureAlgorithm: apiv1.ECDSAWithSHA256,
})
if err != nil {
Expand Down

0 comments on commit 867fd39

Please sign in to comment.