CedarSharp 1.0.0

dotnet add package CedarSharp --version 1.0.0
                    
NuGet\Install-Package CedarSharp -Version 1.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="CedarSharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CedarSharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CedarSharp" />
                    
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 CedarSharp --version 1.0.0
                    
#r "nuget: CedarSharp, 1.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 CedarSharp@1.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=CedarSharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CedarSharp&version=1.0.0
                    
Install as a Cake Tool

CedarSharp

CedarSharp is an unofficial .NET 8 / .NET 10 wrapper around the Rust Cedar policy engine. It calls the original cedar-policy implementation through a small native bridge. The Cedar project and its contributors created and maintain Cedar; this repository provides the .NET wrapper and does not claim authorship of the original engine or policy language.

Version 1.0.0 passed the full CI matrix. See NuGet for published versions and the verification record for release evidence.

Authorization, strict policy validation, policy/schema parsing, request/context/entity checks, structured diagnostics, and loaded native version discovery are implemented.

The 1.0 support scope is the tested CI environments: Windows Server 2025 x64, Ubuntu 24.04 x64, and macOS 15 ARM64, with .NET 8 and .NET 10. These runner versions are the deployment baselines; older OS and glibc versions are not qualified. The API contract records result, exception, nullability, and compatibility guarantees.

Packaging remains opt-in and requires verified native assets for every RID. Do not infer native support from a successful managed build.

CedarSharp preserves Cedar's default deny, forbid precedence, and skip-on-error semantics. An Allow with policy errors remains an Allow with policy errors. Your application decides whether to reject that result. Hufu's adapter will own its stricter decision handling, grants and authority lifecycle separately.

The library is trim- and NativeAOT-compatible. Typed convenience overloads that serialize arbitrary CLR objects use reflection and are annotated RequiresUnreferencedCode/RequiresDynamicCode; for AOT use the JsonElement and JsonNode overloads (or JsonTypeInfo<T>), which take no reflection path.

Usage

using CedarSharp;

var engine = new CedarEngine();
var policies = CedarPolicySet.FromPolicies(new Dictionary<string, string>
{
    ["read-documents"] = "permit(principal, action == Action::\"read\", resource);"
});
var result = engine.Authorize(new CedarAuthorizationRequest(
    new CedarEntityUid("User", "alice"),
    new CedarEntityUid("Action", "read"),
    new CedarEntityUid("Document", "report"),
    policies));

// Parsing failures have no decision. Evaluation errors remain separately visible.
Console.WriteLine(result.Decision);
foreach (var error in result.PolicyErrors)
    Console.WriteLine($"{error.PolicyId}: {error.Error.Message}");
Console.WriteLine(engine.GetVersion());

A successful call (IsSuccess) means Cedar evaluated the request. It does not mean access was allowed or evaluation was error-free. Decision is nullable: Cedar parsing failures populate Errors and have no decision. Native loading, ABI, output-decoding or transport failures throw CedarBridgeException. Invalid CLR arguments or JSON syntax throw standard argument/JSON exceptions; a structurally invalid Cedar call envelope throws CedarInputException. No failure becomes an authorization grant or a fabricated Cedar denial.

var schema = CedarSchema.FromText("""
    entity User;
    entity Document;
    action read appliesTo {
        principal: User, resource: Document, context: {}
    };
    """);
var validation = engine.ValidatePolicies(policies, schema);
Console.WriteLine(validation.IsValid);

CheckPolicies checks syntax; ValidatePolicies performs strict schema-based policy validation. CheckSchema, CheckRequest (alias CheckScope), CheckContext, and CheckEntities expose separate checks. CheckRequest checks the three scope identifiers only — use CheckFullRequest(request, schema) (or the principal/action/resource + context + entities overload) to validate scope, context, and entities together. Authorization does not implicitly validate policies. Supplying a schema to a request enables schema-based entity/context parsing and, by default, request validation. validateRequest: false disables only request validation.

Fail-closed enforcement

// Decision alone is not enough: an Allow can carry policy errors.
if (!result.IsCleanAllow)
    return Results.Forbid(); // or deny, log result.ToString(), audit result.Raw

result.RequireAllow();    // CedarAuthorizationException unless an error-free Allow
result.EnsureNoErrors();  // throws on any error/policy-error; accepts a clean Deny
validation.EnsureValid(); // CedarValidationException unless strict validation passed

CedarBridgeException is reserved for native loading, ABI, transport, or response-decoding failure. Authorization and validation requirement failures throw CedarAuthorizationException / CedarValidationException, each carrying the originating result. No failure becomes a grant or a fabricated denial.

Typed entities and context (no hand-written escapes)

var alice = CedarEntityUid.Parse("User::\"alice\"");
var report = new CedarEntityUid("Document", "report");

var request = new CedarAuthorizationRequest(
    alice,
    new CedarEntityUid("Action", "read"),
    report,
    policies,
    context: new { trusted = true, ip = CedarValue.Ip("127.0.0.1") },
    entities: new[]
    {
        new CedarEntity(report, new { owner = CedarValue.Entity(alice) }),
    },
    schema: schema);

var full = engine.CheckFullRequest(request, schema);
var batch = engine.AuthorizeBatch(new[] { request }, parallel: true);

// Shorthands: policies from (id, text) tuples and a direct authorize overload.
var policies = CedarPolicySet.FromPolicies(("read", "permit(principal, action, resource);"));
var direct = engine.Authorize(alice, new CedarEntityUid("Action", "read"), report, policies);

CedarPolicySet and CedarSchema have value equality, so they can key caches and memoized validation. Every call also emits an Activity on the CedarSharp ActivitySource (cedarsharp.authorize, cedarsharp.validate_policies) with decision, error-count, and engine/bridge version tags for OpenTelemetry; see CedarSharpDiagnostics. Activities never export principal/action/resource identities or error text by default; opt in with CedarSharpDiagnostics.IncludeIdentity / IncludeErrorDetails for trusted sinks.

