Skip to content

Go: package gcpkms

Generated from the Go source by scripts/gen-docs.sh — do not edit; run it to regenerate. Canonical deep reference: pkg.go.dev/github.com/dnsid-ai/dnsid-go/key/gcp. Guides and account setup: https://docs.dnsid.ai.

import "github.com/dnsid-ai/dnsid-go/key/gcp"

Package gcpkms implements an optional Google Cloud KMS-backed DNSid key provider for existing software EC_SIGN_ED25519 versions. Private keys remain in KMS. Signing uses RAW data, not a precomputed digest, with CRC32C integrity and immutable version binding checks.

Supply an official *kms.KeyManagementClient to New; the caller owns and closes that client. Official client options can select a local gRPC endpoint for credential-free integration tests. The provider never creates local files.

Importing this package also registers the google-kms configuration factory:

import _ "github.com/dnsid-ai/dnsid-go/key/gcp"

Configuration keyRef must name an existing numeric CryptoKeyVersion. Optional project and location settings must match keyRef; algorithm, if set, is EdDSA. Credentials use Google’s Application Default Credentials chain, not settings. Configuration opening never creates keys and never falls back to local files. Providers opened through configuration own their client; applications can call Close after all operations finish to release it.

GenerateKey explicitly creates a pending version under the configured parent CryptoKey, whose template must specify software EC_SIGN_ED25519. If KMS reports PENDING_GENERATION, GenerateKey observes that exact version until enabled, sharing one 30-second budget with creation and public-key validation. This requires GetCryptoKeyVersion support and cloudkms.cryptoKeyVersions.get; immediate-enabled creation does not use that method. Readiness within the budget is not guaranteed. Cloud cleanup remains operator-owned on failure, even if a version becomes ready later. Locally pending keys support JWK and SignKey but do not enter the active listing. Activate and Supersede change local eligibility only; they never disable or destroy cloud versions. State is in-memory only: reopening the configured version does not recover pending or superseded state. Applications must not treat reopening as managed-rotation recovery. Persistence and orchestration are not provided.

Merely opening a cloud key is not a migration of an established identity; changing its signer requires authorized rotation.

Install this nested module separately; the base SDK does not depend on Google Cloud libraries. See https://docs.dnsid.ai for DNSid documentation.

Copyright 2026 Known Systems AI, Inc.

Client is the official Google Cloud KMS runtime surface used by Provider. A *kms.KeyManagementClient implements it directly. The caller owns its lifetime.

type Client interface {
GetPublicKey(context.Context, *kmspb.GetPublicKeyRequest, ...gax.CallOption) (*kmspb.PublicKey, error)
AsymmetricSign(context.Context, *kmspb.AsymmetricSignRequest, ...gax.CallOption) (*kmspb.AsymmetricSignResponse, error)
}

Config selects an existing immutable software Ed25519 version.

type Config struct {
// KeyVersionName is projects/{project}/locations/{location}/keyRings/{ring}/cryptoKeys/{key}/cryptoKeyVersions/{number}.
KeyVersionName string
}

Provider signs RAW Ed25519 messages using an existing Google Cloud KMS version. It caches only public material and is safe for concurrent use. Each signing call has a 30-second timeout. Rotation state is local and in-memory only.

type Provider struct {
// contains filtered or unexported fields
}

func Create(ctx context.Context, client Client, parent string) (*Provider, string, string, error)

Create explicitly creates the first software Ed25519 version under an existing ASYMMETRIC_SIGN CryptoKey with a software EC_SIGN_ED25519 template. No prior version is required or read. The client must also support GetCryptoKey and CreateCryptoKeyVersion (and GetCryptoKeyVersion while generation is pending). Creation, readiness and public validation share a 30-second budget. Success returns the provider, validated pending RFC7638 public-key thumbprint (kid), and immutable created version reference. The active listing and default JWK remain empty until Activate is called with that kid, before manager injection. Errors return no provider, kid or reference; after a validated create response, the error includes the known version for reconciliation and wraps its cause. No files are written, remote resources deleted, or failed creates retried. Reconciliation and cleanup are operator-owned, and the client is caller-owned. New and Open continue to open existing immutable versions only.

func New(ctx context.Context, client Client, cfg Config) (*Provider, error)

New opens an existing version, validating its binding, algorithm, software protection and public-key CRC32C. It never creates a key or substitutes a signer. Service and context errors are preserved for errors.Is and gRPC status handling.

func Open(ctx context.Context, src config.KeySource, opts ...option.ClientOption) (*Provider, error)

Open validates configuration and opens its existing immutable version using the official Google client. Options configure that client’s transport and authentication; they do not become deployment settings. With no options, authentication uses Application Default Credentials, as in the registered google-kms factory. No key is created and no file signer is substituted.

The returned provider owns the created client: call Close after all operations finish. On failure Open closes the created client. A connection supplied via option.WithGRPCConn is subject to the official client’s Close behavior, which may close it (including on an opening failure). Supply a dedicated connection, not one shared with unrelated clients.

func (p *Provider) Activate(kid string) error

Activate explicitly promotes a pending key. The previous key remains available as a public JWK but cannot sign. No remote version state is changed.

func (p *Provider) Close() error

Close releases the client created by Open or configuration loading. For New or Create, the caller owns the supplied client and Close is a no-op. Connections supplied through option.WithGRPCConn may also be closed by the official client. Call only after all provider operations have completed.

func (p *Provider) GenerateKey(alg dnsid.JoseAlg) (string, error)

GenerateKey explicitly creates a locally pending Ed25519 version under the configured CryptoKey, whose template must specify software EC_SIGN_ED25519. The client must support CreateCryptoKeyVersion and, if generation is pending in KMS, GetCryptoKeyVersion (requiring cloudkms.cryptoKeyVersions.get). Creation, readiness waiting and public-key validation share a 30-second budget. Failed validation or waiting leaves local state unchanged; cloud cleanup is operator-owned, including versions that become ready after a timeout.

func (p *Provider) JWK(kid ...string) jwk.Key

JWK returns a detached public JWK for the active key, or nil for an unknown ID.

func (p *Provider) ListKeyIds() []string

ListKeyIds returns only the active public-key thumbprint, never pending or retained IDs.

func (p *Provider) Purge(kid string) error

Purge removes a pending or retained key locally. It rejects the active key and never changes cloud state.

func (p *Provider) Sign(payload []byte) (*dnsid.KeySignature, error)

Sign signs payload without prehashing, using the active version.

func (p *Provider) SignKey(kid string, payload []byte) (*dnsid.KeySignature, error)

SignKey signs with an active or pending key. Retained and unknown IDs fail before any API call. Local transitions wait for in-flight signatures to finish.

func (p *Provider) Supersede(kid string) error

Supersede removes local signing eligibility and public access, without disabling or destroying any cloud version. A different active key is preserved.

Generated by gomarkdoc