Skip to main content

Embed storage backends in Go

Use go-authcrunch v1.7.1 with the companion Go modules below. The Caddy companions register Caddy modules. A Go application imports the concrete backend packages it uses and opens them itself.

Go modulePinIntegration notes
go-authcrunch-sqlitev1.1.0Use a private absolute file per storage purpose. Existing backend imports and parsers moved out of core.
go-authcrunch-consulv1.1.0Prepare the Consul SDK client and consulkv.NewBinding. Logical backends borrow that client.
go-authcrunch-aws-dyndbv1.2.0Pass dynamo.Config to each backend or use NewWithClient where provided to reuse an opened client. File Vault also needs S3.

SQLite packages previously imported as go-authcrunch/plugins/CATEGORY/sqlite now live in the standalone module. Update imports to the concrete package names below, including their parser subpackages. Keep existing database paths and the identities that own them. The direct Go parsers validate typed settings without installing a Caddy module or opening a runtime. Preserve quoting when generating statements. A host can use cfgutil.EncodeArgs to encode a value containing spaces.

Bind the declaration and the runtime​

Use authcrunch.NewServerWithOptions for root composition. Pass the returned backend descriptor when that consumer requires one, and bind the actual initialized runtime by the same exact name in ServerOptions. Configure each portal or policy to select its intended backend. An existing root JSON file contains declarations, while interface values and constructors are supplied by the host on each start.

PackageDeclarative selectionRuntime binding
identitystoreConfig.ExternalIdentityStores and the portal's identity-store namesServerOptions.IdentityStores
ticketConfig.ExternalIdentityProviders and the portal's provider namesServerOptions.IdentityProviders. To select an eligible built-in local attachment, supply the matching IdentityProviderAttachmentStores mapping.
oauthloginProvider's login_store.name and login_store.namespaceServerOptions.OAuthLoginStores
refreshstoreConfig.ExternalRefreshStores and portal's refresh_tokens.storeServerOptions.RefreshStores with a managed store and matching limits
registrationConfig.ExternalUserRegistries and the portal's workflow namesServerOptions.UserRegistries with the selected account store and outbox already opened
messagingConfigured queue name selected by registration or another consumerAdd the provider through messaging.Config.AddProvider. Start delivery separately.
credentialsPolicy's named credential authenticator and realmAttach to a gatekeeper with AddAuthenticators before serving
secretsHost-selected manager and recordResolve validated typed fields before constructing consumers that use them
documentsstoreEnabled Documents API with the portal's documents.storeServerOptions.DocumentsFactories. The selected factory opens a fresh handle owned by that portal.

Consul supplies six of these packages. Consult the capability matrix when choosing a driver. SQLite and DynamoDB registration bind to the corresponding account and outbox implementations. A standalone portal can use the corresponding authn.PortalParameters where available. For direct File Vault composition, pass PortalParameters.DocumentsFactory.

Open a SQLite identity store​

This helper expects a prepared configuration with a portal selecting accounts and an identity database whose existing users belong to realm staff. Add the corresponding runtime bindings if your configuration uses other injected backends. The root borrows the account store. The host removes the server from HTTP routing and drains requests before closing it and the store.

package integration

import (
"context"
"errors"
"slices"

"github.com/greenpau/go-authcrunch"
"github.com/greenpau/go-authcrunch-sqlite/identitystore"
"github.com/greenpau/go-authcrunch/pkg/ids"
"go.uber.org/zap"
)

func OpenAccounts(
ctx context.Context, config authcrunch.Config, dbPath string, log *zap.Logger,
) (*authcrunch.Server, func() error, error) {
settings := &identitystore.Config{Name: "accounts", Realm: "staff", Path: dbPath}
if err := settings.Validate(); err != nil {
return nil, nil, err
}
store, err := identitystore.New(ctx, settings)
if err != nil {
return nil, nil, err
}
descriptor, err := ids.NewExternalIdentityStoreConfig(
settings.Name, store.GetKind(), settings.Realm, settings,
)
if err != nil {
return nil, nil, errors.Join(err, store.Close())
}
config.ExternalIdentityStores = append(slices.Clone(config.ExternalIdentityStores), descriptor)
server, err := authcrunch.NewServerWithOptions(&config, log, authcrunch.ServerOptions{
IdentityStores: map[string]ids.IdentityStore{settings.Name: store},
})
if err != nil {
return nil, nil, errors.Join(err, store.Close())
}
closeServer := func() error {
return errors.Join(server.Close(), store.Close())
}
return server, closeServer, nil
}

A trusted setup process can use Store.Create to provision a user with a password supplied privately. Opening the store does not provision a default administrator. Keep immutable account IDs and current credential evidence intact. Wrapping an injected identity store can hide optional methods such as RequestWithIdentity or WithRefreshIdentity. Preserve the interfaces required by the portal's Profile, Documents or refresh features.

Handle File Vault and shutdown ownership​

Call the backend's documentsstore.Config.Factory() with the private SQLite path or the DynamoDB and S3 settings. Use the resulting factory in the runtime-options map under the portal's exact store name. A factory receives the normalized Documents settings and portal name. It must reject an incompatible binding and return a fresh handle. The portal closes that handle after draining. Keep each selected name unique across enabled portals. An enabled portal with no matching factory fails construction.

The host owns borrowed stores, signers and providers. Build dependencies before their consumers. On failure or shutdown, stop admitting requests, drain, close the root, and dispose of its borrowed dependencies in reverse order. For registration and delivery, close workflows and workers before closing the account store and outbox. A worker that has already obtained SMTP acceptance can finish its bounded acknowledgement during shutdown. Keep cleanup paths for partial construction. An uncertain commit means the operation may have succeeded, so inspect state or use the backend's recovery procedure before replaying it.

Agentic Prompts​

Bind a typed identity store
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/operations/backend-embedding

Explain the descriptor, runtime and portal selection for one SQLite realm. Trace partial startup failure and request drain.
Move old SQLite imports
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/operations/backend-embedding

Map the previous package paths to the new module and preserve durable database paths and account identities.
Design File Vault ownership
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/operations/backend-embedding

Compare a named root factory and a direct portal factory. Explain the unique store selection, opening, binding and close behavior.
Preserve optional methods
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/operations/backend-embedding

Review an embedding wrapper for SQLite accounts. Identify the method sets needed for Profile, refresh and Documents and match them to the handler checks.
Shut down queue and registration dependencies
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/operations/backend-embedding

Plan the open and close order for an account store, mail queue, delivery worker, signup workflow and AuthCrunch root. Include uncertain results and partial construction.

Source Code References​