Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 9 min read

Object Storage Service for Tenant Images: Pre-Signed URLs and Export Boundaries

Tenant-Bound Blob Handoffs: Authorization Boundaries for Image Intake and Exports The operational constraint changes the design: a browser should move bytes directly to object storage, but it should never decide which

Tenant-Bound Blob Handoffs: Authorization Boundaries for Image Intake and Exports

The operational constraint changes the design: a browser should move bytes directly to object storage, but it should never decide which tenant owns those bytes or which files belong in an export. The practical answer is a short-lived, single-purpose signed URL issued by an authorization service, with the object key, method, content constraints, and tenant already fixed. Downloads follow the same rule. The client receives permission to perform one bounded transfer, not a reusable storage credential.

For a developer-tools product storing product images, that boundary matters more than the name of the storage service. A successful upload is not proof of ownership, and a successful download is not proof that the caller should see the object. Put those decisions in the service that knows the authenticated user and tenant. Let object storage handle the bytes.

How should an object storage service use pre-signed URLs?

A signed URL is a bearer capability. Anyone who obtains it can generally use it until it expires, within the restrictions the storage system checks. That makes it useful for browser transfers and dangerous to treat as an identity token.

The issuer should first authorize an application action, then sign a request whose scope matches that action. For an avatar or product image, the scope normally includes a tenant-owned key, one HTTP method, a short expiration, and an expected content type or size policy. The upload endpoint should not accept an arbitrary key supplied by the browser. The download endpoint should not sign a key merely because it exists.

The object name is part of the authorization decision. A layout such as tenants/{tenantID}/images/{imageID} gives operators a recognizable boundary, but the prefix itself is not an access-control policy. Storage permissions, application authorization, and export membership still need to agree.

The sequence is deliberately boring.

That is a feature.

The sequence is:

  1. The client asks the application for an upload capability, sending metadata such as an image ID and media type.
  2. The application authenticates the caller, checks tenant membership, creates or reserves the object identity, and asks a signer for a constrained upload URL.
  3. The client uploads bytes directly to storage.
  4. The application verifies the resulting object before marking the image ready.
  5. A later export job selects ready images from tenant-owned records, then issues download capabilities only for that export.

The last two steps are where many implementations become optimistic. A 200 from the storage upload is transport evidence. It is not a complete business invariant. Record state, object metadata, size, checksum policy, and malware or image validation may still need to be checked before the image appears in a tenant export.

Why did direct delivery fail in my runbook?

I have been paged by missed jobs and duplicate deliveries. That history makes me suspicious of workflows that describe a transfer as one atomic event when it is really several events separated by retries, timeouts, and queues.

I initially treated a signed URL as the upload operation. Later, the retry path made the distinction unavoidable: it is only a temporary permission to attempt a transfer.

The signed URL does not remove that uncertainty. A browser can upload successfully and lose the response. A worker can retry an export task after the first attempt has already created its manifest. A client can submit the same completion notification twice. If the system treats each notification as a new command, the export can contain duplicates or the image can move backward from ready to pending.

I start with an idempotency key tied to an application operation, not to the signed URL. The URL is disposable and may be regenerated. The operation record is durable and has a state transition rule. For an image upload, tenantID + imageID + uploadAttempt is more useful than a URL string; for an export, an export ID and a stable member ID make retries addressable.

Here is the shape of the guard I want around a completion callback. It uses a generic storage interface so the authorization and state rules remain visible instead of disappearing into a provider SDK.

package media

import (
    "context"
    "errors"
    "fmt"
    "net/url"
    "time"
)

var ErrAlreadyFinal = errors.New("upload is already final")

type Upload struct {
    TenantID  string
    ImageID   string
    ObjectKey string
    State     string
    ExpiresAt time.Time
}

type Store interface {
    FindUpload(ctx context.Context, tenantID, imageID string) (Upload, error)
    MarkReady(ctx context.Context, tenantID, imageID string) error
}

type Signer interface {
    PutURL(ctx context.Context, objectKey, contentType string, expires time.Duration) (string, error)
}

func IssueUploadURL(ctx context.Context, store Store, signer Signer,
    tenantID, imageID, contentType string) (string, error) {
    upload, err := store.FindUpload(ctx, tenantID, imageID)
    if err != nil {
        return "", err
    }
    if upload.State == "ready" {
        return "", ErrAlreadyFinal
    }
    if upload.TenantID != tenantID || upload.ObjectKey == "" {
        return "", errors.New("upload is outside tenant scope")
    }
    return signer.PutURL(ctx, upload.ObjectKey, contentType, 10*time.Minute)
}

func CompleteUpload(ctx context.Context, store Store, tenantID, imageID string) error {
    upload, err := store.FindUpload(ctx, tenantID, imageID)
    if err != nil {
        return err
    }
    if upload.State == "ready" {
        return nil // A repeated callback is an acknowledged no-op.
    }
    if upload.TenantID != tenantID || upload.ObjectKey == "" {
        return errors.New("upload is outside tenant scope")
    }
    if upload.ExpiresAt.Before(time.Now()) {
        return errors.New("upload attempt expired")
    }
    if _, err := url.Parse(upload.ObjectKey); err != nil {
        return fmt.Errorf("invalid object key: %w", err)
    }
    return store.MarkReady(ctx, tenantID, imageID)
}

