Skip to content

Developer Guide

Using the library, authoring shims, and extending providers.

The crate is not published on crates.io. This example pins a public source revision; it does not require a local KeyRack checkout. Add these dependencies to Cargo.toml and copy a complete Rust example below into src/main.rs. CI compiles and runs these exact blocks.

[dependencies]
keyrack-core = { git = "https://github.com/KeyRack-io/keyrack.git", rev = "70bf446def1cac32881e5e24d36f653551cdc25f" }
tokio = { version = "1", features = ["macros", "rt"] }
use keyrack_core::key::KeySpec;
use keyrack_core::provider::software::SoftwareProvider;
use keyrack_core::provider::CryptoProvider;
#[tokio::main(flavor = "current_thread")]
async fn main() -> keyrack_core::error::Result<()> {
// Development only: this provider loses its keys when the process exits.
let provider = SoftwareProvider::new();
let key = provider.generate_key(&KeySpec::Aes256).await?;
let plaintext = b"secret data";
let aad = b"example context";
let ct = provider.encrypt(&key, plaintext, aad).await?;
let pt = provider.decrypt(&key, &ct.ciphertext, aad).await?;
assert_eq!(pt.expose().as_slice(), plaintext);
Ok(())
}

Swap in Pkcs11Provider or KmipProvider for HSM-backed production.

use keyrack_core::resolver::{resolve_chain, ResolverConfig};
use keyrack_core::rule::RuleRegistry;
use std::collections::BTreeMap;
fn main() -> keyrack_core::error::Result<()> {
let yaml = r#"
namespaces:
- name: example
routing_rules:
- match_pattern: { kind: dek, user: "$user" }
parent: { kind: root }
- match_pattern: { kind: root }
parent: null
"#;
let registry = RuleRegistry::from_yaml(yaml)?;
let attrs = BTreeMap::from([
("kind".to_owned(), "dek".to_owned()),
("user".to_owned(), "alice".to_owned()),
]);
// Computes logical identities only; does not provision or wrap keys.
let chain = resolve_chain(&registry, &attrs, &ResolverConfig::default())?;
assert_eq!(chain.len(), 2); // [leaf_lid, root_lid]
Ok(())
}

Implement the CryptoProvider trait to add new backends. Existing providers:

  • keyrack-pkcs11 — PKCS#11 HSM
  • keyrack-kmip — KMIP client
  • keyrack-vault — HashiCorp Vault Transit

The keyrack-wasm crate compiles to WebAssembly for browser use. No published npm package yet — see TypeScript use case.

This version snapshot comes from KeyRack source commit e25310da1e0a. The table is generated from the same operation inventory checked by the public source gate.

This table enumerates KeyService RPCs and registered REST routes in the default build. It describes availability, not identical request fields or behavior. Existing cross-interface lifecycle tests check semantics separately.

crypto-endpoints is enabled by default. Rows marked crypto feature lose the REST route and return gRPC UNIMPLEMENTED when that feature is disabled. Export and import are not controlled by that feature.

