Hosting Modes

Blob Management has not been released yet; see the overview.

The modules that store through Blob Management reference only the provider package and, for files kept by id, Dignite.Abp.BlobManagement.Application.Contracts, so where it runs is decided by the hosts alone. There are two ways, and one Blob Management per deployment environment: never two hosts each installing it behind one gateway.

In the Application's Process

One host installs Blob Management (Setting Up) and the modules that use it. The provider and the file service call it directly, as a trusted caller: no grant, no tokens.

  • Install Dignite.Abp.BlobManagement.Application, Dignite.Abp.BlobManagement.HttpApi (for public reads, the browser's uploads with a ticket and reads with a link, and the APIs the management page calls) and the database provider; call ConfigureBlobManagement() in the migrations DbContext.
  • Leave AbpBlobStoringBlobManagementOptions.PublicBaseUrl empty: public addresses, upload addresses and read links are relative to the host.
  • Leave ABP's integration services hidden, as they are by default. The BLOB API and the file API (/integration-api/blob-management/*) are integration services: in this mode the provider and the file service call Blob Management in process, and nothing reaches it over them.
  • Upload tickets and read links are signed with the host's Data Protection key ring, which an ABP host already persists for its cookies when it runs more than one instance.

This is the simplest mode, and the one to start with.

Blob Management as Its Own Service

One service installs Blob Management; the applications install the provider and Dignite.Abp.BlobManagement.HttpApi.Client (A Remote Blob Management), whose proxies serve both the provider and the file service. Its containers are declared in code, in the service's host module, beside the storage provider they keep their bytes with (Managed Containers).

A business system joins in three steps: the authorization server registers its OAuth client; Blob Management declares the containers it uses and is deployed; the host's administrator grants the client those containers' files (Granting an Application).

What this mode needs:

  • Integration services exposed. The BLOB API and the file API are ABP integration services, hidden unless the host says otherwise: the service's host sets AbpAspNetCoreMvcOptions.ExposeIntegrationServices = true. They are for the applications' back ends - each call is still authorized as an OAuth client granted the container - and are not audit-logged unless the host sets AbpAuditingOptions.IsEnabledForIntegrationServices.
  • One authorization server. The applications get client-credentials tokens from it, and Blob Management validates them (the service is an API resource of it). Each application is an OAuth client, granted the files of the containers it uses. The token reaches every tenant - the proxies name the tenant of each call - so it never leaves the application's back end.
  • Tenants. The proxies send the tenant with each call; the service must resolve it (ABP's header and query-string resolvers do, by default) and know the same tenants - in an ABP microservice solution, from the shared tenant management data. Behind a gateway, the gateway passes the tenant header on. The browser's uploads and reads name no tenant: their ticket or link does.
  • Routes. The gateway routes two prefixes to the service for browsers: /api/blob-management/* - the container, directory, usage and file-reading APIs of the management page, the uploads with a ticket and the reads with a link - and /blobs/*, the public reads. The applications' back ends reach /integration-api/blob-management/* - the BLOB and file APIs - at the service itself or through a route for back ends only; a gateway that browsers reach does not route that prefix.
  • The public address. Set AbpBlobStoringBlobManagementOptions.PublicBaseUrl in the applications to the service's (or the gateway's) public address, so the addresses they build for browsers reach it. A file's url, a ticket's uploadUrl and a link's url are relative to that address as well: the application puts it in front before it hands them to a browser.
  • Data Protection. See below.
  • CORS. A browser uploads to the service from the business system's pages, a cross-origin POST with a body: the service's CORS policy allows those origins (App:CorsOrigins in an ABP host) on /api/blob-management/uploads/*. Reads with a link and public reads are plain GETs an <img> or a link makes, and need no CORS unless a script fetches them.
  • A CDN in front of /blobs. Public reads are Cache-Control: public for a day, with an ETag. The cache key must include the tenant (__tenant) and the size (width, height) from the query string - a key without them serves one tenant's file, or one size, for another - and is best limited to those three, so other parameters added to an address do not split the cache or reach the host past it. Reads with a link are private and not for a shared cache.
  • Several instances. A shared distributed cache, as for any ABP service - read links are kept in it, so that one file gets one link per window whichever instance issued it - and a shared distributed lock provider. The lock serves saving under a name - two saves under one name take turns on it - and the cleanup of pending files, which one instance runs at a time. ABP's default lock only covers one process.
  • Permission data. An application's grant on a container, like every other of Blob Management's permissions, is stored by ABP's Permission Management, in the tables the other services share: the service reads it. To grant a client in the resource permission dialog - choose Application, find the client, tick Files - the host the dialog runs against installs Volo.Abp.PermissionManagement.Domain.OpenIddict next to the OpenIddict domain; without them, grant it with SetForClientAsync in a data seed (Granting an Application).

The management page, the usage and the directories add what any ABP service with users needs:

  • User tokens from the same authorization server.
  • User names, if the usage by user should show them: ABP's IExternalUserLookupServiceProvider, such as the Identity module's HTTP client (Usage).
  • The UI's address. An Angular application points apis.BlobManagement at the service or the gateway (Angular UI).

Rate Limits

In either mode, the anonymous addresses - public reads, uploads with a ticket, reads with a link - name ASP.NET Core rate limiting policies, which Blob Management registers. They act where the host runs the limiter after routing:

app.UseRouting();
app.UseRateLimiter();

A client past a limit is answered 429 with Retry-After. The limits are per client address and minute, each address its own, in BlobManagementRateLimitingOptions; 0 sets no limit:

Option Counts Default
RenditionsPerMinute Public reads that ask for a size, rendered on the request 120
PublicReadsPerMinute Public reads as stored No limit
UploadsPerMinute Uploads with a ticket 60
ReadLinksPerMinute Reads with a link No limit
Configure<BlobManagementRateLimitingOptions>(options =>
{
    options.RenditionsPerMinute = 300;
});

Behind a reverse proxy or a CDN, configure ASP.NET Core's forwarded headers so that the client's address is the one counted; otherwise the proxy's is, and everyone behind it shares one limit.

Data Protection

Upload tickets and read links are signed and encrypted with ASP.NET Core Data Protection, and only Blob Management reads them: a business system asks for one and hands it on, and never holds the keys.

  • Persist the key ring. By default it is kept in memory or the user profile and changes with each deployment, which turns every ticket and link handed out into a 403.
  • Share it among Blob Management's instances only, with one application name: a ticket one instance signs is read by whichever instance the browser reaches. Do not share it with the business systems: whoever holds the keys can write tickets.
context.Services.AddDataProtection()
    .SetApplicationName("BlobManagement")
    .PersistKeysToStackExchangeRedis(redis, "BlobManagement-Protection-Keys");

When Blob Management is installed in the application's own process, it shares that host's key ring, which the host persists for its own cookies anyway.

See Also