BccCode.Privacy.Hosting 12.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BccCode.Privacy.Hosting --version 12.0.0
                    
NuGet\Install-Package BccCode.Privacy.Hosting -Version 12.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BccCode.Privacy.Hosting" Version="12.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BccCode.Privacy.Hosting" Version="12.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BccCode.Privacy.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BccCode.Privacy.Hosting --version 12.0.0
                    
#r "nuget: BccCode.Privacy.Hosting, 12.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BccCode.Privacy.Hosting@12.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BccCode.Privacy.Hosting&version=12.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BccCode.Privacy.Hosting&version=12.0.0
                    
Install as a Cake Tool

BccCode.Privacy.Hosting

One call that installs BCC Privacy for an application's DbContext, and checks the application's declarations at start-up. Start-up publishes nothing: publishing to the Privacy API belongs to the deploy. Part of the BCC Privacy package family: it brings the core, EntityFrameworkCore, Jobs, AspNetCore, Wolverine, ChangeHistory and BccCode.Privacy.Client.

builder.Services.AddDbContext<AppDbContext>(o => o.UseNpgsql(connectionString));   // an ordinary DbContext
builder.Services.AddPrivacy<AppDbContext>(o => o.Declare(typeof(ApplicationData).Assembly));
// ...
app.UseAuthentication();
app.UsePrivacy();

AddPrivacy<TContext> is the one registration of privacy for a context. It registers, for the data classes and processes named with Declare(...):

  • the EF layer (AddPrivacyEntityFrameworkCore<TContext>): the privacy columns and tables in the model, the filters by org and process, the derivation on save, IPrivacyContextFactory<TContext>, and the scoped PrivacyContext. The context implements nothing; o.Adapter(a => ...) sets the adapter's options (keep rules);
  • the request's PrivacyContext from the org claim and the endpoint's [PrivacyProcess<T>] (BccCode.Privacy.AspNetCore);
  • the same for messages (BccCode.Privacy.Wolverine), unless o.UseWolverine = false;
  • ChangeHistory's reader scope from the privacy context's orgs (BccCode.Privacy.ChangeHistory). With a context that derives from ChangeHistoryDbContext, another reader scope stops start-up in every environment;
  • the start-up checks below, and the cache of adopted values;
  • the Core group loader (Core groups).

Add the privacy job with AddPrivacyJobs<TContext>() (BccCode.Privacy.Jobs), its endpoint with app.MapPrivacyJobs(), and the subscriber for Privacy's consent events with app.MapPrivacyConsentEvents<TContext>() (a consent is stored once, in privacy.consents).

Declarations: data classes and processes (LIB-23)

The application declares what each entity holds in data classes (PrivacyData<T>, PrivacyChildData<T, TParentData>) and what each process keeps, about whom, why and for how long in process classes (PrivacyProcess, PrivacySubProcess<T>), all in BccCode.Privacy. Hosting reads them from the assemblies or types it is given:

builder.Services.AddPrivacy<AppDbContext>(o => o.Declare(typeof(ApplicationData).Assembly));   // BccPrivacy:AppSlug, e.g. "ateam"

The EF layer, start-up, privacy check and privacy publish all read this one model.

Start-up runs the model checks in every environment: an entity field in no personal data category (PRIVACY001) and the other errors (PRIVACY002 and on) stop start-up with a PrivacyModelException that lists them all; overlaps between processes are logged as information. Keys, navigations, tables and columns come from the context's EF model.

At deploy the application publishes the declarations itself, as jasper codegen is run:

