Stop Exposing Files: Private Buckets, Internal Rendering and Temporary URLs with MinIO and Laravel 12

A public bucket works until a link lands in a WhatsApp chat. How to keep MinIO/S3 private in Laravel with per-folder permissions, internal rendering and short-lived signed URLs, and what a bad first decision cost us.

Stop Exposing Files: Private Buckets, Internal Rendering and Temporary URLs with MinIO and Laravel 12
Photo by Barnabas Piper / Unsplash

Someone asks your system to store payment receipts or customers' ID documents. You spin up a MinIO server (self-hosted is cheaper than AWS) and take the fastest decision on the table: "let's start with a public policy and sort it out later." After all, if the file name carries a 40-character hash, nobody is going to find it, right?

Weeks later, with the web app at peak traffic, you see the mistake. Links travel. A user sends one to their accountant over WhatsApp, and that URL ends up cached, stored in places you don't control, and exposing confidential data to anyone who gets hold of it.

Refactoring and migrating file handling in the middle of peak usage was a bad idea. The poor planning cost us about two weeks of rework and, worse, it affected some of the platform's clients. Something that could have been right from day one turned into a nightmare. If the bucket is public from the start, you have already lost control.

This article covers how to keep a single bucket private in Laravel 12 and hand out access on purpose. It doesn't cover MinIO installation or backups.

One closed bucket, folders with rules

The instinct is to create a bucket for every kind of file. Don't. A single closed bucket, with permissions managed per directory, is easier to reason about.

Keep a public folder for things the whole world can see: profile pictures, the app logo you reuse in emails. Keep a private folder strictly for sensitive documents. Anything that lands in the private zone is blocked by default.

Before any of that works, Laravel has to be able to talk to MinIO.

Connecting Laravel to MinIO

MinIO speaks the same language as AWS S3, so in Laravel you only need to configure the s3 disk, and the .env file is enough for that:

AWS_ACCESS_KEY_ID=your_minio_user
AWS_SECRET_ACCESS_KEY=your_secret_password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=private-documents
AWS_ENDPOINT=https://minio.example.com
AWS_USE_PATH_STYLE_ENDPOINT=true

The line that matters is AWS_USE_PATH_STYLE_ENDPOINT=true. Without it, Laravel looks for the bucket as a subdomain (private-documents.minio.example.com), which is almost never set up on a self-hosted install, instead of using the path-style address.

With the disk working, the next question is how a legitimate user gets a private file if there is no public URL to open.

Rendering internally: keep your storage out of sight

For private documents, the rule is simple: the user should never see the real address of your MinIO or S3.

Instead of handing out a direct link to the storage, send the request through a Laravel controller that does an "internal render". Laravel goes to the bucket, fetches the file and serves it as a plain HTTP response, but only if the user has the right permissions.

public function descargarComprobante(Comprobante $comprobante)
{
    // 1. Check that this user can access this document
    if ($comprobante->user_id !== auth()->id()) {
        abort(403, 'Access denied');
    }

    // 2. Return the file directly, without exposing the real path
    return Storage::disk('s3')->response($comprobante->ruta_archivo);
}

What the customer sees in the browser is a route of your own application. The MinIO server stays invisible, isolated behind your backend.

Sometimes, though, a route that needs a logged-in session is not an option.

Temporary URLs: short-lived and configurable

There are cases where you do need a direct link: a third-party service that has to download a report, or an email attachment where there is no active session. For those, use temporary signed URLs. In S3 terms, a presigned URL.

The trick is to avoid hardcoding the lifetime. Make it configurable and, above all, short. In your services config file, add:

'minio' => [
    'token_ttl' => env('MINIO_TOKEN_TTL', 5), // 5 minutes by default is more than enough
],

And when you sign the asset:

use Illuminate\Support\Facades\Storage;

$minutes = config('services.minio.token_ttl');
$url = Storage::disk('s3')->temporaryUrl(
    $path, now()->addMinutes($minutes)
);

That final string carries a token and a cryptographic signature. If someone edits the expiry time in the address bar, or tries to guess the name of another file, the signature breaks and MinIO rejects the request. Open the same link after it expires and you get an AccessDenied error.

What it costs

Internal rendering has a price. Every download now streams through your Laravel app, so it uses your server's bandwidth and a PHP worker for as long as the transfer lasts. For large files, a temporary URL lets the client talk to MinIO directly and keeps your app out of the way. Which one fits depends on file size and on whether the person asking has a session.

Self-hosting MinIO has its own bill. You don't pay per request or for outbound bandwidth at AWS prices, but you do own the maintenance: updating the server, managing the underlying disks and running the backups.

And there is one trap specific to temporary URLs: they depend on the clock. If the Laravel server and the MinIO server disagree on the time (an NTP failure, for example), signatures can be born already expired or get rejected. If links start failing for no visible reason, compare the clocks first.

Peace of mind in production

Setting up a private bucket and managing access through internal rendering or short-lived links takes a couple of extra steps at the start of the project. In exchange, your critical files stop being one WhatsApp message away from becoming the company's next data leak.