buckets

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuditCredentialAccess

func AuditCredentialAccess(ctx context.Context, requestID string, action string, bucket string, err error)

AuditCredentialAccess logs credential access events with request and auth mode context. The fields and result policy intentionally match the legacy S3 credential audit contract.

func AuthorizeScopeWrite

func AuthorizeScopeWrite(ctx context.Context, organization, project string, methods ...string) error

AuthorizeScopeWrite checks the shared authorization policy for creating, updating, or deleting a bucket scope. Missing Gen3 headers remain a transport concern and must be rejected by the caller before invoking this function.

func BucketsAllowedByNames

func BucketsAllowedByNames(ctx context.Context, scopes []Scope, bucket string, methods ...string) bool

BucketsAllowedByNames filters scopes by their physical bucket name and applies ScopeAllowed to matching scopes.

func DeriveCredentialID

func DeriveCredentialID(bucket, provider, region, endpoint, accessKey string) string

DeriveCredentialID returns a stable internal ID derived from the non-secret credential identity. SecretKey is intentionally excluded so credential rotation does not change the identity.

func ScopeAllowed

func ScopeAllowed(ctx context.Context, scope Scope, methods ...string) bool

ScopeAllowed reports whether the caller may use the requested methods for a bucket scope. Transport authentication is checked by the HTTP handler; this function owns the authorization policy shared by bucket endpoints.

func VisibleToCaller

func VisibleToCaller(visible map[string]VisibleBucket, bucket, credentialID string) bool

VisibleToCaller reports whether a caller's bucket or credential aliases are represented in a visible bucket map.

Types

type Credential

type Credential struct {
	CredentialID string `db:"credential_id"`
	Bucket       string `db:"bucket"`
	Provider     string `db:"provider"`
	Region       string `db:"region"`
	AccessKey    string `db:"access_key"`
	SecretKey    string `db:"secret_key"`
	Endpoint     string `db:"endpoint"`
}

Credential represents the s3_credential table and the provider credentials consumed by storage implementations. SecretKey is never part of derived identity, but remains available to the provider after decryption.

type CredentialAdmin

type CredentialAdmin interface {
	SaveS3Credential(ctx context.Context, cred *Credential) error
	DeleteS3Credential(ctx context.Context, bucket string) error
}

CredentialAdmin owns credential creation and deletion.

type CredentialReader

type CredentialReader interface {
	GetS3Credential(ctx context.Context, bucket string) (*Credential, error)
	ListS3Credentials(ctx context.Context) ([]Credential, error)
}

CredentialReader reads configured bucket credentials.

type Dependencies

type Dependencies struct {
	Credentials     CredentialReader
	CredentialAdmin CredentialAdmin
	Scopes          ScopeStore
	Visibility      VisibilityQuery
	Fallback        VisibilityFallback
}

Dependencies are the narrow repository and visibility ports used by Service. Visibility is an optional persistence optimization; Fallback is the composition-owned object scan used when that optimization is unavailable.

type Scope

type Scope struct {
	Organization string `db:"organization"`
	ProjectID    string `db:"project_id"`
	CredentialID string `db:"credential_id"`
	Bucket       string `db:"bucket"`
	PathPrefix   string `db:"path_prefix"`
}

Scope maps a Gen3 organization/project resource to a bucket credential.

type ScopeStore

type ScopeStore interface {
	CreateBucketScope(ctx context.Context, scope *Scope) error
	DeleteBucketScope(ctx context.Context, organization, projectID, credentialID, pathPrefix string) error
	GetBucketScope(ctx context.Context, organization, projectID string) (*Scope, error)
	ListBucketScopes(ctx context.Context) ([]Scope, error)
}

ScopeStore owns bucket-scope lifecycle and lookup.

type Service

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

Service owns bucket credential and scope policy, including cache invalidation. Repository adapters remain responsible for SQL, encryption, auditing, and transaction semantics.

func NewService

func NewService(deps Dependencies, invalidator cacheInvalidator) (*Service, error)

NewService validates and constructs the bucket service with its production scope-cache lifetime. A nil invalidator is a supported no-op configuration.

func (*Service) CreateBucketScope

func (s *Service) CreateBucketScope(ctx context.Context, scope *Scope) error

CreateBucketScope persists a scope and only then seeds the positive cache.

func (*Service) DeleteBucketScope

func (s *Service) DeleteBucketScope(ctx context.Context, organization, projectID, credentialID, pathPrefix string) error

DeleteBucketScope deletes the requested scope, clears cached scope answers, and preserves the existing last-scope credential cleanup policy.

func (*Service) DeleteS3Credential

func (s *Service) DeleteS3Credential(ctx context.Context, bucket string) error

DeleteS3Credential resolves aliases before mutation, then invalidates all known aliases only after the repository confirms deletion.

func (*Service) GetS3Credential

func (s *Service) GetS3Credential(ctx context.Context, bucket string) (*Credential, error)

GetS3Credential resolves a credential by its canonical ID or legacy physical bucket alias according to the repository compatibility contract.

func (*Service) ListBucketScopes

func (s *Service) ListBucketScopes(ctx context.Context) ([]Scope, error)

ListBucketScopes delegates scope enumeration without changing repository order or adapter-owned normalization.

func (*Service) ListS3Credentials

func (s *Service) ListS3Credentials(ctx context.Context) ([]Credential, error)

ListS3Credentials returns configured credentials in repository order. The first returned credential remains the default bucket selection.

func (*Service) ListVisibleBuckets

func (s *Service) ListVisibleBuckets(ctx context.Context) (map[string]VisibleBucket, error)

ListVisibleBuckets assembles configured credentials, explicit scopes, and object-derived rows. The optional query wins; the fallback is used only when that optimization is absent.

func (*Service) LookupBucketScope

func (s *Service) LookupBucketScope(ctx context.Context, organization, project string) (Scope, bool, error)

LookupBucketScope returns a normalized scope and caches both hits and not-found misses. Other backend errors are never cached.

func (*Service) ResolveBucket

func (s *Service) ResolveBucket(ctx context.Context, bucketName string) (string, error)

func (*Service) SaveS3Credential

func (s *Service) SaveS3Credential(ctx context.Context, cred *Credential) error

SaveS3Credential persists a credential before invalidating every identity alias that could key a provider signer.

type VisibilityFallback

type VisibilityFallback func(context.Context) ([]VisibilityRow, error)

VisibilityFallback supplies the object-derived visibility projection when a persistence adapter does not provide VisibilityQuery. The composition layer owns object scanning and read-policy filtering before returning these rows.

type VisibilityQuery

type VisibilityQuery interface {
	ListBucketVisibilityRows(ctx context.Context, resources []string, includeUnscoped, restrictToResources bool) ([]VisibilityRow, error)
}

VisibilityQuery is an optional object-projection optimization for bucket visibility. The bucket service supplies the object-scan fallback.

type VisibilityRow

type VisibilityRow struct {
	AccessURL  string
	AccessType string
	Resource   string
}

VisibilityRow is the minimum storage projection needed to build bucket visibility responses without hydrating full objects.

type VisibleBucket

type VisibleBucket struct {
	Credential Credential
	Programs   []string
}

VisibleBucket is the credential and resource projection exposed to callers that need to authorize access to a physical bucket.

Jump to

Keyboard shortcuts

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