var app = builder.Build();
if (await app.RunPrivacyCommandAsync(args)) return;    // dotnet run -- privacy check | privacy publish
Command What it does
privacy check The model checks, a data controller for every process, and the notices. Prints the overlaps, which process keeps each category longest, and, with a client, will delete process X for each of the application's processes in Privacy it no longer declares. Run it in CI on every pull request
privacy publish [--revision-file f] The checks, then the notices and one process document per process (entities with their tables and fields per category, the app's personal data categories, holdings, sub-processes, bases, grounds and the adoption rule); then deletes what is no longer declared. Prints the revision: set BccPrivacy:AcceptedRevision to it for the build; start-up compares

A process is published for BccPrivacy:DataControllerId, or else for its single AdoptableBy org. Slugs are the processes' names in Privacy; there is no lock file.

Core groups: the one cache of their members

A data-subject group with Core criteria (DataSubjects(name, criteria: (Person p) => new { p.RoleAssignments })) covers the members of the Core groups each org's adoption names for it. Their members are copied into privacy.group_members, the one local cache, which saves and the privacy job read; AddPrivacy registers the built-in loader (IPrivacyCoreGroups):

  • What it reads. The cache of adopted values: for every adoption in force, every data-subject group with criteria of that process (and its sub-processes), and every Core group uid under populations.<group>.groupUids, as Privacy holds it. A Core group adopted by two orgs, two processes or two declared groups has a copy for each, keyed by (org, process, group, Core group): a member covers only the process whose adoption names the Core group. Core groups adopted for a group without criteria are not loaded (see below). A group adopted by a filter (groupFilter) is not loaded and is logged as a warning: Core creates its group and keeps its uid, and the adoption does not carry it.
  • Where from. Core API's member listing through the Core API SDK (ICoreApiClient.Groups, GET /groups/{uid}/members, 1000 per page). Register the client with services.AddBccCoreApiClient(...) and the scope CoreApiScope.GroupsRead (groups#read); start-up needs it only when an adoption names Core groups. Core lists no validity, so a member is in from when the loader first sees them until Core no longer lists them.
  • When. At start-up, after the adopted values are read, the initial load fills each group that has no members here yet. Start-up then goes on; nothing runs in the background. The nightly reconciliation is POST /internal/privacy/jobs/core-groups (app.MapPrivacyJobs()), called by the application's scheduler (Cloud Scheduler). It reads every adopted group and replaces a copy that differs, through db.ReplaceCoreGroupMembersAsync, which derives the rows of the persons concerned again; it also removes the copies of groups no adoption in force names any more. A reconciliation that changed a copy logs a warning with its counts (added, removed, changed; no person uids): the alert that member changes were missed. The job answers the counts; ?onlyMissing=true loads only the groups with no members yet. The loader always asks Core for every member, whatever query options the application sets for its own Core reads.
  • Events: pending on Core (bcc-core-api#642). Core will publish no.bcc.api.group.members_changed (groupUid, added, removed, sequence) on BCC PubSub, applied idempotently on (groupUid, sequence) in between reconciliations, and a member list with a checksum for a cheaper reconciliation. Until then the copy is as fresh as the last reconciliation. The rows are keyed by (group_uid, person_uid, org_uid, process_id, group_name), so a handler applies added and removed by group and person for every copy Adopted() lists; it will also keep the last applied sequence per group.

Adopted values, read from Privacy

Privacy owns adoptions and all their values. Code declares only AdoptableBy(org, ...), published with the process; Privacy adopts the process for that org at publish when it names exactly one, and people set everything else (the data-subject groups' members, the variables such as retention) in Privacy's UI or the portal. There is no adoption in code or configuration, and the libraries never write one.

AddPrivacy registers PrivacyAdoptedValues, the cache of what the application needs at runtime: per org and process, whether the adoption is in force, the groups' members (populations) and the retention cap. It is read from Privacy at start-up (GET /api/adoptions, scope privacy.adoptions#read) and kept current by Privacy's adoption-changed event (PrivacyAdoptionChangedHandler, found by Wolverine). Its age is the health check privacy-adopted-values (degraded past BccPrivacy:AdoptionCacheMaxAge, one day by default).

  • First start. privacy publish runs in the deploy before the application starts, and Privacy auto-adopts at that publish, so the first read finds the adoption. If the read fails, start-up goes on (start-up calls no service it depends on): the health check reports the cache as degraded, the Core group loader changes nothing (no groups are loaded on a first start, so Core-group cover is empty: fail closed), and retention uses the declared periods with no org cap until a read or an event succeeds.
  • Checked as read. Each adoption read or received is checked against the declarations (PrivacyAdoptionCheck) and every problem is logged as a warning: a group the process does not declare, Core groups or a filter for a group without criteria (Core-group adoption requires criteria), a filter that reads a field outside the criteria. They are warnings, not errors, because Privacy owns the values and the application cannot fix them; they cover no one.

Login: the processes and the org (B-6, c10)

A process declares who may adopt it with AdoptableBy(org, ...); none means only the data controller. With AdoptOnFirstUse() an org adopts it when it first uses it; otherwise Privacy adopts it (see above). The login request (WithPrivacyLogin, RequestConsentAtLogin<TProcess>()) is in BccCode.Privacy.AspNetCore.

Notices, in code

The data controller's privacy notice is declared in code; configuration cannot declare it. Data categories are not declared here: they are PersonalDataCategory constants, published with the processes.

builder.Services.AddPrivacy<AppDbContext>(o => o
    .Notice("privacy-policy", new() { Name = "Privacy policy", Url = "https://example.org/privacy",
        Urls = { ["NO"] = "https://example.org/personvern" } }));   // DataControllerId: default BccPrivacy:DataControllerId

privacy publish sends the notice before the processes. A data controller has one notice: two declared for the same controller is a problem. When the controller's notice already belongs to another application or the administrators, it is left alone and the publish reports a warning.

Ownership

Privacy records the owner of what the application pushes by its AppUID, the app_uid claim of its token, as Core API does. Ask for the AppUID to be added to the client's machine claims in sign-on; a push without it is refused (403). Only the application that created a process or notice can change it.

Removed processes

Set BccPrivacy:RemoveUndeclaredProcesses to true to let privacy publish delete processes the application no longer declares. Privacy refuses to delete a process people have consented to (409); such a process is kept, and a warning is printed. Processes owned by another application or by the administrators are never touched.

Per environment

The defaults follow the BCC platform environment: BccPlatform:HostingEnvironment (Prod, Dev, Local) when set, otherwise BccPlatform:Environment. ASP.NET Core's environment name does not count.

Dev, Local (or Environment Dev, Emulator) Sandbox, Staging Prod
Declarations checked Yes, logged Yes, logged Yes; a problem stops start-up
Compared with BccPrivacy:AcceptedRevision Yes, logged Yes; missing or different stops start-up Yes; missing or different stops start-up
Published to Privacy Never at start-up Never at start-up Never at start-up

Start-up calls no other service, so an unreachable Privacy API never stops it. The deploy publishes the definitions and records the revision Privacy accepted in BccPrivacy:AcceptedRevision; start-up compares the local definitions with it. Missing or different, start-up stops everywhere but development and local runs, where it is logged.

With no platform environment, start-up stops and names the settings, unless BccPrivacy:FailOnError is set. In Prod, a missing setting stops start-up: a process without a data controller (and no BccPrivacy:DataControllerId), or definitions that differ from the accepted revision. Override with BccPrivacy:FailOnError.

Release note: 0.6

Start-up no longer pushes processes and items to Privacy (LIB-15). Every restart depended on the Privacy API, and a failed push could leave a half-published set. Publish at deploy instead (privacy publish, LIB-4) and set BccPrivacy:AcceptedRevision to the revision it reports; without it, start-up stops outside development. BccPrivacy:Push is removed. An item name the catalogue does not know is no longer found at start-up; the publish step finds it. PrivacyPusher stays for callers that publish themselves.

Version 0.x. Licence: Apache 2.0. Source: bcc-code/bcc-privacy, libraries/dotnet.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on BccCode.Privacy.Hosting:

Package Downloads
BccCode.Privacy.Wolverine

BCC Privacy for Wolverine: the organisation, process and person carried on message envelopes, and handler middleware that sets each handler's privacy context from them and from the handler's [PrivacyProcess<T>].

BccCode.Privacy.ChangeHistory

Connects BCC Privacy for EF Core and BccCode.ChangeHistory on one model: events and links are read per organisation of the privacy context, history only while the current row is visible, and the privacy columns make no history version.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
14.6.8 44 11/26/2026
14.6.7 43 11/26/2026
14.6.6 44 11/26/2026
14.6.5 44 11/26/2026
14.6.4 43 11/26/2026
14.6.3 47 11/26/2026
14.6.2 44 11/26/2026
14.6.1 53 11/26/2026
14.6.0 38 11/26/2026
14.5.0 45 11/26/2026
14.4.0 45 11/26/2026
14.3.0 40 11/26/2026
14.2.0 42 11/26/2026
14.1.1 43 11/26/2026
14.1.0 42 11/26/2026
14.0.1 42 11/26/2026
14.0.0 43 11/26/2026
13.0.0 43 11/26/2026
12.0.1 40 11/26/2026
12.0.0 45 11/26/2026
Loading failed