proxy

package
v2.17.9 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package proxy implements a storage proxy that provides presigned URL generation

Index

Constants

View Source
const (
	// DefaultPresignDuration is the default duration for presigned URLs
	DefaultPresignDurationMinutes = 15
	// SecretDivisor is used to split the secret into nonce and key components
	SecretDivisor = 2
)
View Source
const (
	// DownloadAudience is the audience claim carried by every share-verified token; it must differ from the
	// session audience so a share-verified token is never accepted as a session and vice versa
	DownloadAudience = "openlane-files"
	// ShareVerifiedTokenType is the typ claim carried by the token proving a recipient verified their email for a share
	ShareVerifiedTokenType = "share-verified"
	// ShareVerifiedDuration is the lifetime of a share-verified token
	ShareVerifiedDuration = 15 * time.Minute
	// MaxShareDuration is the longest lifetime a share may be created with
	MaxShareDuration = 30 * 24 * time.Hour
	// MaxShareFiles is the most files a share link may grant
	MaxShareFiles = 20
	// UnlimitedShareUses is the max uses value that places no cap on downloads through a share link
	UnlimitedShareUses = 0

	// ClaimType is the claim naming the token type
	ClaimType = "typ"
	// ClaimShareID is the claim naming the share link a share-verified token belongs to
	ClaimShareID = "sid"
	// ClaimRecipient is the claim carrying the sha256 hex of the normalized recipient email
	ClaimRecipient = "rcp"
)

Variables

View Source
var (
	// ErrMissingFileID indicates that the file ID is missing
	ErrMissingFileID = errors.New("missing file id")
	// ErrMissingObjectURI indicates that the file metadata is missing the object URI
	ErrMissingObjectURI = errors.New("file metadata missing object URI")
	// ErrInvalidSecretLength indicates that the secret must be 128 bytes when provided
	ErrInvalidSecretLength = errors.New("secret must be 128 bytes when provided")
	// ErrCallerRequired indicates that a caller is required in the context.
	ErrCallerRequired = errors.New("caller required in context")
	// ErrShareVerifiedTokenInvalid indicates the share-verified token failed signature, issuer, audience, or expiry validation
	ErrShareVerifiedTokenInvalid = errors.New("invalid share verified token")
	// ErrShareVerifiedTokenType indicates the token is not a share-verified token
	ErrShareVerifiedTokenType = errors.New("share verified token type mismatch")
)
View Source
var (
	// ErrTokenManagerRequired indicates proxy signing is impossible without a token manager.
	ErrTokenManagerRequired = errors.New("proxy presign requires token manager")
	// ErrEntClientRequired indicates storing secrets requires an ent client.
	ErrEntClientRequired = errors.New("storing secrets requires ent client")
)

Functions

func ComposeShareToken

func ComposeShareToken(orgID, signature string) string

ComposeShareToken builds the share token carried by the share URL from the owning organization id and the signature

func ComposeShareURL

func ComposeShareURL(baseURL, shareID, tokenString string) string

ComposeShareURL builds the share URL under the storage links base URL carrying the share token

func GenerateDownloadURL

func GenerateDownloadURL(ctx context.Context, file *storagetypes.File, duration time.Duration, cfg *storage.ProxyPresignConfig) (string, error)

GenerateDownloadURL builds a proxy download URL and persists the signing secret for validation.

func GenerateDownloadURLWithSecret

func GenerateDownloadURLWithSecret(file *storagetypes.File, secret []byte, duration time.Duration, cfg *storage.ProxyPresignConfig) (string, error)

GenerateDownloadURLWithSecret builds a proxy download URL using the provided secret for testing.

func NewShareVerifiedToken

func NewShareVerifiedToken(tm *tokens.TokenManager, issuer, shareID, recipientHash string) (string, error)

NewShareVerifiedToken mints the token proving the recipient of a share verified their email

func NormalizeRecipientEmail

func NormalizeRecipientEmail(email string) string

NormalizeRecipientEmail returns the trimmed, lowercased form of a recipient email

func RecipientHash

func RecipientHash(email string) string

RecipientHash returns the sha256 hex of the normalized recipient email

func ShouldBypassPresignInterceptor

func ShouldBypassPresignInterceptor(ctx context.Context) bool

ShouldBypassPresignInterceptor reports whether presign interceptors should be skipped.

func SplitShareToken

func SplitShareToken(token string) (string, string, bool)

SplitShareToken returns the organization id and the signature carried by a share token

func VerifyShareVerifiedToken

func VerifyShareVerifiedToken(tm *tokens.TokenManager, issuer, tokenString string) (string, string, error)

VerifyShareVerifiedToken checks the signature, issuer, audience, expiry, and type of a share-verified token and returns its share id and recipient hash

func WithPresignInterceptorBypass

func WithPresignInterceptorBypass(ctx context.Context) context.Context

WithPresignInterceptorBypass marks the context so downstream Ent interceptors skip presign handling.

Types

This section is empty.

Jump to

Keyboard shortcuts

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