@cratis/pi 7.175.0 → 7.176.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/SKILL.md +2 -3
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/authorization.md +2 -1
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/command-identity.md +194 -0
- package/package/corpus/skills/cratis-arc-authentication-authorization-and-identity/references/product-sources.md +26 -0
- package/package/corpus/skills/cratis-arc-command/references/decisions-and-routing.md +8 -5
- package/package/corpus/skills/cratis-arc-command/references/read-model-injection.md +29 -13
- package/package/corpus/skills/cratis-arc-command-operation/SKILL.md +1 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/SKILL.md +1 -0
- package/package/corpus/skills/cratis-chronicle-compliance/SKILL.md +1 -0
- package/package/corpus/skills/cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md +7 -4
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ told about them. Each has its own extension point.
|
|
|
13
13
|
|
|
14
14
|
## Verified product sources
|
|
15
15
|
|
|
16
|
-
Read [references/product-sources.md](references/
|
|
16
|
+
Read [product sources](references/product-sources.md) for packages; [command identity](references/command-identity.md) for actor injection, caller-keyed reads and Chronicle attribution.
|
|
17
17
|
|
|
18
18
|
Authorization capabilities arrived over time: named policies, schemes, fallback baselines, guest policies and Microsoft-attribute enforcement all need a recent Arc. [authorization](references/authorization.md) lists the requirements; check them if you run an older version.
|
|
19
19
|
|
|
@@ -297,6 +297,5 @@ To run locally with an identity, supply the forwarded headers yourself — see
|
|
|
297
297
|
|
|
298
298
|
- Rejecting a command's input or state: `cratis-arc-command-validation` scope
|
|
299
299
|
(validators are not the place for state-dependent permission rules).
|
|
300
|
-
-
|
|
301
|
-
multi-tenancy guidance.
|
|
300
|
+
- Tenant namespaces and per-tenant event stores: Chronicle multi-tenancy.
|
|
302
301
|
- Building the React page that consumes identity: the Arc React guidance.
|
|
@@ -375,7 +375,8 @@ being in-process does not prove permission.
|
|
|
375
375
|
of transport. During HTTP it is the request principal; outside HTTP it can be the
|
|
376
376
|
principal established by a server-side scope. Read claims from it, not from the
|
|
377
377
|
identity cookie, and not through `IHttpContextAccessor` in code that must also run
|
|
378
|
-
on hub emissions.
|
|
378
|
+
on hub emissions. For application actor injection, caller-keyed reads and
|
|
379
|
+
Chronicle attribution, read [command identity](command-identity.md).
|
|
379
380
|
|
|
380
381
|
Command authorization reads the principal from the current request. A reactor,
|
|
381
382
|
hosted service, or one command orchestrating another has no request, so any
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Command identity and Chronicle attribution
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Choose the contract
|
|
6
|
+
- Supply an application actor
|
|
7
|
+
- Select a caller-keyed read model
|
|
8
|
+
- Attribute events without copying personal data
|
|
9
|
+
|
|
10
|
+
## Choose the contract
|
|
11
|
+
|
|
12
|
+
| Need | Contract |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| Identify the caller at the server boundary | `ICurrentPrincipalAccessor.Current` in `Cratis.Arc.Authorization` |
|
|
15
|
+
| Supply an application-owned actor value to `Provide()` or `Handle()` | `IAsyncParameterDependencyResolver` in `Cratis.Arc.DependencyInjection` |
|
|
16
|
+
| Select a Chronicle read model using the caller | `[LookUpBy<CallerSubject>]`, `CallerClaim` or `IReadModelKeyProvider` in `Cratis.Arc.Commands` |
|
|
17
|
+
| Decide whether the caller may perform the action | Named authorization policies and `[Authorize]`; `Provide()` may short-circuit only when acquisition yields nothing usable |
|
|
18
|
+
| Attribute an append | Chronicle's `IIdentityProvider.GetCurrent()` supplies `CausedBy`; observers read `EventContext.CausedBy` |
|
|
19
|
+
|
|
20
|
+
An actor value and a lookup key are neither proof of permission nor a substitute
|
|
21
|
+
for authorization. Derive them from the server-selected authenticated principal,
|
|
22
|
+
not a command's `UserId`, a readable identity cookie, or untrusted headers.
|
|
23
|
+
Configure the trusted authentication boundary first; see
|
|
24
|
+
[forwarded identity](../SKILL.md#read-this-first-what-is-and-is-not-trusted).
|
|
25
|
+
Anonymous callers get no privileged fallback. Never manufacture a System actor
|
|
26
|
+
to make an unresolved caller pass.
|
|
27
|
+
|
|
28
|
+
## Supply an application actor
|
|
29
|
+
|
|
30
|
+
Prefer a small, immutable application type over passing `ClaimsPrincipal` into
|
|
31
|
+
business decisions. The following is a complete resolver illustration, not a
|
|
32
|
+
host: it requires Arc's principal accessor and the service registration below.
|
|
33
|
+
`CurrentActor` and `ActorSubject` are application-owned types, not Arc APIs. This
|
|
34
|
+
application requires one distinct, nonempty exact `sub` claim and refuses the
|
|
35
|
+
System identity. Adapt that policy explicitly for verified workload callers;
|
|
36
|
+
do not silently substitute a system subject. Keep the raw subject inside the
|
|
37
|
+
application boundary; use a non-personal domain key where the domain needs one.
|
|
38
|
+
|
|
39
|
+
```csharp
|
|
40
|
+
using System;
|
|
41
|
+
using System.Linq;
|
|
42
|
+
using System.Reflection;
|
|
43
|
+
using System.Threading.Tasks;
|
|
44
|
+
using Cratis.Arc.Authorization;
|
|
45
|
+
using Cratis.Arc.DependencyInjection;
|
|
46
|
+
using Cratis.Concepts;
|
|
47
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
48
|
+
|
|
49
|
+
public record ActorSubject(string Value) : ConceptAs<string>(Value);
|
|
50
|
+
public record CurrentActor(ActorSubject Subject);
|
|
51
|
+
|
|
52
|
+
public sealed class CurrentActorResolver : IAsyncParameterDependencyResolver
|
|
53
|
+
{
|
|
54
|
+
public bool TryResolve(IServiceProvider services, ParameterInfo parameter, out object? dependency)
|
|
55
|
+
{
|
|
56
|
+
dependency = null;
|
|
57
|
+
if (parameter.ParameterType != typeof(CurrentActor)) return false;
|
|
58
|
+
dependency = ActorFor(services.GetRequiredService<ICurrentPrincipalAccessor>());
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public ValueTask<ParameterDependencyResolution> Resolve(IServiceProvider services, ParameterInfo parameter) =>
|
|
63
|
+
ValueTask.FromResult(TryResolve(services, parameter, out var dependency)
|
|
64
|
+
? ParameterDependencyResolution.Resolved(dependency)
|
|
65
|
+
: ParameterDependencyResolution.NotResolved);
|
|
66
|
+
|
|
67
|
+
static CurrentActor? ActorFor(ICurrentPrincipalAccessor principals)
|
|
68
|
+
{
|
|
69
|
+
if (principals.Current is not { Identity: { IsAuthenticated: true } } principal ||
|
|
70
|
+
principal.Identity.AuthenticationType == "System") return null;
|
|
71
|
+
|
|
72
|
+
var subjects = principal.Claims
|
|
73
|
+
.Where(claim => claim.Type == "sub" && !string.IsNullOrEmpty(claim.Value))
|
|
74
|
+
.Select(claim => claim.Value)
|
|
75
|
+
.Distinct(StringComparer.Ordinal)
|
|
76
|
+
.Take(2)
|
|
77
|
+
.ToArray();
|
|
78
|
+
return subjects is [var subject] && subject != "[System]"
|
|
79
|
+
? new CurrentActor(new ActorSubject(subject))
|
|
80
|
+
: null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Register through the public resolver interface in the host's service setup:
|
|
86
|
+
|
|
87
|
+
```csharp
|
|
88
|
+
services.AddScoped<ICanResolveParameterDependency, CurrentActorResolver>();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`IAsyncParameterDependencyResolver` extends `ICanResolveParameterDependency`, so
|
|
92
|
+
both members matter. Awaiting command parameter binding calls `Resolve`; a
|
|
93
|
+
synchronous consumer calls `TryResolve`. Return
|
|
94
|
+
`ParameterDependencyResolution.NotResolved` (or `false`) for types you do not
|
|
95
|
+
own. `ParameterDependencyResolution.Resolved(null)` means the resolver owns the
|
|
96
|
+
parameter but has no value; it does not mean “try the next resolver”. The example
|
|
97
|
+
has no I/O. If acquisition needs I/O, await it in `Resolve`; do not block on a
|
|
98
|
+
Task in `TryResolve` or hide acquisition in `Handle()`.
|
|
99
|
+
|
|
100
|
+
Chronicle's registered chain consults Chronicle first, then application resolvers
|
|
101
|
+
from the current service scope. Do not replace its
|
|
102
|
+
`IInstancesOf<ICanResolveParameterDependency>` composition to install your actor
|
|
103
|
+
resolver, or claim a Chronicle read-model type as your application actor.
|
|
104
|
+
|
|
105
|
+
Require a named policy such as `[Authorize(Policy = "CanEnableFeature")]` on the
|
|
106
|
+
command and register that policy in the host. The policy owns the `CanEnable`
|
|
107
|
+
permission check, before validation or acquisition. A validator under read
|
|
108
|
+
protection `On` is an alternative for state-dependent preconditions, not caller
|
|
109
|
+
admission; see [validators are not an authorization boundary](../SKILL.md#validators-are-not-an-authorization-boundary).
|
|
110
|
+
|
|
111
|
+
These are **method excerpts** inside that command, not a complete slice.
|
|
112
|
+
`FeatureEnabled` is an application event with no identity fields:
|
|
113
|
+
|
|
114
|
+
```csharp
|
|
115
|
+
public AuthorizationResult Provide(CurrentActor? actor) =>
|
|
116
|
+
actor is null
|
|
117
|
+
? AuthorizationResult.Failure("Actor unavailable.")
|
|
118
|
+
: AuthorizationResult.Success;
|
|
119
|
+
|
|
120
|
+
public FeatureEnabled Handle(CurrentActor actor) => new();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The failed authorization result stops handler execution only because acquisition
|
|
124
|
+
yielded no usable actor, not because `Provide()` owns permission checks. A
|
|
125
|
+
non-nullable actor parameter alone is not a permission check. Do not use
|
|
126
|
+
`Provide()` to echo a client-supplied actor: ordinary returned values can satisfy
|
|
127
|
+
assignable `Handle()` parameters before resolver fallback. Keep acquisition in
|
|
128
|
+
`Provide()` or parameter binding and pass decision inputs explicitly; keep the
|
|
129
|
+
handler's decision free of hidden principal/service I/O. See
|
|
130
|
+
[authorization](authorization.md) and
|
|
131
|
+
[command decisions](../../cratis-arc-command/references/decisions-and-routing.md).
|
|
132
|
+
|
|
133
|
+
## Select a caller-keyed read model
|
|
134
|
+
|
|
135
|
+
Do not build a general actor resolver merely to select an existing Chronicle
|
|
136
|
+
read model. Arc already supports a generic lookup provider on a read-model
|
|
137
|
+
`Handle()` parameter. In a method excerpt where `CallerPreferences` is a
|
|
138
|
+
registered read model keyed by the caller's exact subject:
|
|
139
|
+
|
|
140
|
+
```csharp
|
|
141
|
+
public FeatureEnabled Handle([LookUpBy<CallerSubject>] CallerPreferences preferences) => new();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`CallerSubject` reads exact `sub`, without claim-type mapping. For another exact
|
|
145
|
+
claim, define a public parameterless provider such as:
|
|
146
|
+
|
|
147
|
+
```csharp
|
|
148
|
+
public sealed class CallerAccount() : CallerClaim("account_id");
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Use `[LookUpBy<CallerAccount>]` on the read-model parameter. `CallerClaim` refuses
|
|
152
|
+
unauthenticated and System callers. `CommandCaller.Single` accepts one distinct
|
|
153
|
+
nonempty value using ordinal comparisons: repeated equal claims are one value;
|
|
154
|
+
different values are ambiguous.
|
|
155
|
+
|
|
156
|
+
For a derived key, implement `IReadModelKeyProvider.Resolve(ReadModelKeyContext)`.
|
|
157
|
+
Its `Caller` is the immutable selected `CommandCaller`, captured before command
|
|
158
|
+
context providers run; actor-chain claims are excluded. Its `ReadModelType` is
|
|
159
|
+
the target model. Return `ReadModelKeyLookup.Found(key)`, `.Missing` or
|
|
160
|
+
`.Ambiguous`. Providers require a public parameterless constructor and must be
|
|
161
|
+
stateless, thread-safe, synchronous, I/O-free and service-free. Do not consult
|
|
162
|
+
ambient identity, inject services, or decode an unvalidated token in a provider.
|
|
163
|
+
|
|
164
|
+
Missing/ambiguous results, provider failures, and a missing or changed captured
|
|
165
|
+
caller fail closed through `ReadModelKeyResolutionDenied`, mapped to an
|
|
166
|
+
unauthorized command result without caller/provider exception data. This is key
|
|
167
|
+
resolution, not proof that the selected model exists or that the action is
|
|
168
|
+
permitted. Do not combine generic and property lookup forms, replace a
|
|
169
|
+
caller-keyed model with a `Provide()` value, or use a caller provider to redirect
|
|
170
|
+
a per-stream model away from the command's own stream. See
|
|
171
|
+
[read-model injection](../../cratis-arc-command/references/read-model-injection.md)
|
|
172
|
+
for command-property lookup, absence and read protection.
|
|
173
|
+
|
|
174
|
+
## Attribute events without copying personal data
|
|
175
|
+
|
|
176
|
+
Chronicle append preparation calls `IIdentityProvider.GetCurrent()` and sends the
|
|
177
|
+
identity as `CausedBy`. `EventContext.CausedBy` exposes that attribution to
|
|
178
|
+
observers. `Identity.OnBehalfOf` links an identity chain. This is audit metadata,
|
|
179
|
+
not authentication, permission, or an event's compliance subject. Do not put
|
|
180
|
+
subjects, names, emails, usernames, roles, claims or actor objects in event payloads
|
|
181
|
+
merely to record who acted. Keep events about business facts.
|
|
182
|
+
|
|
183
|
+
Chronicle's ASP.NET provider maps exact `sub`, `name` and `preferred_username`,
|
|
184
|
+
with `Identity.Name` fallbacks for the latter two. Arc's identity decorator
|
|
185
|
+
preserves the selected Chronicle identity and also handles authenticated
|
|
186
|
+
server-side principals outside HTTP. When a principal has a `ClaimsIdentity.Actor`,
|
|
187
|
+
Arc records the actor first and the represented user as `Identity.OnBehalfOf`;
|
|
188
|
+
this chain is attribution, never an authorization grant.
|
|
189
|
+
|
|
190
|
+
For standalone Chronicle, configure `IIdentityProvider` at the application
|
|
191
|
+
boundary; `SetCurrentIdentity`/`ClearCurrentIdentity` control attribution, not
|
|
192
|
+
caller permissions. Never forward raw identifiers to external services, logs,
|
|
193
|
+
telemetry, or evaluators. For lawful personal event data and the separate erasure
|
|
194
|
+
subject, use [Chronicle compliance](../../cratis-chronicle-compliance/SKILL.md).
|
|
@@ -9,3 +9,29 @@ This reference holds the packages and types Arc identity and authorization guida
|
|
|
9
9
|
| `@cratis/arc` | `IdentityProvider`, `IIdentity` |
|
|
10
10
|
| `@cratis/arc.react` | `IdentityProvider` component, `useIdentity`, `RequireRole` |
|
|
11
11
|
| Cratis AuthProxy (`cratis/authproxy`) | the trusted ingress described in [AuthProxy](authproxy.md) |
|
|
12
|
+
|
|
13
|
+
## Command identity and audit evidence
|
|
14
|
+
|
|
15
|
+
Verified against Arc `origin/main` (`d3ecc873b`) and Chronicle `origin/main`
|
|
16
|
+
(`ed97fe729a`). These sources own the contracts in
|
|
17
|
+
[command identity](command-identity.md); check your installed version before using
|
|
18
|
+
caller providers. No minimum release is asserted here.
|
|
19
|
+
|
|
20
|
+
| Source | Contract verified |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| Arc `Source/DotNET/Arc.Core/Authorization/ICurrentPrincipalAccessor.cs`, `CurrentPrincipalAccessor.cs`, `AuthorizationCommandIdentity.cs` | Selected principal; AsyncLocal, execution-context and HTTP access; immutable exact-claim caller snapshot without actor-chain claims |
|
|
23
|
+
| Arc `Source/DotNET/Arc.Core/DependencyInjection/IAsyncParameterDependencyResolver.cs`, `ICanResolveParameterDependency.cs`, `ParameterDependencyResolution.cs`, `ParameterDependencyResolver.cs` | Async and synchronous resolver members, resolved-null versus not-resolved, awaited binding |
|
|
24
|
+
| Arc `Source/DotNET/Chronicle/ReadModels/ChronicleParameterDependencyResolvers.cs`, `ReadModelServiceCollectionExtensions.cs` | Chronicle-first composition, scoped application resolver discovery through `IInstancesOf<ICanResolveParameterDependency>` |
|
|
25
|
+
| Arc `Source/DotNET/Arc.Core/Commands/CommandProvideInvoker.cs`, `CommandHandlerArgumentResolver.cs`, `ModelBound/ModelBoundCommandHandler.cs` | `Provide()` parameter binding; ordinary provided-value precedence; a supplied matching value for a caller-provider read-model parameter is refused with `InvalidLookUpBy` |
|
|
26
|
+
| Arc `Source/DotNET/Arc.Core/Authorization/AuthorizationResult.cs`; `Source/DotNET/Arc.Core/Commands/CommandPipeline.cs` | Failed `AuthorizationResult` from `Provide()` stops handler execution; key-resolution denial maps to unauthorized without exception details |
|
|
27
|
+
| Arc `Source/DotNET/Arc.Core/Commands/LookUpByAttribute.cs`, `IReadModelKeyProvider.cs`, `ReadModelKeyContext.cs`, `ReadModelKeyLookup.cs`, `CallerClaim.cs`, `CallerSubject.cs`, `ReadModelKeyProviders.cs`, `ReadModelKeyResolutionDenied.cs`, `CommandAttributePolicy.cs`; `Source/DotNET/Arc.Core/Authorization/CommandCaller.cs` | Both lookup forms, parameterless synchronous providers, exact claims, missing/ambiguous denial and caller consistency |
|
|
28
|
+
| Arc `Source/DotNET/Chronicle/ReadModels/CommandReadModelLookup.cs`, `ChronicleParameterDependencyResolver.cs` | Provider lookup precedes read protection; guarded and plain keyed loading |
|
|
29
|
+
| Arc `Source/DotNET/Chronicle.Specs/ReadModels/for_per_stream_models/when_a_key_provider_redirects_the_stream.cs` | A caller provider cannot redirect a per-stream read away from the command stream |
|
|
30
|
+
| Arc `Source/DotNET/Chronicle/Identities/ArcIdentityProvider.cs` | Selected Chronicle identity preservation, non-HTTP principal attribution, actor-first `OnBehalfOf` chain |
|
|
31
|
+
| Chronicle `Source/Clients/DotNET/Identities/IIdentityProvider.cs`, `Identity.cs`, `IdentityConverters.cs`; `Source/Clients/AspNetCore/Identities/IdentityProvider.cs` | Current/explicit identity, exact ASP.NET claim mapping, System identity and actor chain |
|
|
32
|
+
| Chronicle `Source/Clients/DotNET/EventSequences/EventSequence.cs`, `Events/EventContext.cs` | Append preparation obtains `CausedBy` from `GetCurrent()`; event context exposes attribution |
|
|
33
|
+
|
|
34
|
+
`CurrentActor`, `ActorSubject`, `CallerPreferences`, `CallerAccount` and
|
|
35
|
+
`FeatureEnabled` in the example are application-owned, not
|
|
36
|
+
product types. `ConceptAs<string>` follows Chronicle's
|
|
37
|
+
`Source/Clients/DotNET/EventStoreName.cs` and `GlobalUsings.cs`.
|
|
@@ -40,11 +40,14 @@ Requires Arc 22.106.0 for read protection. Older Arc has only the per-command
|
|
|
40
40
|
`[ProtectedDecision]` path below.
|
|
41
41
|
|
|
42
42
|
- **One entity's state.** Put the rule in a validator with the read model as a
|
|
43
|
-
constructor parameter; `Handle()` returns the events.
|
|
44
|
-
`[LookUpBy(nameof(Cmd.Prop))]`
|
|
45
|
-
|
|
46
|
-
command
|
|
47
|
-
|
|
43
|
+
constructor parameter; `Handle()` returns the events. Choose one explicit key
|
|
44
|
+
form: `[LookUpBy(nameof(Cmd.Prop))]` for a command property or
|
|
45
|
+
`[LookUpBy<CallerSubject>]` for a caller-keyed handler model (`Cratis.Arc.Commands`);
|
|
46
|
+
read [command identity](../../cratis-arc-authentication-authorization-and-identity/references/command-identity.md)
|
|
47
|
+
for providers, actor injection and attribution. Without an explicit lookup the
|
|
48
|
+
key is the single command property matching the model's `Id` type, else the
|
|
49
|
+
command's event source id. Several matches fail with
|
|
50
|
+
`AmbiguousReadModelLookup` (500): declare the intended lookup.
|
|
48
51
|
- **Two entities.** Two read-model parameters, the second with `[LookUpBy]`;
|
|
49
52
|
`Handle()` returns `IEnumerable<EventForEventSourceId>`, one event per entity,
|
|
50
53
|
appended atomically. Use a distinct event type per entity.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Contents
|
|
4
4
|
|
|
5
|
+
- Choose the key
|
|
5
6
|
- Nullability is the required/optional switch
|
|
6
7
|
- `null` is not always what absence looks like
|
|
7
8
|
- Which provider owns a read model type
|
|
@@ -16,28 +17,43 @@ and, for per-command opt-in, `[ProtectedDecision]` with `DecisionRead<T>`.
|
|
|
16
17
|
|
|
17
18
|
A read model can be injected into a `CommandValidator<T>` constructor, into
|
|
18
19
|
`Provide()`, or into `Handle()`. Arc resolves it through an
|
|
19
|
-
`ICanResolveReadModelForCommand` provider
|
|
20
|
-
|
|
20
|
+
`ICanResolveReadModelForCommand` provider using the selected lookup key. An
|
|
21
|
+
explicit command-property or caller-provider lookup is not limited to protected
|
|
22
|
+
commands. Without one, the default depends on the read-protection mode.
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
the wrong instance or nothing at all. That is a correctness bug, not a compile
|
|
24
|
-
error. The three shapes it takes:
|
|
24
|
+
Choose the key explicitly when the default is wrong. Three common cases:
|
|
25
25
|
|
|
26
26
|
1. you need a *referenced other* entity — act on A, check B;
|
|
27
27
|
2. the command has more than one candidate identity property, so resolution is
|
|
28
28
|
ambiguous;
|
|
29
29
|
3. the id is generated inside `Handle()` and does not exist yet.
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
Explicit lookup works in every read-protection mode. Choosing a key does not
|
|
32
|
+
make a plain read protected. For a key computed in `Provide()`, use
|
|
33
|
+
`IDecisionReads.Get` when it must guard the append; a direct by-id read under
|
|
34
|
+
`Off` remains unprotected.
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
var other = await readModels.GetInstanceById<<Other>>((EventSourceId)<OtherId>);
|
|
37
|
-
```
|
|
36
|
+
## Choose the key
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
Use one explicit form on a read-model `Handle()` parameter (`Cratis.Arc.Commands`):
|
|
39
|
+
|
|
40
|
+
- `[LookUpBy(nameof(CommandName.KeyProperty))]` selects a command property.
|
|
41
|
+
- `[LookUpBy<CallerSubject>]`, a `CallerClaim` subclass or another
|
|
42
|
+
`IReadModelKeyProvider` selects a caller-derived key. See
|
|
43
|
+
[command identity](../../cratis-arc-authentication-authorization-and-identity/references/command-identity.md)
|
|
44
|
+
for exact claims, immutable caller capture, denial, actor injection and audit.
|
|
45
|
+
|
|
46
|
+
Do not combine property and provider forms or specify several providers. Without
|
|
47
|
+
an explicit lookup, `On` uses the single command property whose type exactly
|
|
48
|
+
matches the model's `Id` type; several matches raise `AmbiguousReadModelLookup`;
|
|
49
|
+
no match falls back to the command event source id. `Off` and `Measure` retain
|
|
50
|
+
the legacy event-source-id default. A caller provider cannot redirect a
|
|
51
|
+
per-stream model away from the command route.
|
|
52
|
+
|
|
53
|
+
Ordinary `Provide()` values assignable to a `Handle()` parameter are used before
|
|
54
|
+
service/read-model resolution. For a caller-provider read-model parameter, a
|
|
55
|
+
supplied matching value is refused with `InvalidLookUpBy`, not bypassed: do not
|
|
56
|
+
try to replace the identity-keyed model with a provided value.
|
|
41
57
|
|
|
42
58
|
Requires Arc 22.93.0 for ARCCHR0023 (no unique key-type match), ARCCHR0025
|
|
43
59
|
(keyless command reads a newly generated id and finds no model) and ARCCHR0026
|
|
@@ -48,6 +48,7 @@ Arc for TypeScript server API.
|
|
|
48
48
|
|
|
49
49
|
Do not disguise a write as `Provide()`. Supply identities, clock values, and
|
|
50
50
|
state before `Handle()`; returning operations does not make hidden I/O pure.
|
|
51
|
+
Actors/audit: [identity](../cratis-arc-authentication-authorization-and-identity/references/command-identity.md).
|
|
51
52
|
|
|
52
53
|
## Declare the work and its reversal
|
|
53
54
|
|
|
@@ -32,6 +32,7 @@ Read references/occurrences.md when recording durable triggers, implementing
|
|
|
32
32
|
occurrence handlers, or choosing startup/shutdown activation and retry semantics.
|
|
33
33
|
Read references/immediate-append-refusal.md when a unit must prevent immediate
|
|
34
34
|
appends from escaping its atomic receipt boundary before transport.
|
|
35
|
+
For caller versus `CausedBy` attribution: [command identity](../cratis-arc-authentication-authorization-and-identity/references/command-identity.md).
|
|
35
36
|
|
|
36
37
|
## Lifecycle
|
|
37
38
|
|
|
@@ -84,6 +84,7 @@ can fail those appends. Verify a protected-value round trip, not only compilatio
|
|
|
84
84
|
Mark only genuinely personal values. Business metadata, identifiers of
|
|
85
85
|
non-persons, and amounts stay unmarked — every marked value costs an encryption
|
|
86
86
|
round trip and becomes unreadable the moment the subject is erased.
|
|
87
|
+
Attribution, not payload PII: [identity](../cratis-arc-authentication-authorization-and-identity/references/command-identity.md).
|
|
87
88
|
|
|
88
89
|
## Decide the subject
|
|
89
90
|
|
|
@@ -131,10 +131,13 @@ Under `On`:
|
|
|
131
131
|
Take the model as a parameter, or mark the method `[Unprotected("why")]` (it
|
|
132
132
|
covers the body, not injected parameters).
|
|
133
133
|
- Immediate appends (an injected `IEventLog.Append`) are refused. Return the events.
|
|
134
|
-
-
|
|
135
|
-
(
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
- Explicit lookup selects either a command property with
|
|
135
|
+
`[LookUpBy(nameof(Cmd.Prop))]` or a caller-keyed handler model with
|
|
136
|
+
`[LookUpBy<CallerSubject>]` (`Cratis.Arc.Commands`); see
|
|
137
|
+
[command identity](../../cratis-arc-authentication-authorization-and-identity/references/command-identity.md).
|
|
138
|
+
Otherwise use the single command property matching the model's `Id` type;
|
|
139
|
+
several matches raise `AmbiguousReadModelLookup` (HTTP 500); no match falls
|
|
140
|
+
back to the command's event source id.
|
|
138
141
|
- Admitted: event-source-keyed model-bound or declarative projections with a
|
|
139
142
|
string or Guid `Id`, and unfiltered reducers without constructor dependencies
|
|
140
143
|
(except `ILogger<T>`; self-reducing models are exempt). Refused with
|