Permguard 0.3.0
dotnet add package Permguard --version 0.3.0
NuGet\Install-Package Permguard -Version 0.3.0
<PackageReference Include="Permguard" Version="0.3.0" />
<PackageVersion Include="Permguard" Version="0.3.0" />
<PackageReference Include="Permguard" />
paket add Permguard --version 0.3.0
#r "nuget: Permguard, 0.3.0"
#:package Permguard@0.3.0
#addin nuget:?package=Permguard&version=0.3.0
#tool nuget:?package=Permguard&version=0.3.0
Permguard .NET SDK
<p align="center"> <img src="https://raw.githubusercontent.com/permguard/sdk-netcore/main/assets/readme/hero.png?v=2" alt="Permguard SDK for .NET. Ask Permguard, from .NET: the official .NET client of the Permguard Policy Decision Point, .NET 8 or newer, over HTTP or gRPC, Apache-2.0. Beside it, a C# window creates a client for grpc://localhost:7443 and evaluates whether the User alice may read in the ledger main-ledger of the zone acme; the answer is permit." width="820"> </p>
<p align="center"> <a href="https://github.com/permguard/permguard"><b>Permguard</b></a> · <a href="https://docs.permguard.com/"><b>Documentation</b></a> · <a href="#install"><b>Install</b></a> · <a href="#quick-start"><b>Quick start</b></a> · <a href="#develop"><b>Develop</b></a> </p>
The official .NET client of the Permguard Policy Decision Point.
Before your code acts, it asks Permguard whether a subject may perform an action on a resource, and Permguard answers from the policies of a ledger.
This SDK is how .NET code asks: one asynchronous client for the native, stateless PDP interface permguard.api.pdp.native.v1, over HTTP/JSON or gRPC, with the same request and the same answer on both.
<p align="center"> <img src="https://raw.githubusercontent.com/permguard/sdk-netcore/main/assets/readme/flow.png?v=2" alt="How a decision is asked. Your .NET code asks before it acts: who, User alice; does what, read; on what, Document budget-2026. The Permguard .NET SDK, one client with EvaluateAsync and EvaluateManyAsync, sends it as JSON to an http or https endpoint or over gRPC to a grpc or grpcs endpoint. The Permguard data plane, the PDP of the native v1 interface, decides with the policies of the ledger main-ledger in the zone acme, under the profile gateway, on Cedar, Rego or Dogwood. The answer is a permit, a deny, which is a normal answer, or a Refusal with its class and code." width="820"> </p>
<p align="center"><sub>Your code asks, the SDK carries the question, the data plane decides with the ledger's policies.</sub></p>
Install
The SDK targets .NET 8 and is published on NuGet.
dotnet add package Permguard
It needs a Permguard data plane to ask: by default it listens on port 7443, for HTTP and gRPC alike.
See the Permguard repository to run one.
Quick start
using Permguard;
using PdpAction = Permguard.Action;
// grpc:// or grpcs:// speaks gRPC; http:// or https:// speaks JSON.
await using var client = new Client("grpc://localhost:7443");
try
{
var response = await client.EvaluateAsync(new EvaluateRequest("acme", "main-ledger")
{
Subject = new Entity("User", "alice"),
Resource = new Entity("Document", "budget-2026"),
Action = new PdpAction("read"),
RequestId = Guid.NewGuid().ToString(),
});
Console.WriteLine(response.Decision ? "PERMIT" : "DENY");
}
catch (Refusal refusal)
{
Console.Error.WriteLine($"refused: class={refusal.ErrorClass} code={refusal.Code} message={refusal.Message}");
}
Action is also a name in System: the PdpAction alias keeps the two apart.
The same program is in SampleJsonPermguard; pass an endpoint or set PERMGUARD_PDP_URL to point it at another data plane.
A request that names no profile is decided by the ledger's default profile: the manifest permguard init writes declares it, with one partition, cedar.
A ledger whose manifest declares other profiles is asked with the profile's name, and its partition inputs are keyed by that profile's partitions.
The request
| Property | What it says |
|---|---|
EvaluateRequest(zone, ledger) |
the ledger whose policies decide, in its zone |
Profile |
the profile of the ledger's manifest that selects the partitions to run |
Subject |
who asks: a type and an id, with optional Properties |
Resource |
what is acted on: a type and an id, with optional Properties |
Action |
what is done: a name, with optional Properties |
Context |
any other fact the policies read |
PartitionInputs |
runtime data for the partitions of the profile, see below |
RequestId |
your id for the call, given back in the answer |
RequestNonce |
asks for a signed response, see below |
The answer
A deny is not an exception: it is a successful EvaluateResponse with Decision == false.
Validation, authorization, availability and server failures throw Refusal, with their stable ErrorClass and Code, and the HttpStatus or GrpcStatus they came with.
A call that fails in the client is a Refusal too, the same on HTTP and gRPC and in every Permguard SDK: class unavailable (Refusal.Unavailable) with code timeout (Refusal.Timeout) when the call's timeout passed, code unreachable (Refusal.Unreachable) when the data plane could not be reached.
A cancellation of your own CancellationToken is not a refusal: it throws OperationCanceledException.
Each decision's Context.Evidence says how the plane recorded it: its Mode, its Status and, once recorded, its RecordId and Position.
A request that sets RequestNonce (base64url without padding, 16 to 64 bytes) asks for a signed response, and the answer carries the plane's Attestation: the plane signs only for an authenticated caller, and refuses with unauthenticated rather than answer unsigned.
Partition inputs
Runtime data is addressed to the partition name the ledger's profile declares:
var request = new EvaluateRequest("acme", "main-ledger")
{
PartitionInputs = new Dictionary<string, PartitionInput>
{
["cedar"] = new PartitionInput("permguard.cedar.entities.v1", new[]
{
new Dictionary<string, object?>
{
["uid"] = new Dictionary<string, object?> { ["type"] = "Team", ["id"] = "engineering" },
["attrs"] = new Dictionary<string, object?> { ["active"] = true },
["parents"] = Array.Empty<object>(),
},
}),
},
};
The key is a partition name from the selected profile. The input type asserts the partition's input contract; it does not select a policy runtime.
Many evaluations at once
Set the defaults on the request, list the Evaluations, and call EvaluateManyAsync:
var response = await client.EvaluateManyAsync(new EvaluateRequest("acme", "main-ledger")
{
Subject = new Entity("User", "alice"),
Evaluations = new[]
{
new Evaluation
{
Resource = new Entity("Document", "budget-2026"),
Action = new PdpAction("read"),
RequestId = "read",
},
new Evaluation
{
Resource = new Entity("Document", "budget-2026"),
Action = new PdpAction("update"),
RequestId = "update",
},
},
Options = new EvaluationOptions { EvaluationsSemantic = EvaluationsSemantic.ExecuteAll },
});
foreach (var result in response.Evaluations ?? [])
{
Console.WriteLine($"{result.RequestId}: {(result.Decision ? "PERMIT" : "DENY")}");
}
Each evaluation inherits what it does not set from the request.
Endpoints and options
| Endpoint | Transport |
|---|---|
http:// |
JSON over HTTP |
https:// |
JSON over HTTPS |
grpc:// |
permguard.data.v1.PolicyDecisionPoint |
grpcs:// |
permguard.data.v1.PolicyDecisionPoint on TLS |
await using var client = new Client("https://pdp.example.com", new ClientOptions
{
Timeout = TimeSpan.FromSeconds(5),
Headers = new Dictionary<string, string> { ["authorization"] = $"Bearer {token}" },
});
var configuration = await client.GetConfigurationAsync();
| Option | Sets |
|---|---|
Timeout |
the timeout of every call, five seconds by default |
Headers |
static headers, also sent as gRPC metadata |
HttpClient |
the HttpClient used for HTTP |
GrpcChannelOptions |
the channel options used for gRPC |
Every call also takes a CancellationToken.
GetConfigurationAsync reads the data plane's discovery document.
Credentials
In production a data plane admits a call only with an access token of its cluster's Authority Plane, issued to a service account whose scopes include decision.evaluate on that data plane.
Obtain one with the account's access key and secret key, then send it on every call as authorization: Bearer <token>, with the header option above.
curl -s -u "$PERMGUARD_ACCESS_KEY:$PERMGUARD_SECRET_KEY" \
-d grant_type=client_credentials \
https://permguard.example:8443/authority/v1/token | jq -r .access_token
A token lasts an hour unless asked shorter: obtain another before it expires.
The development configurations Permguard ships grant decision.evaluate to everybody, so the quick start needs no token.
See the Authority Plane for service accounts, their scopes and keys.
Compatibility
This major version implements permguard.api.pdp.native.v1.
Compatibility is tied to that versioned interface, not to a server minor version.
The contract this release carries is the pdp.proto of Permguard v0.1.33, the tag PERMGUARD_CONTRACT names: CI fails when the copy in Permguard/Grpc differs from it, and runs the tests against a data plane of that release over HTTP and gRPC.
It covers the decision interface: a request may ask for a signed response with RequestNonce, and the answer carries the plane's Attestation and each decision's Context.Evidence; the discovery document carries the version, lifecycle, limits and response signing.
The temporal interface, permguard.api.pdp.temporal.v1alpha1, is not covered by this SDK.
Develop
dotnet restore SamplePermguard.sln
dotnet test SamplePermguard.sln --configuration Release -m:1
dotnet pack Permguard/Permguard.csproj --configuration Release
The tests host an in-process gRPC data plane, so they need the ASP.NET Core 8 runtime (Microsoft.AspNetCore.App 8.x) beside the .NET 8 SDK; on a machine with only a newer runtime, DOTNET_ROLL_FORWARD=Major runs them on it.
Permguard/Grpc/pdp.proto is the canonical contract of the Permguard release PERMGUARD_CONTRACT names, with the C# namespace option added; bash scripts/check-contract.sh Permguard/Grpc/pdp.proto checks it.
bash scripts/e2e-server.sh starts that release with a ledger the end-to-end test asks (E2E_HTTP=http://127.0.0.1:7443 E2E_GRPC=grpc://127.0.0.1:7443 dotnet test Permguard.Tests/Permguard.Tests.csproj --filter Category=E2E); without those variables the test is skipped, and E2E_PORT_OFFSET moves the server's ports when another server holds them.
The project's version is a placeholder, 0.0.0: a release takes its version from its tag, so the version to install is the latest on NuGet.
The NuGet package includes LICENSE, NOTICE.md, THIRD_PARTY_NOTICES.md and this README.
License
Apache License 2.0: see LICENSE, NOTICE.md and THIRD_PARTY_NOTICES.md.
Permguard is a trademark of Nitro Agility S.r.l., see TRADEMARKS.md. .NET and the .NET logo are trademarks of Microsoft Corporation, shown only to name the platform this SDK is for.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Google.Protobuf (>= 3.30.0)
- Grpc.Net.Client (>= 2.70.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.