Cedar entity UIDs parse and format Cedar source grammar, not JSON: CedarEntityUid.Parse("Acme::User::\"a\\u{96ea}\"") and uid.ToString() produce Type::"id" with Cedar escapes. Empty ids are legal; the type is validated as a Cedar identifier path.

Deployment modes

The package supports framework-dependent, self-contained, RID-specific publishing, trimming (PublishTrimmed), and NativeAOT (PublishAot). The loader resolves the native asset relative to AppContext.BaseDirectory, so single-file and AOT deployments should copy runtimes/<rid>/native/ beside the app (the SDK does this by default for RID publishes). CEDARSHARP_NATIVE_PATH selects a self-built asset and is still hash- and identity-verified; relative paths resolve against the current directory. The repository's samples/CedarSharp.AotSmoke project is published and executed under NativeAOT for each supported RID in CI. Single-file publishing has not been separately exercised by CI.

Inputs are immutable copied snapshots. CedarPolicySet.FromJson supports the upstream staticPolicies, templates, and templateLinks representation; FromPolicies assigns stable caller-controlled policy IDs. CedarSchema.FromJson accepts Cedar JSON schemas. Context and entity JSON use Cedar's documented value encoding, including entity and extension escapes. All results retain the full upstream Raw JSON alongside typed diagnostics, related errors and source ranges (UTF-8 byte offsets). Sets of determining IDs/errors have no ordering guarantee.

The NuGet package includes XML documentation for the public API. Instances may be shared between threads. Calls are synchronous and parse inputs per evaluation. The native library lives for the process lifetime; no disposal is required. There are no cancellation or hard resource-deadline guarantees. The bridge limits wire input to 16 MiB and output to 64 MiB; these are not limits on Cedar's intermediate memory usage or execution time. CEDARSHARP_NATIVE_PATH may point at a directory or file holding a self-built native asset; it is still hash- and identity-verified before loading.

Build and native CI

The baseline is Cedar 4.13.0, Rust 1.94.0, bridge 0.1.0, ABI 1. Only ipaddr, decimal, and datetime extensions are enabled. Experimental features and symbolic analysis are excluded. See native contract.

# Requires the pinned Rust toolchain and an OS-native linker/SDK.
pwsh ./eng/Build-Native.ps1 -Rid win-x64
dotnet build CedarSharp.slnx -c Release
dotnet run --project tests/CedarSharp.Tests -c Release -f net8.0
dotnet run --project tests/CedarSharp.Tests -c Release -f net10.0

The CI matrix builds and executes on Windows x64, Linux x64, and macOS ARM64, then assembles one NuGet archive and runs clean package consumers on each OS. It also publishes and runs the NativeAOT smoke per RID. macOS uses a native ARM64 runner. Linux qualification targets the CI runner's glibc baseline; musl, Windows ARM64 and macOS x64 are not supported by this slice. Oldest-OS baselines are not yet qualified; see docs/verification.md.

For a Windows-only local package smoke check after staging win-x64, use a -local version and the explicit test override:

dotnet pack src/CedarSharp/CedarSharp.csproj -c Release -o artifacts/local-pack `
  -p:CedarSharpEnablePack=true -p:CedarSharpLocalSmokePack=true -p:PackageVersion=0.1.0-local.1
./eng/Verify-NuGetPackage.ps1 -PackagePath artifacts/local-pack/CedarSharp.0.1.0-local.1.nupkg `
  -ExpectedRids win-x64 -ExpectedVersion 0.1.0-local.1
./eng/Test-PackagedConsumer.ps1 -PackagePath artifacts/local-pack/CedarSharp.0.1.0-local.1.nupkg `
  -Framework net8.0 -RuntimeIdentifier win-x64

The normal package gate requires all three verified RID assets. The local smoke archive is an ignored development artifact and has not qualified Linux or macOS.

Publishing to NuGet

The separate Publish to NuGet workflow is started manually from main. It runs the complete native, package, and six OS/framework consumer combinations at that commit, then verifies the exact package again before publishing it through NuGet trusted publishing. A normal push or CI run does not publish. The workflow publishes the version in src/CedarSharp/CedarSharp.csproj; update that version before starting a new release. NuGet will reject an already published version.

Trusted publishing was exercised for 0.1.0-preview.1 in publish run #1 and for 0.2.0-preview.1 in publish run #2. To release a new version, choose Actions → Publish to NuGet → Run workflow on main after advancing the version and reviewing the release evidence. The workflow requests a short-lived API key only after verification has passed. See the changelog and NuGet trusted publishing setup.

Native assets and their SHA-256 manifests must be deployed together. The loader uses only an adjacent package asset or runtimes/<rid>/native/, verifies the manifest and live version, and does not search arbitrary PATH locations or download code. The hash detects corruption/mismatched staging; it does not replace trust in the package publisher or secure deployment permissions.

See the implementation plan, verification evidence, roadmap, and external-consumer sample.

License and attribution

CedarSharp is licensed under Apache License 2.0, the same license as upstream Cedar. The Cedar engine and policy language are the work of the Cedar project and its contributors. CedarSharp is an independent wrapper, unaffiliated with the Cedar project and Penghou/Hufu. The NOTICE records upstream attribution; native packages also carry the Cedar and dependency license and notice files. Publication status is tracked in verification evidence.

Product 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 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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CedarSharp:

Package Downloads
Penghou.Hufu.Cedar

Optional CedarSharp policy evaluation for Hufu authority.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 991 9/30/2026
0.2.0-preview.1 81 9/30/2026
0.1.0-preview.1 75 9/30/2026