RatelKey.Burrow.Sdk
1.3.1
dotnet add package RatelKey.Burrow.Sdk --version 1.3.1
NuGet\Install-Package RatelKey.Burrow.Sdk -Version 1.3.1
<PackageReference Include="RatelKey.Burrow.Sdk" Version="1.3.1" />
<PackageVersion Include="RatelKey.Burrow.Sdk" Version="1.3.1" />
<PackageReference Include="RatelKey.Burrow.Sdk" />
paket add RatelKey.Burrow.Sdk --version 1.3.1
#r "nuget: RatelKey.Burrow.Sdk, 1.3.1"
#:package RatelKey.Burrow.Sdk@1.3.1
#addin nuget:?package=RatelKey.Burrow.Sdk&version=1.3.1
#tool nuget:?package=RatelKey.Burrow.Sdk&version=1.3.1
Burrow SDK for .NET
Read secrets from a self-hosted RatelKey Burrow with a machine identity.
- Single and structured secrets, and individual fields of a structured secret.
- The machine's own access map (
ListProjectsAsync,ListSecretsAsync). - Certificate pinning, or standard CA trust (
TlsMode). - Live secrets that follow every change on the Burrow (
LiveAsync,LiveEnvironmentAsync). - An encrypted copy of each read that answers when the Burrow can't be reached (
CacheEnabled). - Certificates from a dynamic certificate secret, such as SSH logins, for a key made in memory (
GetCertificateAsync,LiveCertificateAsync). - An OIDC token instead of a key (
Burrow.Oidc). - Verifying the Burrow's signed webhooks (
BurrowWebhooks.Verify).
Requirements
- .NET 8+.
- One dependency:
BouncyCastle.Cryptography, for Ed25519.
Install
dotnet add package RatelKey.Burrow.Sdk
Bootstrap a machine
From the Burrow dashboard, Machines → Add machine, and run the install it gives you on the target host.
The identity lands at ~/.burrow/burrows/<slug>/identity.json.
Quick start
using RatelKey.Burrow;
// The single machine identity on this host (under ~/.burrow, or $BURROW_HOME).
using var burrow = Burrow.Open();
// A single-value secret:
var apiKey = (await burrow.GetSecretAsync("payments/prod/API_KEY")).Value;
// A structured secret, one read, projected locally with no re-fetch:
var db = await burrow.GetSecretAsync("payments/prod/DATABASE");
var all = db.ToDictionary(); // every field, name to value
var host = db.GetField("host"); // one field
var fields = db.GetFields("username", "password"); // in the order given
// What this machine can read:
foreach (var p in await burrow.ListProjectsAsync())
Console.WriteLine($"{p.Project}: {string.Join(", ", p.Categories)}");
Point it at a specific identity by selector or path:
Burrow.Open("burrow-a1b2c3d4e5f60718"); // slug / name / machine id / URL
Burrow.Open("/home/you/.burrow/burrows/burrow-a1b2c3d4e5f60718"); // path (a burrow dir or identity.json)
Without ~/.burrow
For an app that manages its own key material:
using var burrow = Burrow.Connect(
burrowUrl: "https://burrow.internal:12010",
machineId: "...",
privateKeyPem: Environment.GetEnvironmentVariable("BURROW_MACHINE_KEY")!); // PKCS#8 PEM
Live secrets
A live handle holds a secret's current value and follows every change on the Burrow as it happens.
var db = await burrow.LiveAsync("payments/prod/DATABASE");
db.GetField("password"); // always the current value
db.Changed += (_, change) => pool.Reconnect(change.Next);
burrow.LiveEnvironmentAsync("payments/prod") does the same for a whole environment: env.Get("API_KEY"), and
Changed lists what changed, was added or was removed.
- The call completes after the first read. A missing secret or grant is refused there.
- All live handles on a client share one connection. It reconnects on its own and re-reads anything that changed while it was down.
StatusisLive,Reconnecting,Revoked(access was taken away) orRemoved(deleted on the Burrow). The last two are final, and the handle keeps its last value.- Handlers run on the SDK's background threads. One that throws is reported on
Error. CloseAsync()or disposing the client closes every handle.- Needs a Burrow with live updates; an older one is refused at
LiveAsync.
Fallback cache
The fallback cache keeps a copy of each secret the client reads, and answers with it when your Burrow can't be reached. It's off until you turn it on:
using var burrow = Burrow.Open().CacheEnabled();
Without CacheEnabled, Burrow.Open() uses the cache when ratel cache enable turned it on for the machine, and
CacheEnabled(false) keeps it off. With Burrow.Connect, it needs a pinStoreDir to keep the copies in.
Burrow.Enroll and Burrow.Oidc can't use it.
A read uses the cache only when it fails because your Burrow can't be reached or can't answer. A secret answered from the cache says when its copy was saved:
var key = await burrow.GetSecretAsync("payments/prod/API_KEY");
if (key.CachedAt is { } savedAt) logger.LogWarning("Using the copy saved at {SavedAt}", savedAt);
A live secret or environment doesn't answer from the cache. While your Burrow can't be reached it keeps the value it last read, and each read it makes keeps the copies up to date. When your Burrow refuses a read, because the machine was removed or disabled, lost access, or the secret is gone, the read fails as usual and the refused copies are deleted. A dynamic secret's login comes back as it was saved, so it may have expired.
Certificates
A dynamic certificate secret, such as an SSH user secret, gives each machine that asks a short-lived certificate of its own. The SDK makes a new Ed25519 key in memory for each one and sends only its public half.
var login = await burrow.GetCertificateAsync("api/prod/DEPLOY_SSH");
login.PrivateKey // the OpenSSH private key
login.Value // its certificate (ssh-ed25519-cert-v01@openssh.com ...)
login.Principals // the logins it signs in as
login.Host // where the secret says to connect, or null
login.ValidBefore // when it stops being accepted
Hand the key and certificate to your SSH library, or write them to id_ed25519 (mode 600) and
id_ed25519-cert.pub for ssh -i. Passing TimeSpan.FromMinutes(5) as validity asks for one that lasts less than
the secret allows.
LiveCertificateAsync keeps one current:
var login = await burrow.LiveCertificateAsync("api/prod/DEPLOY_SSH");
login.Current; // the certificate and key to use now
login.Changed += (_, change) => connections.UseKey(change.Next);
await login.RenewAsync(); // a new one at once, e.g. after a host refused it
- It renews once two thirds of the certificate's time have passed, and as soon as the secret's settings change. Each renewal makes a new key.
- Revoking one certificate from the dashboard sends no event;
RenewAsync()gets a new one. GetSecretAsyncon a certificate secret throwsBurrowServerException(409) namingGetCertificateAsync.
In-memory identity
Enroll with a machine token's code from the Burrow's Machine tokens page. The key stays in memory and nothing is written to disk. The code carries the Burrow's address and certificate trust.
await using var burrow = Burrow.Enroll(Environment.GetEnvironmentVariable("BURROW_ENROLL_CODE")!);
var db = await burrow.GetSecretAsync("payments/prod/DATABASE");
- The machine enrolls on the first read and renews itself with the same code before it expires.
Burrow.Open()enrolls fromBURROW_ENROLL_CODEwhen the host has no identity under~/.burrow.CloseAsync()or disposing the client ends the machine at once, so it shows as expired on the Burrow.- Only a machine token's code works here. A one-time invitation is refused.
OIDC
using var burrow = Burrow.Oidc(
burrowUrl: "https://burrow.example.com",
fingerprint: Environment.GetEnvironmentVariable("BURROW_FINGERPRINT")); // omit for a publicly-trusted certificate
var apiKey = (await burrow.GetSecretAsync("payments/prod/API_KEY")).Value;
audience defaults to burrowUrl. GitHub Actions requires permissions: id-token: write. GitLab CI/CD (gitlab.com) requires the job to declare its token as RATEL_ID_TOKEN:
id_tokens:
RATEL_ID_TOKEN:
aud: https://burrow.example.com
Bitbucket Pipelines requires the step to list the Burrow as an OIDC audience:
- step:
oidc:
audiences:
- https://burrow.example.com
Certificate trust
using var burrow = Burrow.Open(tls: TlsMode.SystemTrust);
Without an explicit tls, the SDK uses the trust chosen when the machine was added: encrypted by default (works everywhere), or verified against the Burrow's own key or a CA if that was selected.
TlsMode.Pinned: trust-on-first-use, stored at~/.burrow/burrows/<slug>/known_cert.TlsMode.PinnedTo("aa:bb:..."): a fixed fingerprint (from the Burrow's network settings).TlsMode.SystemTrust: CA and hostname verification, for a Burrow on a custom domain or Let's Encrypt.TlsMode.Insecure: no verification; accepts any certificate. Opt-in only, for a network you already trust. Shortcut:Burrow.Open().InsecureTls().
Webhooks
Verify a delivery from a Burrow's Signed webhook. Needs only the webhook's signing secret, not a machine identity.
app.MapPost("/hooks/burrow", async (HttpRequest request) =>
{
using var body = new MemoryStream();
await request.Body.CopyToAsync(body);
var e = BurrowWebhooks.Verify(body.ToArray(), request.Headers[BurrowWebhooks.SignatureHeader],
Environment.GetEnvironmentVariable("BURROW_WEBHOOK_SECRET")!);
Console.WriteLine($"{e.Event} {e.Data.Summary}");
return Results.NoContent();
});
Pass the raw body, before JSON parsing. A retry of the same event carries the same e.Id, so keep the ids you've handled to ignore repeats.
Errors
Every failure is a BurrowException: BurrowAuthException (401), BurrowForbiddenException (403, no grant),
BurrowNotFoundException (404), BurrowServerException (5xx, or 409 when a secret refuses the request),
BurrowCertificateException (pin mismatch),
BurrowTransportException (unreachable or unparsable), BurrowIdentityException (no, ambiguous or invalid
identity), plus two projection errors on the result: SecretShapeException (e.g. Value on a structured
secret) and FieldNotFoundException. The message carries the Burrow's own reason. BurrowWebhooks.Verify
throws BurrowWebhookException for a missing or wrong signature.
| 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
- BouncyCastle.Cryptography (>= 2.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.