Skip to content
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

fix: fixes azurekms. #29

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 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,14 @@ 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" {
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 +200,14 @@ func createCertificates(km apiv1.KeyManager, rootTemplatePath, intermediateTempl
return fmt.Errorf("error parsing intermediate template: %w", err)
}

intermediateKeyName := "sigstore-key-intermediate"
if kmsType == "azurekms" {
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
Loading