The example leaves verification behind the Store boundary on purpose. A production implementation should check the object through the storage API and enforce the product's size, media, checksum, and content-validation rules before MarkReady. It should also make the state update conditional on the expected prior state, so two workers cannot both claim the same transition.

The URL duration is a policy choice, not a security guarantee. A longer lifetime helps a slow transfer; it also extends the period in which a leaked bearer capability works. The right value follows from expected object size, network conditions, and the ability to revoke or invalidate the application operation. Expiration cannot undo a URL that has already been used to copy an object.

There is a real trade-off here: direct delivery reduces application bandwidth and simplifies horizontal scaling, while a proxy gives the application more immediate inspection and revocation control. Neither choice is free.

Which storage differences affect the boundary?

The underlying systems expose similar-looking concepts under different names and constraints. Amazon S3 documents presigned URLs as time-limited access to upload or download an object. Google Cloud Storage calls its mechanism signed URLs and documents signed requests for specific resources. Azure Blob Storage uses a shared access signature, with permissions and expiry carried in the token. Those are useful differences to record in an evaluation, but none of them moves tenant authorization into the browser.

Capability boundary S3 presigned URL Cloud Storage signed URL Azure Blob SAS
Permission model Signed request parameters and method Signed request parameters and method Explicit SAS permissions and expiry
Main design concern Credential used to sign and request scope Signing version, headers, and resource scope SAS delegation scope, permissions, and revocation strategy
Application invariant Tenant authorization remains outside the URL Tenant authorization remains outside the URL Tenant authorization remains outside the token

This is not a ranking. The table is a reminder to compare the boundary that the application owns with the boundary the storage API enforces. A team can make a correct design with any of these families, and can make an unsafe design with any of them by signing a caller-provided path or issuing a token before checking tenant membership.

The limitation is important: a signed URL is a poor fit when every byte must be inspected before it reaches durable storage, or when the client cannot be trusted to send directly to the storage endpoint. In those cases, a server-side relay or inspection stage may be the right trade, even though it adds bandwidth, latency, and backpressure work.

The same review applies to a self-hosted S3-compatible service. โ€œCompatibleโ€ describes an interface, not identical behavior across every deployment. Check the signing algorithm, required headers, clock-skew tolerance, multipart behavior, metadata handling, and audit events in the exact storage implementation you will operate. Treat those as testable contract points.

How should tenant-scoped exports behave under retries?

An export is a different authorization event from an upload. It should have a manifest owned by a tenant, a stable export ID, and a defined snapshot or cutoff. Querying โ€œall current imagesโ€ repeatedly while workers run can produce a moving target. Capture the intended members first, then process those members idempotently.

For each manifest entry, store the logical image ID, tenant ID, object key, and processing state. A worker may create a temporary archive object or an individual download handoff, but a retry must address the same manifest entry. If the destination is a tenant-scoped export key, use a conditional create or an equivalent compare-and-set rule. Do not use โ€œthe worker finishedโ€ as the sole duplicate check; workers crash after side effects and before acknowledgements.

The download capability should be issued after the export is authorized and its manifest is ready. Its scope should point at the exact export object, not at a tenant prefix. The application can then record who requested the export and when, while the storage service handles the transfer. Logging a signed URL itself is usually a mistake because logs become another bearer-token surface; record the export ID, object key, tenant ID, and expiry instead.

Observability should make the two halves distinguishable. Count URL issuance, storage transfer failures, completion callbacks, verification failures, export retries, and duplicate acknowledgements separately. Include tenant and operation identifiers in structured logs, with redaction rules for query strings. Alert on an unusual gap between issued upload capabilities and verified objects, and on exports whose retry count crosses a bounded threshold.

There is a boundary to this advice. If the application must transform every byte synchronously, or if policy requires all content to pass through a trusted inspection service before storage, direct browser delivery may not fit. The extra hop can be justified by that control. It should be a deliberate policy decision, with backpressure and retry semantics designed explicitly, rather than an accidental consequence of wanting a simpler authorization story.

A decision rule for the implementation review

Ask four questions before choosing a storage integration:

  • Can the application bind every issued capability to one tenant, one object identity, and one intended method?
  • Can the system verify the stored object before making it visible in an export?
  • Can a retry repeat the operation without creating a second logical image or export member?
  • Can operators investigate issuance, transfer, verification, and delivery without putting bearer tokens in logs?

If any answer is unclear, the missing piece is in the application contract, not in the URL syntax. Signed URLs reduce delivery work. They do not replace authorization, object verification, idempotency, or audit design.

For product images, I would accept a little more bookkeeping in exchange for those explicit boundaries. The browser gets a narrow handoff. The tenant decision stays server-side. Export workers operate on a fixed manifest. That division keeps a transient transfer failure from becoming a data-ownership bug, which is the failure mode an on-call runbook should be built to prevent.

Sources

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.