dsql

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 51 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Dsql

Parity grade: A · SDK aws-sdk-go-v2/service/dsql@v1.22.3 · last audited 2026-10-10 (5bb0d02ee)

Coverage

Metric Value
PARITY entries audited 16 (16 ok)
Feature families 4 (4 ok)
Known gaps 7
Structural gaps (can't be emulated) 2
Deferred items 0
Resource leaks clean
Known gaps
  • Data plane opt-in (DSQL_ENGINE=docker, or --engines=auto/docker with a reachable runtime; default stub keeps the control plane only). The cluster endpoint .dsql..on.aws is not resolvable and clients cannot assume port 5432: connect to host/port from GET /_gopherstack/dsql/clusters/{id}; tokens are generated for the control-plane endpoint (also accepted: endpoint:port, loopback:port). The CA is served at /_gopherstack/dsql/ca.pem.
  • Cluster data is ephemeral: each data plane is a fresh postgres container with no volume, so a restart or snapshot restore re-creates clusters (CREATING until up) with an empty database.
  • Unsupported-feature rejection covers CREATE TRIGGER, DROP TRIGGER, ALTER TABLE ... DISABLE/ENABLE TRIGGER, isolation levels other than repeatable read, temporary tables, TRUNCATE, VACUUM, CREATE TABLESPACE, CREATE DATABASE and LANGUAGE plpgsql functions at the statement start only (not inside multi-statement strings or DO blocks). Foreign keys and sequences are accepted: the current User Guide documents both as supported (the bd issue text predates that). Plain CREATE INDEX is rejected (ASYNC required). The unsupported set matches the migration guide (no triggers, temporary tables, TRUNCATE, VACUUM, tablespaces or extra databases; SQL functions but no PL/pgSQL).
  • CREATE INDEX ASYNC runs a plain (blocking) CREATE INDEX in a background job: CONCURRENTLY deadlocks with a session in sys.wait_for_job, so a failed unique build leaves no INVALID index (DSQL leaves one). Old completed/failed rows are pruned on the next submit as documented; job_id is 26 base32 characters as in the docs, object_id is the index oid once built.
  • Transaction rules are enforced inside PostgreSQL (event + statement triggers with transition tables), so they hold on both wire protocols. Still open, each with its blocker: the 5 minute transaction age limit ('transaction age limit of 300s exceeded') needs a hook at commit or a timer inside the server, and stock PostgreSQL has neither (a statement-time check would not fire for an idle transaction, and a test would need a 5 minute wait); the 1 KiB combined index key size limit ('key size too large') needs per-index key bytes of every written row, which the statement-level transition-table guard in services/dsql/bootstrap.go (gs_dml_ins) does not compute; the 128 MiB per-query memory limit ('query requires too much temp space, out of memory', 53200) has no PostgreSQL setting with that behaviour.
  • The cluster resource policy (PutClusterPolicy) is not evaluated at connect time; only the caller's identity policies are, and only when IAM enforcement is on. AWS IAM GRANT/REVOKE and sys.iam_pg_role_mappings are modelled (roles are logged in with an engine-private password), other sys.* views are absent.
  • The postgres TLS front proxy duplicates the framing and startup code in services/rds/engine_proxy.go; a shared pkgs/ package is a follow-up.
Structural gaps

These do not block an A grade — no implementation could produce real data here because the underlying data source cannot exist in an emulator.

  • bypassPolicyLockoutSafetyCheck (CreateCluster, PutClusterPolicy) is accepted but not evaluated: the lockout check asks whether the calling principal keeps access, and the emulator has no authenticated caller identity or IAM policy evaluation (same stance as services/kms).
  • GetVpcEndpointServiceName returns wire-shaped names only: there is no PrivateLink / VPC endpoint plane to back them.

More

Documentation

Index

Constants

View Source
const (
	EngineStub   = "stub"
	EngineDocker = "docker"
)

Engine modes for the DSQL data plane.

Variables

View Source
var (
	// ErrClusterNotFound is returned when a cluster identifier does not exist.
	ErrClusterNotFound = awserr.New("cluster not found", awserr.ErrNotFound)
	// ErrStreamNotFound is returned when a stream identifier does not exist.
	ErrStreamNotFound = awserr.New("stream not found", awserr.ErrNotFound)
	// ErrPolicyNotFound is returned when a cluster has no resource policy set.
	ErrPolicyNotFound = awserr.New("cluster policy not found", awserr.ErrNotFound)
	// ErrDeletionProtected is returned when DeleteCluster is called on a
	// cluster with deletionProtectionEnabled set.
	ErrDeletionProtected = awserr.New("cluster has deletion protection enabled", awserr.ErrInvalidParameter)
	// ErrValidation is returned when request input fails validation.
	ErrValidation = awserr.New("invalid argument", awserr.ErrInvalidParameter)
	// ErrPolicyVersionMismatch is returned when an expectedPolicyVersion does
	// not match the cluster's current policy version.
	ErrPolicyVersionMismatch = awserr.New("policy version mismatch", awserr.ErrConflict)
	// ErrClusterQuotaExceeded is returned when an account/region would exceed
	// the emulated per-region cluster quota.
	ErrClusterQuotaExceeded = errors.New("cluster quota exceeded")
	// ErrStreamQuotaExceeded is returned when a cluster would exceed the
	// emulated per-cluster stream quota.
	ErrStreamQuotaExceeded = errors.New("stream quota exceeded")
)
View Source
var ErrNoSnapshot = errors.New("backend does not support restore")

ErrNoSnapshot is returned when a backend does not support snapshot/restore.

View Source
var ErrTokenReused = awserr.New("client token was already used with different parameters", awserr.ErrConflict)

ErrTokenReused is a clientToken reused with different parameters; the SDK declares only ConflictException for it.

Functions

This section is empty.

Types

type CADirConfig

type CADirConfig interface {
	GetDSQLCADir() string
}

CADirConfig locates the directory persisting the data-plane CA; empty keeps it in memory.

type Cluster

type Cluster struct {
	CreationTime              time.Time
	PendingUntil              time.Time
	Policy                    *ClusterPolicy
	MultiRegion               *MultiRegionProperties
	Tags                      map[string]string
	Identifier                string
	ARN                       string
	Endpoint                  string
	Status                    string
	KmsEncryptionKey          string
	AccountID                 string
	Region                    string
	DeletionProtectionEnabled bool
}

Cluster is the persisted representation of an Aurora DSQL cluster.

type ClusterPolicy

type ClusterPolicy struct {
	Policy  string
	Version string
}

ClusterPolicy is a resource-based policy attached to a cluster.

type ClusterRef

type ClusterRef struct {
	ID        string
	Endpoint  string
	Region    string
	AccountID string
	ARN       string
}

ClusterRef identifies the cluster a data plane is launched for.

type ConfigProvider

type ConfigProvider interface {
	GetDSQLSettings() Settings
}

ConfigProvider supplies DSQL settings from the application config.

type CreateClusterInput

type CreateClusterInput struct {
	MultiRegion               *MultiRegionProperties
	Tags                      map[string]string
	Policy                    string
	KmsEncryptionKey          string
	DeletionProtectionEnabled bool
}

CreateClusterInput carries CreateCluster's optional fields.

type CreateStreamInput

type CreateStreamInput struct {
	Target   *StreamTarget
	Tags     map[string]string
	Format   string
	Ordering string
}

CreateStreamInput carries CreateStream's fields.

type DockerConfig

type DockerConfig struct {
	Runtime pgengine.Runtime
	Ports   *portalloc.Allocator
	Logger  *slog.Logger
	// Auth returns the IAM wiring; nil refuses every connection.
	Auth func() *IAMAuthConfig
	// Now is the clock token expiry is checked against; nil means time.Now.
	Now          func() time.Time
	Image        string
	Host         string
	CADir        string
	StartTimeout time.Duration
}

DockerConfig configures the docker data plane: one PostgreSQL container and one TLS proxy per cluster.

type Handler

type Handler struct {
	Backend StorageBackend

	AccountID     string
	DefaultRegion string
	// contains filtered or unexported fields
}

Handler is the HTTP handler for the Aurora DSQL REST-JSON control-plane API.

func NewHandler

func NewHandler(backend StorageBackend) *Handler

NewHandler creates a new Aurora DSQL handler backed by backend.

func (*Handler) ChaosOperations

func (h *Handler) ChaosOperations() []string

ChaosOperations returns all operations that can be fault-injected.

func (*Handler) ChaosRegions

func (h *Handler) ChaosRegions() []string

ChaosRegions returns all regions this handler handles.

func (*Handler) ChaosServiceName

func (h *Handler) ChaosServiceName() string

ChaosServiceName returns the lowercase AWS service name for fault rule matching.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation extracts the operation name from the request.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource extracts the resource identifier from the request.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations returns the list of supported operations.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler function for Aurora DSQL requests.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority returns the routing priority.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all backend state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence by delegating to the backend if it supports it.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher returns a function that matches Aurora DSQL REST API requests.

/tags/{arn} is SigV4-scoped rather than claimed unconditionally: it is a generic-tagging path many restjson1 services reuse verbatim (see .claude/memories/route-matcher-prefix-collision.md), so an unscoped claim here would swallow another service's own TagResource/UntagResource/ ListTagsForResource requests.

func (*Handler) Shutdown

func (h *Handler) Shutdown(_ context.Context)

Shutdown stops every cluster data plane; a no-op without a docker engine.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence by delegating to the backend if it supports it.

type IAMAuthConfig

type IAMAuthConfig struct {
	Identities IAMAuthIdentityProvider
	Sessions   IAMAuthSessionProvider
	// Enforce evaluates dsql:DbConnect[Admin] against the caller's policies; off, any known principal may connect.
	Enforce bool
}

IAMAuthConfig wires token verification to the credential stores.

type IAMAuthIdentityProvider

type IAMAuthIdentityProvider interface {
	ListAllAccessKeys() []iam.AccessKey
	GetUserByAccessKeyID(accessKeyID string) (*iam.User, error)
	GetPoliciesForUser(userName string) ([]string, error)
	GetPoliciesForRole(roleName string) ([]string, error)
}

IAMAuthIdentityProvider is the slice of the IAM backend that token verification needs.

type IAMAuthResolver

type IAMAuthResolver func() IAMAuthConfig

IAMAuthResolver returns the current IAM wiring; it is called per connection so IAM may be created later.

type IAMAuthSessionProvider

type IAMAuthSessionProvider interface {
	LookupSession(accessKeyID, sessionToken string) *sts.SessionInfo
}

IAMAuthSessionProvider resolves STS-issued temporary credentials.

type InMemoryBackend

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

InMemoryBackend is the in-memory implementation of StorageBackend.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates a new in-memory Aurora DSQL backend.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops every cluster data plane and waits for the containers to be removed.

func (*InMemoryBackend) ConnectAddr

func (b *InMemoryBackend) ConnectAddr(identifier string) (string, int, bool)

ConnectAddr returns where clients reach the cluster's database once its data plane is up.

func (*InMemoryBackend) CreateCluster

func (b *InMemoryBackend) CreateCluster(accountID, region string, in CreateClusterInput) (*Cluster, error)

CreateCluster creates a new Aurora DSQL cluster. New clusters start CREATING and lazily transition to ACTIVE on the next read once clusterActivationDelay elapses -- see PARITY.md for why this is a lazy deadline rather than a background reconciler.

func (*InMemoryBackend) CreateStream

func (b *InMemoryBackend) CreateStream(clusterIdentifier string, in CreateStreamInput) (*Stream, error)

CreateStream creates a Kinesis change-data-capture stream on a cluster. New streams start CREATING and lazily transition to ACTIVE on the next read once streamActivationDelay elapses.

func (*InMemoryBackend) DeleteCluster

func (b *InMemoryBackend) DeleteCluster(identifier string) (*Cluster, error)

DeleteCluster marks a cluster DELETING; it is lazily removed from the table clusterDeletionDelay after this call, on the next resolve. A cluster with deletion protection enabled cannot be deleted.

func (*InMemoryBackend) DeleteClusterPolicy

func (b *InMemoryBackend) DeleteClusterPolicy(identifier, expectedVersion string) (*ClusterPolicy, error)

DeleteClusterPolicy removes a cluster's resource-based policy. If expectedVersion is non-empty it must match the current policy version.

func (*InMemoryBackend) DeleteStream

func (b *InMemoryBackend) DeleteStream(clusterIdentifier, streamIdentifier string) (*Stream, error)

DeleteStream marks a stream DELETING; it is lazily removed streamDeletionDelay later, on the next read.

func (*InMemoryBackend) EnableDockerEngine

func (b *InMemoryBackend) EnableDockerEngine(cfg DockerConfig) error

EnableDockerEngine backs every cluster with a PostgreSQL container behind an IAM-token proxy.

func (*InMemoryBackend) EnableEngine

func (b *InMemoryBackend) EnableEngine(l Launcher)

EnableEngine switches the backend to launcher-backed clusters: a cluster turns ACTIVE only once its data plane is up.

func (*InMemoryBackend) EngineCAPEM

func (b *InMemoryBackend) EngineCAPEM() []byte

EngineCAPEM returns the PEM of the CA that signs docker-mode cluster endpoints, or nil without an engine.

func (*InMemoryBackend) GetCluster

func (b *InMemoryBackend) GetCluster(identifier string) (*Cluster, error)

GetCluster returns the current information about a cluster.

func (*InMemoryBackend) GetClusterPolicy

func (b *InMemoryBackend) GetClusterPolicy(identifier string) (*ClusterPolicy, error)

GetClusterPolicy returns a cluster's resource-based policy.

func (*InMemoryBackend) GetStream

func (b *InMemoryBackend) GetStream(clusterIdentifier, streamIdentifier string) (*Stream, error)

GetStream returns the current information about a stream.

func (*InMemoryBackend) GetVpcEndpointServiceName

func (b *InMemoryBackend) GetVpcEndpointServiceName(identifier, region string) (string, string, error)

GetVpcEndpointServiceName returns the VPC endpoint service name and cluster-specific VPC endpoint DNS name a client would use to reach the cluster privately. There is no real VPC/PrivateLink plane behind this emulator, so both values are wire-shaped but not backed by a functioning endpoint -- see PARITY.md.

func (*InMemoryBackend) ListClusters

func (b *InMemoryBackend) ListClusters(nextToken string, maxResults int) ([]*Cluster, string, error)

ListClusters returns clusters ordered by identifier, paginated by nextToken/maxResults.

func (*InMemoryBackend) ListStreams

func (b *InMemoryBackend) ListStreams(clusterIdentifier, nextToken string, maxResults int) ([]*Stream, string, error)

ListStreams returns a cluster's streams ordered by stream identifier, paginated by nextToken/maxResults.

func (*InMemoryBackend) ListTagsForResource

func (b *InMemoryBackend) ListTagsForResource(resourceARN string) (map[string]string, error)

ListTagsForResource returns all tags on a cluster.

func (*InMemoryBackend) PutClusterPolicy

func (b *InMemoryBackend) PutClusterPolicy(identifier, policy, expectedVersion string) (*ClusterPolicy, error)

PutClusterPolicy creates or replaces a cluster's resource-based policy. If expectedVersion is non-empty it must match the current policy version (optimistic concurrency), matching PutClusterPolicyInput's expectedPolicyVersion semantics.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all backend state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore deserializes backend state from a JSON snapshot.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the wall clock used for lifecycle deadlines; nil restores time.Now.

func (*InMemoryBackend) SetIAMAuth

func (b *InMemoryBackend) SetIAMAuth(r IAMAuthResolver)

SetIAMAuth registers the resolver consulted for every connection to a docker-backed cluster.

func (*InMemoryBackend) SetLifecycleDelay

func (b *InMemoryBackend) SetLifecycleDelay(d time.Duration)

SetLifecycleDelay overrides the CREATING/UPDATING/DELETING windows for clusters and streams; 0 keeps the built-in values.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serializes backend state to JSON.

func (*InMemoryBackend) TagResource

func (b *InMemoryBackend) TagResource(resourceARN string, tags map[string]string) error

TagResource adds or replaces tags on a cluster identified by its ARN.

func (*InMemoryBackend) UntagResource

func (b *InMemoryBackend) UntagResource(resourceARN string, tagKeys []string) error

UntagResource removes tags from a cluster by key.

func (*InMemoryBackend) UpdateCluster

func (b *InMemoryBackend) UpdateCluster(identifier string, in UpdateClusterInput) (*Cluster, error)

UpdateCluster updates a cluster's mutable configuration and transitions it through UPDATING back to ACTIVE on the next read.

type Instance

type Instance interface {
	// Addr is the host and port clients connect to.
	Addr() (string, int)
	// Close stops the data plane and releases its resources.
	Close(ctx context.Context)
}

Instance is one running cluster data plane.

type Launcher

type Launcher interface {
	Launch(ctx context.Context, ref ClusterRef) (Instance, error)
}

Launcher starts the data plane of a cluster and returns once the database accepts connections.

type MultiRegionProperties

type MultiRegionProperties struct {
	WitnessRegion string
	Clusters      []string
}

MultiRegionProperties mirrors types.MultiRegionProperties.

type Provider

type Provider struct{}

Provider implements service.Provider for the Aurora DSQL service.

func (*Provider) Init

Init initializes the Aurora DSQL service backend and handler.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

type Settings

type Settings struct {
	Engine      string `json:"engine"       env:"DSQL_ENGINE"       default:"stub"        help:"Engine: stub or docker."`
	EngineImage string `json:"engine_image" env:"DSQL_ENGINE_IMAGE" default:"postgres:17" help:"PostgreSQL image."`
}

Settings holds service-level configuration for the DSQL backend. Kong picks the fields up when the struct is embedded in the root CLI command.

type Snapshottable

type Snapshottable interface {
	Snapshot(ctx context.Context) []byte
	Restore(context.Context, []byte) error
}

Snapshottable is an optional interface a StorageBackend may implement to support snapshot/restore for persistence or test isolation.

type StorageBackend

type StorageBackend interface {
	CreateCluster(accountID, region string, in CreateClusterInput) (*Cluster, error)
	GetCluster(identifier string) (*Cluster, error)
	ListClusters(nextToken string, maxResults int) ([]*Cluster, string, error)
	UpdateCluster(identifier string, in UpdateClusterInput) (*Cluster, error)
	DeleteCluster(identifier string) (*Cluster, error)

	GetClusterPolicy(identifier string) (*ClusterPolicy, error)
	PutClusterPolicy(identifier, policy, expectedVersion string) (*ClusterPolicy, error)
	DeleteClusterPolicy(identifier, expectedVersion string) (*ClusterPolicy, error)

	GetVpcEndpointServiceName(identifier, region string) (serviceName, clusterVpcEndpoint string, err error)

	CreateStream(clusterIdentifier string, in CreateStreamInput) (*Stream, error)
	GetStream(clusterIdentifier, streamIdentifier string) (*Stream, error)
	DeleteStream(clusterIdentifier, streamIdentifier string) (*Stream, error)
	ListStreams(clusterIdentifier, nextToken string, maxResults int) ([]*Stream, string, error)

	TagResource(resourceARN string, tags map[string]string) error
	UntagResource(resourceARN string, tagKeys []string) error
	ListTagsForResource(resourceARN string) (map[string]string, error)

	Reset()
}

StorageBackend is the interface for the Aurora DSQL backend.

type Stream

type Stream struct {
	CreationTime      time.Time
	PendingUntil      time.Time
	Target            *StreamTarget
	Tags              map[string]string
	ClusterIdentifier string
	StreamIdentifier  string
	ARN               string
	Status            string
	Format            string
	Ordering          string
}

Stream is the persisted representation of an Aurora DSQL change-data-capture stream.

type StreamTarget

type StreamTarget struct {
	RoleArn   string
	StreamArn string
}

StreamTarget mirrors types.TargetDefinitionMemberKinesis.

type UpdateClusterInput

type UpdateClusterInput struct {
	MultiRegion               *MultiRegionProperties
	DeletionProtectionEnabled *bool
	KmsEncryptionKey          string
}

UpdateClusterInput carries UpdateCluster's optional fields. A nil pointer means "leave unchanged"; KmsEncryptionKey uses the empty string to mean "unchanged" and the reserved value "AWS_OWNED_KMS_KEY" to mean "revert to the AWS owned key", matching the real API's documented semantics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL