Cloud Storage for User Uploads: Signed Document Access Boundaries and Deletion Deadlines
Cloud Storage for User Uploads: Signed Document Access Boundaries and Deletion Deadlines For user uploads, comparing Azure Blob Storage, Google Cloud Storage, and Amazon S3 is useful only after a fintech system states
Cloud Storage for User Uploads: Signed Document Access Boundaries and Deletion Deadlines
For user uploads, comparing Azure Blob Storage, Google Cloud Storage, and Amazon S3 is useful only after a fintech system states the boundary it must enforce. For signed documents with an explicit deletion deadline, the durable record is a retention decision: who may retrieve the object, under which authorization, and when the system must make retrieval impossible. Direct client uploads are acceptable only when the service signs a narrowly scoped request and records the same decision in an audit trail.
This is the decision rule I use for the storage comparison: keep authorization and retention state in the application-owned ledger, keep bytes in object storage, and treat a provider-issued signed URL as a delivery capability rather than as proof of entitlement. The design tolerates retries, makes reconciliation possible, and leaves the provider-specific URL mechanism behind one interface.
The boundary comes first.
Auditability wins.
What must remain true after a retry or a deadline?
The workflow has four invariants. A document has one immutable object identity, one tenant and case association, one retention deadline, and a state transition that can be explained later. An upload retry must not create a second logical document. A download retry must not extend authorization. A deletion retry must be safe after the object has already disappeared.
Those statements sound operational until a signed contract is involved. Then the failure boundaries matter. The database can commit metadata while an upload is still in flight; an object can be present while its metadata row is missing; a client can retain a URL after its intended lifetime; and a lifecycle rule can remove bytes without producing the business audit event required by the compliance process. Object storage supplies useful primitives, but it does not know that a particular PDF is the document that settled a particular payment.
I therefore separate three clocks:
- The authorization clock controls how long a user may obtain a delivery URL.
- The retention clock controls the deletion deadline recorded for the document.
- The reconciliation clock controls how quickly an operator investigates a mismatch between metadata and bytes.
The first clock may be minutes. The second may be years or a precisely stated business deadline. The third is an operational service-level objective. Confusing them is a common source of accidental retention: a long-lived object lifecycle policy is mistaken for a legal retention decision, or a short-lived URL is treated as if it revoked every previously issued copy. Once bytes have been delivered, a storage service cannot recall a downloaded file.
How should cloud storage handle user uploads and signed document delivery?
The three major object-storage families can all support this pattern, but their request-signing and policy vocabulary differ. The comparison below is deliberately narrow; it is about the boundary between an application authorization decision and a client delivery request, not a ranking of providers.
| Service family | Delivery mechanism to isolate | Useful engineering boundary | Important limitation |
|---|---|---|---|
| Amazon S3 | Presigned URL | A URL can authorize a specific object operation for a bounded period; the application can keep the bucket private and issue it after an authorization check. | The URL is a bearer capability. It does not replace application authorization, and a downloaded copy cannot be revoked. |
| Azure Blob Storage | Shared access signature (SAS) | A SAS can constrain resource scope, permissions, and validity for a client-facing transfer. | The token is also a bearer capability; its delegation policy and revocation model must be designed explicitly. |
| Google Cloud Storage | Signed URL | A signed request can provide time-bounded access to a named object without exposing broad bucket credentials to the client. | The URL is a bearer capability, and the application still owns the document-to-user authorization decision. |
This leaves a real choice. Provider-native direct delivery is operationally simple and usually reduces proxy bandwidth, while an application proxy gives the service more direct control over response headers, authorization checks, and emergency blocking. Neither choice changes the retention invariant.
For a small document, a proxy may be the clearer boundary because the service can check status immediately before streaming. For large uploads, a direct transfer with a one-object, one-operation capability may be the better delivery path. The decision should be driven by the sensitivity of the content, expected object size, network topology, and the strength of the audit requirement. βThe browser has a URLβ is not an authorization model.
The critical path is a state machine, not a URL generator
The application should create the logical document before it asks a client to upload, then accept the object only if its identity and checksum match the record. The following Go sketch shows the important ordering without binding the design to a commercial SDK. The interfaces are intentionally small: an adapter can implement them for S3, Blob Storage, or Cloud Storage while the business service remains testable. That separation is more than a portability exercise; it lets the test suite force a timeout, duplicate callback, mismatched digest, or deletion race without pretending that a provider request has exactly-once semantics.
package retention
import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"time"
)
type Document struct {
ID string
TenantID string
ObjectKey string
Digest string
DeleteAt time.Time
State string
}
type Repository interface {
CreatePending(ctx context.Context, d Document) error
MarkUploaded(ctx context.Context, id, digest string, size int64) error
MarkDeleteRequested(ctx context.Context, id string) error
}
type ObjectStore interface {
IssueUpload(ctx context.Context, key string, expires time.Duration) (string, error)
Head(ctx context.Context, key string) (size int64, digest string, err error)
Delete(ctx context.Context, key string) error
}
func PrepareUpload(ctx context.Context, repo Repository, store ObjectStore, d Document) (string, error) {
if d.ID == "" || d.ObjectKey == "" || d.DeleteAt.IsZero() {
return "", errors.New("incomplete document identity")
}
if err := repo.CreatePending(ctx, d); err != nil {
return "", err
}
return store.IssueUpload(ctx, d.ObjectKey, 10*time.Minute)
}
func ConfirmUpload(ctx context.Context, repo Repository, store ObjectStore, d Document, body []byte) error {
sum := sha256.Sum256(body)
want := hex.EncodeToString(sum[:])
if want != d.Digest {
return errors.New("content digest mismatch")
}
size, got, err := store.Head(ctx, d.ObjectKey)
if err != nil {
return err
}
if got != d.Digest || size != int64(len(body)) {
return errors.New("stored object does not match document")
}
return repo.MarkUploaded(ctx, d.ID, got, size)
}
The example keeps the business state transition in the repository and makes the object check explicit. In production, the digest should be computed from the exact bytes being transferred, and the upload confirmation should be idempotent: repeating a successful confirmation must return the same logical result, not append another document event. A real implementation also avoids holding a full document in memory; the sketch is a compact illustration of the ordering, not a streaming upload implementation.
The deletion worker follows the same discipline. It selects records whose deadline has passed, records a delete intent with an idempotency key, requests object deletion, and then verifies the outcome with a bounded retry policy. A βnot foundβ result is normally a successful terminal state for deletion, but the audit record must distinguish βdeletedβ from βnever observedβ so reconciliation can investigate an earlier metadata mismatch.
Exactly-once execution is not a property to assume from a queue or a cron job. It is a business result assembled from an idempotency key, durable state transitions, and reconciliation. The worker may execute twice; the document deletion decision must still be represented once.
What breaks when access control is delegated to delivery?
The rejected option is to put a long-lived public object URL in a database and rely on the storage platformβs lifecycle policy to delete the object later. It is attractive because there are few moving pieces. It also collapses two different questions: βmay this principal read the document now?β and βhas the retention deadline passed?β
That option is valid for genuinely public, non-sensitive assets where revocation and per-user authorization do not matter. It is a poor fit for signed financial documents. A lifecycle policy is a useful backstop, but the application still needs a deadline in authoritative metadata, a deletion event, and a way to find objects that violate the expected state. Compliance requirements also vary by jurisdiction and record type; a retention field is not legal advice, and the system should not encode a universal period merely because a storage policy accepts one.
The simpler direct-delivery option has a different failure mode: a client receives a valid capability, then the userβs account is disabled or the document is placed under legal hold. A short expiry limits exposure, but it does not perform immediate revocation for a URL already issued. If immediate blocking is material, route retrieval through an authorization-aware service or maintain a revocation control that is checked before every delivery. That adds latency and operational work. It is the price of the stronger boundary.
How do I test and operate the deadline?
Test the state machine with provider adapters replaced by a fake store, then run a smaller set of contract tests against each selected service. The important cases are repetitive and unglamorous: the upload callback arrives twice; the object has the wrong checksum; the database commit succeeds while the signed-request call fails; deletion is retried after a timeout; a deadline is exactly equal to the workerβs current time; and a previously issued URL is used after the application has denied access. Time must be injectable so a test can place an object precisely on either side of the deadline.
Observe counts and states, not just HTTP failures. Useful signals include pending documents older than the upload window, objects without matching metadata, deletion intents past their retry budget, and successful URL issuance for documents already expired or blocked. Include tenant and document identifiers in structured audit fields only when the logging policy permits it; never turn the document body or a signed capability into a log message.
The deployment procedure should version bucket/container policy separately from application code, review changes as security-sensitive, and make a rollback unable to extend expired retention accidentally. A policy change that broadens read access deserves the same review as an authorization code change. Periodic inventory is essential because object stores and relational databases fail independently, and a clean application metric cannot prove that no orphaned bytes exist.
The final architecture is therefore intentionally unexciting: private objects, application-owned document state, narrowly scoped delivery capabilities, explicit deadlines, idempotent workers, and an audit trail that records decisions rather than only HTTP responses. The storage service affects adapter details and delivery ergonomics. It does not own the business meaning of a signed document.
References
- AWS, βAmazon S3 presigned URLsβ: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- Microsoft Learn, βGrant limited access to Azure Storage resources using shared access signatures (SAS)β: https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview
- Google Cloud, βSigned URLsβ: https://cloud.google.com/storage/docs/access-control/signed-urls
- NIST, βDigital Identity Guidelines: Authentication and Lifecycle Management (SP 800-63B)β: https://pages.nist.gov/800-63-3/sp800-63b.html
- OWASP, βLogging Cheat Sheetβ: https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.