RPCgRPCREST method and pathScope / gap reason
AcknowledgeRotationJobHandler available—Existing REST gap: Rotation-job coordination is exposed by this gRPC handler; the REST facade has no corresponding route.
CancelKeyDeletionHandler availablePOST /v1/keys/:key_id/actions-cancel-deletion
CompleteRotationJobHandler available—Existing REST gap: Rotation-job coordination is exposed by this gRPC handler; the REST facade has no corresponding route.
CreateAliasHandler availablePOST /v1/aliases
CreateHsmConnectionHandler available—Existing REST gap: HSM connection administration is exposed by this gRPC handler; the REST facade has no corresponding route.
CreateKeyHandler availablePOST /v1/keys
DecryptHandler availablePOST /v1/keys/:key_id/actions-decryptcrypto feature.
DeleteAliasHandler availableDELETE /v1/aliases/:alias_name
DeleteHsmConnectionHandler available—Existing REST gap: HSM connection administration is exposed by this gRPC handler; the REST facade has no corresponding route.
DescribeKeyHandler availableGET /v1/keys/:key_id/describe
DescribeNamespaceDeclared stub; see limitation—Unimplemented namespace registry: The handler always returns NotFound; the namespace registry is not implemented.
DisableKeyHandler availablePOST /v1/keys/:key_id/actions-disable
DisableKeyRotationHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
EnableKeyHandler availablePOST /v1/keys/:key_id/actions-enable
EnableKeyRotationHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
EncryptHandler availablePOST /v1/keys/:key_id/actions-encryptcrypto feature.
ExplainRoutingHandler availablePOST /v1/routing/explain
FailRotationJobHandler available—Existing REST gap: Rotation-job coordination is exposed by this gRPC handler; the REST facade has no corresponding route.
GenerateDataKeyHandler availablePOST /v1/keys/:key_id/actions-generate-data-keycrypto feature.
GenerateDataKeyWithoutPlaintextHandler available—crypto feature. Existing REST gap: The REST GenerateDataKey operation always returns plaintext; no REST operation suppresses it. Use this gRPC RPC for ciphertext-only data keys.
GenerateMacHandler availablePOST /v1/keys/:key_id/actions-generate-maccrypto feature.
GenerateRandomHandler availablePOST /v1/generate-randomcrypto feature.
GetHsmConnectionHandler available—Existing REST gap: HSM connection administration is exposed by this gRPC handler; the REST facade has no corresponding route.
GetHsmConnectionStatusHandler available—Existing REST gap: HSM connection administration is exposed by this gRPC handler; the REST facade has no corresponding route.
GetKeyHandler availableGET /v1/keys/:key_id
GetKeyAncestorsHandler available—Existing REST gap: Ancestor traversal has a gRPC handler and no REST route.
GetKeyDependentsHandler available—Existing REST gap: Dependent-key traversal has a gRPC handler and no REST route.
GetKeyMaterialHandler available—Intentional gap: The 0.4.0 exportability API intentionally exposes this operation only through gRPC (CHANGELOG: key export API, gRPC only).
GetKeyRotationHistoryHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
GetKeyRotationPolicyHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
GetKeyRotationStatusHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
GetKeyVersionHandler available—Existing REST gap: Version-specific retrieval has a gRPC handler and no REST route.
ImportKeyHandler availablePOST /v1/keys/import
ListAliasesHandler availableGET /v1/aliases
ListHsmConnectionsHandler available—Existing REST gap: HSM connection administration is exposed by this gRPC handler; the REST facade has no corresponding route.
ListKeyVersionsHandler available—Existing REST gap: Dedicated version listing is available through gRPC; REST metadata embeds versions but has no equivalent list operation.
ListKeysHandler availableGET /v1/keys
ListNamespacesDeclared stub; see limitation—Unimplemented namespace registry: The handler always returns an empty list; the namespace registry is not implemented.
ListResourceTagsHandler availableGET /v1/keys/:key_id/tags
ListRotationJobsHandler available—Existing REST gap: Rotation-job coordination is exposed by this gRPC handler; the REST facade has no corresponding route.
MakeKeyExportableHandler available—Intentional gap: The 0.4.0 exportability API intentionally exposes this operation only through gRPC (CHANGELOG: key export API, gRPC only).
ReEncryptHandler availablePOST /v1/keys/:key_id/actions-re-encryptcrypto feature.
RegisterNamespaceDeclared stub; see limitation—Unimplemented namespace registry: The handler logs and echoes the name without storing a namespace. The namespace registry is not implemented.
ReportKeyCompromiseHandler availablePOST /v1/keys/:key_id/actions-report-compromise
RevokeKeyExportabilityHandler available—Intentional gap: The 0.4.0 exportability API intentionally exposes this operation only through gRPC (CHANGELOG: key export API, gRPC only).
RotateKeyHandler availablePOST /v1/keys/:key_id/actions-rotate
ScheduleKeyDeletionHandler availablePOST /v1/keys/:key_id/actions-schedule-deletion
SetKeyRotationPolicyHandler available—Existing REST gap: Rotation settings/history are exposed by this gRPC handler; the REST facade has no corresponding route.
SignHandler availablePOST /v1/keys/:key_id/actions-signcrypto feature.
TagResourceHandler availablePOST /v1/keys/:key_id/tags
UntagResourceHandler availableDELETE /v1/keys/:key_id/tags
UpdateKeyHandler availablePUT /v1/keys/:key_id
VerifyHandler availablePOST /v1/keys/:key_id/actions-verifycrypto feature.
VerifyMacHandler availablePOST /v1/keys/:key_id/actions-verify-maccrypto feature.
REST method and pathReason
GET /healthzHTTP health metadata endpoint; no corresponding KeyService RPC.
GET /metricsPrometheus HTTP scrape endpoint; no corresponding KeyService RPC.
GET /readyzHTTP readiness probe for storage and provider access; no corresponding KeyService RPC.

keyrack.v1.PdpService (Authorize, BatchAuthorize, ExplainAuthorization): This is the external PDP protocol consumed by the service, not a service registered on its northbound listener.

REST authentication also depends on deployment configuration. With the peer-certificate-only mTLS authenticator, authenticated REST operations return 501 AuthenticationTransportUnsupported; the table does not claim that a registered route supplies that identity transport.

CrateRole
keyrack-coreTypes, traits, providers, audit
keyrack-servicegRPC + REST service binary
keyrack-cedar-pdpStandalone Cedar PDP
keyrack-cliLint, provision, migrate, admin

The complete developer guide lives in the keyrack-oss repository.

See also: Operator guide · Security model