Documentation
¶
Overview ¶
Package certmagicazureblob provides an Azure Blob Storage backend for CertMagic, enabling distributed TLS certificate management across a Caddy cluster.
Index ¶
- type AzureBlobStorage
- func (*AzureBlobStorage) CaddyModule() caddy.ModuleInfo
- func (s *AzureBlobStorage) CertMagicStorage() (certmagic.Storage, error)
- func (s *AzureBlobStorage) Cleanup() error
- func (s *AzureBlobStorage) Delete(ctx context.Context, key string) error
- func (s *AzureBlobStorage) Exists(ctx context.Context, key string) bool
- func (s *AzureBlobStorage) List(ctx context.Context, pathPrefix string, recursive bool) ([]string, error)
- func (s *AzureBlobStorage) Load(ctx context.Context, key string) ([]byte, error)
- func (s *AzureBlobStorage) Lock(ctx context.Context, name string) error
- func (s *AzureBlobStorage) Provision(ctx caddy.Context) error
- func (s *AzureBlobStorage) Stat(ctx context.Context, key string) (certmagic.KeyInfo, error)
- func (s *AzureBlobStorage) Store(ctx context.Context, key string, value []byte) error
- func (s *AzureBlobStorage) Unlock(ctx context.Context, name string) error
- func (s *AzureBlobStorage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (s *AzureBlobStorage) Validate() error
- type ClientProvider
- type ConnStringProvider
- type SASClientProvider
- type ServicePrincipalProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AzureBlobStorage ¶
type AzureBlobStorage struct {
// ConnectionString is the Azure Storage account connection string.
// Provides account-level access. Mutually exclusive with other auth methods.
ConnectionString string `json:"connection_string,omitempty"`
// ContainerSASURL is a container-scoped SAS URL for least-privilege access.
// Restricts the plugin to a single container with only the permissions
// granted by the SAS token. Mutually exclusive with other auth methods.
// Example: https://<account>.blob.core.windows.net/<container>?<sas-params>
ContainerSASURL string `json:"container_sas_url,omitempty"`
// TenantID is the Azure AD tenant ID for service principal auth.
TenantID string `json:"tenant_id,omitempty"`
// ClientID is the Azure AD application (client) ID for service principal auth.
ClientID string `json:"client_id,omitempty"`
// ClientSecret is the Azure AD client secret for service principal auth.
ClientSecret string `json:"client_secret,omitempty"`
// AccountURL is the Azure Blob Storage service URL for service principal auth.
// Example: https://<account>.blob.core.windows.net
// Supports sovereign clouds, private endpoints, and Azurite.
AccountURL string `json:"account_url,omitempty"`
// EncryptionKey is an optional hex-encoded 32-byte AES-256-GCM key.
EncryptionKey string `json:"encryption_key,omitempty"`
// Container is the blob container name. Default: "caddy-certs".
Container string `json:"container,omitempty"`
// Prefix is an optional path prefix for all blob names within the container.
Prefix string `json:"prefix,omitempty"`
// LeaseDuration is the blob lease duration in seconds (15-60). Default: 30.
LeaseDuration int32 `json:"lease_duration,omitempty"`
// CleanLockBlobs deletes lock blobs after releasing the lease. Default: false.
// When false, empty lock blobs accumulate in the locks/ prefix over time.
// For most deployments, an Azure Blob lifecycle management policy is the
// better cleanup approach — see README for details.
CleanLockBlobs bool `json:"clean_lock_blobs,omitempty"`
// CreateContainer controls whether the plugin auto-creates the blob container
// on startup. Default: true. Set to false when the container is pre-provisioned
// by infrastructure tooling, which allows tighter RBAC (no container-create
// permission needed).
CreateContainer *bool `json:"create_container,omitempty"`
// contains filtered or unexported fields
}
AzureBlobStorage implements certmagic.Storage using Azure Blob Storage. It supports distributed locking via Azure Blob Leases, making it suitable for Caddy clusters that share TLS certificates.
func (*AzureBlobStorage) CaddyModule ¶
func (*AzureBlobStorage) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*AzureBlobStorage) CertMagicStorage ¶
func (s *AzureBlobStorage) CertMagicStorage() (certmagic.Storage, error)
CertMagicStorage returns the storage implementation. Required by Caddy's storage module interface.
func (*AzureBlobStorage) Cleanup ¶
func (s *AzureBlobStorage) Cleanup() error
Cleanup releases all held locks and cleans up resources. Called by Caddy during shutdown.
func (*AzureBlobStorage) Delete ¶
func (s *AzureBlobStorage) Delete(ctx context.Context, key string) error
Delete removes the value at key. If the key is a prefix (directory), all keys under it are deleted. Delete is idempotent — deleting a non-existent key is not an error.
func (*AzureBlobStorage) Exists ¶
func (s *AzureBlobStorage) Exists(ctx context.Context, key string) bool
Exists returns true if the key exists as either a blob or a prefix (directory).
func (*AzureBlobStorage) List ¶
func (s *AzureBlobStorage) List(ctx context.Context, pathPrefix string, recursive bool) ([]string, error)
List returns all keys matching the given path prefix.
func (*AzureBlobStorage) Lock ¶
func (s *AzureBlobStorage) Lock(ctx context.Context, name string) error
Lock acquires a distributed lock for the given name. It blocks until the lock is acquired or the context is cancelled. The lock is maintained by a background goroutine that renews the underlying blob lease periodically.
func (*AzureBlobStorage) Provision ¶
func (s *AzureBlobStorage) Provision(ctx caddy.Context) error
Provision sets up the storage module. Called by Caddy after configuration is loaded.
func (*AzureBlobStorage) Stat ¶
Stat returns information about the key. For prefix (directory) keys, it returns a non-terminal KeyInfo.
func (*AzureBlobStorage) Unlock ¶
func (s *AzureBlobStorage) Unlock(ctx context.Context, name string) error
Unlock releases a previously acquired lock.
func (*AzureBlobStorage) UnmarshalCaddyfile ¶
func (s *AzureBlobStorage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile parses the Caddyfile configuration for this module.
storage azure_blob {
connection_string "{$AZURE_STORAGE_CONNECTION_STRING}"
container_sas_url "{$CADDY_CERTS_SAS_URL}"
tenant_id "{$AZURE_TENANT_ID}"
client_id "{$AZURE_CLIENT_ID}"
client_secret "{$AZURE_CLIENT_SECRET}"
account_url "https://myaccount.blob.core.windows.net"
encryption_key "{env.CADDY_CERT_ENCRYPTION_KEY}"
container caddy-certs
prefix ""
lease_duration 30
clean_lock_blobs
create_container false
}
func (*AzureBlobStorage) Validate ¶
func (s *AzureBlobStorage) Validate() error
Validate checks that the configuration is valid and Azure is reachable. Called by Caddy after Provision, before the module is used.
type ClientProvider ¶
type ClientProvider interface {
// ContainerClient returns an Azure Blob container client for the given container name.
// Implementations should cache or reuse clients where appropriate.
ContainerClient(ctx context.Context, containerName string) (*container.Client, error)
}
ClientProvider abstracts Azure Blob Storage client creation. Implement this interface to support different authentication methods (connection string, managed identity, SAS tokens, etc.).
type ConnStringProvider ¶
type ConnStringProvider struct {
ConnectionString string
// contains filtered or unexported fields
}
ConnStringProvider implements ClientProvider using an Azure Storage connection string.
func NewConnStringProvider ¶
func NewConnStringProvider(connectionString string, skipEnsure bool) *ConnStringProvider
NewConnStringProvider creates a ConnStringProvider with the given connection string.
type SASClientProvider ¶
type SASClientProvider struct {
// ContainerSASURL is the full SAS URL for the container, e.g.:
// https://<account>.blob.core.windows.net/<container>?<sas-params>
ContainerSASURL string
// ContainerName is the container name extracted from the SAS URL during provisioning.
ContainerName string
// contains filtered or unexported fields
}
SASClientProvider implements ClientProvider using a container-scoped SAS URL. This restricts access to a single container with only the permissions granted by the SAS token — no account-level access, no other containers.
func (*SASClientProvider) ContainerClient ¶
type ServicePrincipalProvider ¶
type ServicePrincipalProvider struct {
// AccountURL is the Azure Blob Storage service URL, e.g.:
// https://<account>.blob.core.windows.net
// Supports sovereign clouds, private endpoints, and Azurite.
AccountURL string
TenantID string
ClientID string
ClientSecret string
// contains filtered or unexported fields
}
ServicePrincipalProvider implements ClientProvider using Azure AD service principal credentials (client ID, client secret, tenant ID). This is the recommended auth method for production deployments where managed identity is not available and you want to avoid long-lived connection strings.
func NewServicePrincipalProvider ¶
func NewServicePrincipalProvider(accountURL, tenantID, clientID, clientSecret string, skipEnsure bool) *ServicePrincipalProvider
NewServicePrincipalProvider creates a ServicePrincipalProvider with the given credentials.