| Crates.io | hessra_authz |
| lib.rs | hessra_authz |
| version | 0.3.1 |
| created_at | 2025-05-19 18:58:30.011051+00 |
| updated_at | 2025-08-04 21:21:04.589173+00 |
| description | Postgres Authorization with Local Biscuit Verification — by Hessra |
| homepage | |
| repository | https://github.com/Hessra-Labs/hessra-sdk.rs |
| max_upload_size | |
| id | 1680268 |
| size | 109,524 |
A PostgreSQL extension for authorization and token verification using Biscuit tokens, built with pgrx.
The hessra_authz extension provides a lightweight, secure way to manage and verify authorization tokens issued from the Hessra authorization service directly within PostgreSQL. It supports:
This extension is ideal for applications that use PostgreSQL and need to perform token-based authorization checks directly in database queries.
On macOS, set the following environment variables:
export MACOSX_DEPLOYMENT_TARGET=15.4
export PKG_CONFIG_PATH=/opt/homebrew/opt/icu4c/lib/pkgconfig
Consider adding these to your ~/.zshrc or ~/.bashrc for persistent setup.
cargo install cargo-pgrx
cargo pgrx init
cargo pgrx install --package hessra_authz
CREATE EXTENSION hessra_authz;
-- Add a public key (last parameter sets it as the default key)
SELECT add_public_key('my_key', '-----BEGIN PUBLIC KEY-----\n...', true);
-- Retrieve a key
SELECT get_public_key('my_key');
-- Get the default key
SELECT get_public_key(NULL);
-- Update a key
SELECT update_public_key('my_key', '-----BEGIN PUBLIC KEY-----\n...', false);
-- Delete a key
SELECT delete_public_key('my_key');
-- Add a service chain
SELECT add_service_chain('payment_flow', '[
{
"component": "auth_service",
"public_key": "ed25519/0123456789abcdef0123456789abcdef"
},
{
"component": "payment_service",
"public_key": "ed25519/fedcba9876543210fedcba9876543210"
}
]');
-- Retrieve a service chain
SELECT get_service_chain('payment_flow');
-- Update a service chain
SELECT update_service_chain('payment_flow', '[...]');
-- Delete a service chain
SELECT delete_service_chain('payment_flow');
-- Verify a token directly
SELECT verify_token(
'biscuit_token_string',
'-----BEGIN PUBLIC KEY-----\n...',
'subject',
'resource',
'operation',
NULL
);
-- Verify a token using a stored key
SELECT verify_token_with_stored_key(
'biscuit_token_string',
'my_key', -- Optional, uses default key if NULL
'subject',
'resource_path',
'operation',
NULL
);
-- Create a policy that uses token verification
CREATE POLICY user_data_policy ON user_data
USING (
verify_token_with_stored_key(
current_setting('app.auth_token', true),
NULL, -- Use default key
user_id::text,
'user_data/' || id::text,
'create',
NULL
) IS NULL -- Successful verification returns NULL
);
-- Enable row-level security
ALTER TABLE user_data ENABLE ROW LEVEL SECURITY;
cargo pgrx test --package hessra_authz
cargo pgrx run --package hessra_authz
Biscuit is an authorization token format built for microservices and distributed systems:
This extension integrates with the Biscuit token format to enable secure, decentralized authorization directly within PostgreSQL.
This project is licensed under the Apache-2.0 License.