CLI client for FastPKI — API-based PKI management
Project description
FastPKI
FastPKI is an API-based PKI management system that provides an easier alternative to Easy-RSA. It allows you to create and manage Certificate Authorities, issue certificates, and revoke them through a RESTful API.
Features
- Create and manage Certificate Authorities (CAs)
- Intermediate CA hierarchy with path length constraints
- Automatic
allow_leaf_certspolicy enforcement - Issue certificates (server, client, and CA)
- Revoke certificates
- Organization management for multi-tenant deployments
- Role-based access control (SUPERUSER, ADMIN, USER)
- Per-user capability flags for fine-grained permissions
- Ownership-based access control on CAs and certificates
- RESTful API for easy integration
- Compatible with SQLite and PostgreSQL
- Database migrations with Alembic
- Docker support for easy deployment
- Type checking with mypy
- Code quality with ruff linter and formatter
Requirements
- Python 3.9+
- FastAPI
- SQLModel
- Cryptography
- Docker (optional)
Quick Start
Using the Container Image
Pre-built images are available on GitHub Container Registry:
docker pull ghcr.io/jsenecal/fastpki:latest
Available tags:
latest— Latest release<version>— Specific release (e.g.0.1.0)master— Latest build from master branch
Using Docker Compose
# Clone the repository
git clone https://github.com/jsenecal/fastpki.git
cd fastpki
# Create a .env file from the example
cp .env.example .env
# Create data directory for SQLite database
mkdir -p data
# Development mode with SQLite (recommended for local development)
docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml up -d
For production deployments with PostgreSQL:
# Production mode with PostgreSQL
docker-compose -f docker/docker-compose.yml -f docker/docker-compose.prod.yml up -d
The API will be available at http://localhost:8000
Local Development
# Clone the repository
git clone https://github.com/jsenecal/fastpki.git
cd fastpki
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies with uv (faster)
uv pip install -e ".[dev]"
# Create a .env file from the example
cp .env.example .env
# Create data directory for SQLite database
mkdir -p data
# Run the application
uvicorn app.main:app --reload
Development
Code Quality
We use the following tools to ensure code quality:
- ruff: Fast Python linter and formatter
- mypy: Static type checker
Run linting and type checking:
# Using make
make lint
# Or directly
ruff check app tests
mypy app
Format code:
# Using make
make format
# Or directly
ruff format app tests
Pre-commit Hooks
Install pre-commit hooks to automatically check your code before committing:
pre-commit install
API Documentation
When the application is running, you can access the automatic API documentation at:
- Swagger UI: http://localhost:8000/api/v1/docs
- ReDoc: http://localhost:8000/api/v1/redoc
Authentication, Authorization & Permissions
User Roles
FastPKI has three user roles:
- SUPERUSER — Full access to all resources across the system
- ADMIN — Full access to all resources within their organization
- USER — Read access within their organization; write actions require capability flags
Permission Hierarchy
Permission checks follow this order:
- Superusers have full access to everything
- Resource creators have full access to their own resources
- Admins have full access to all resources within their organization
- Users can read resources within their organization
- Per-user capability flags grant specific write actions to regular users
Capability Flags
Regular users can be granted fine-grained permissions via boolean capability flags:
| Flag | Description |
|---|---|
can_create_ca |
Create Certificate Authorities |
can_create_cert |
Create certificates |
can_revoke_cert |
Revoke certificates |
can_export_private_key |
Export private keys |
can_delete_ca |
Delete Certificate Authorities |
First User Creation
FastPKI implements a first-user privilege system for initial setup:
-
The first user created in the system can be assigned any role, including
superuser. This is a bootstrap mechanism that allows for the initial setup of the system. -
After the first user is created, only existing superusers can create other users with elevated privileges (
adminorsuperuserroles). -
Regular users can only create other regular users.
To create the first superuser:
# Make a POST request to create the first user with superuser role
curl -X POST http://localhost:8000/api/v1/users/ \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"email": "admin@example.com",
"password": "securepassword",
"role": "superuser"
}'
This first superuser can then authenticate and manage other users through the API.
Database Support
FastPKI supports both SQLite and PostgreSQL:
-
SQLite (default for development):
- Data is stored in the
data/fastpki.dbfile for persistence - Uses the aiosqlite driver for async support
- Connection string:
sqlite+aiosqlite:///./data/fastpki.db
- Data is stored in the
-
PostgreSQL (recommended for production):
- Uses the asyncpg driver for async support
- Connection string:
postgresql+asyncpg://postgres:postgres@db:5432/fastpki - Configure using the
DATABASE_URLenvironment variable
Project Structure
/alembic # Database migrations
/app # Main application code
/api # API endpoints
/core # Core configuration
/db # Database models and session management
/schemas # Pydantic schemas for API requests/responses
/services # Business logic (CA, certificate, user, organization, permission)
/tests # Test suite (279 tests, 90% coverage)
/docker # Docker configuration
/data # SQLite database files and other persistent data
Testing
The test suite includes 279 tests with 90% code coverage. Tests are written using pytest:
# Run tests (using make)
make test
# Run tests with coverage
make test-cov
# Or directly
pytest
pytest --cov=app
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastpki-0.3.1.tar.gz.
File metadata
- Download URL: fastpki-0.3.1.tar.gz
- Upload date:
- Size: 227.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93ad99a94ffcd8e1bf49946f23273901b5d29e5967047319b1dbf8e7cac649bc
|
|
| MD5 |
5e5fd2fdce3f98ddf1446d0194553cfa
|
|
| BLAKE2b-256 |
4e944521eaf38afe15deaa9dec7bef99d33bf7935b4f1aa53a0764c2f9f582e1
|
Provenance
The following attestation bundles were made for fastpki-0.3.1.tar.gz:
Publisher:
ci.yml on jsenecal/fastpki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastpki-0.3.1.tar.gz -
Subject digest:
93ad99a94ffcd8e1bf49946f23273901b5d29e5967047319b1dbf8e7cac649bc - Sigstore transparency entry: 1292339330
- Sigstore integration time:
-
Permalink:
jsenecal/fastpki@914dd6337bb198aeec9cbe9317ceb2b6416c2166 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/jsenecal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@914dd6337bb198aeec9cbe9317ceb2b6416c2166 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastpki-0.3.1-py3-none-any.whl.
File metadata
- Download URL: fastpki-0.3.1-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
905c1c1ffce9ecae1bebccc778760ac2a8b935ae7deb2b25c06336689a406604
|
|
| MD5 |
b8151cd14abdeebb8f081f94a772bf24
|
|
| BLAKE2b-256 |
cbcbcbc2ec8dd5aefe372821b0c9b3685c3dddabe1e33ba7edbcd071b8fb94f4
|
Provenance
The following attestation bundles were made for fastpki-0.3.1-py3-none-any.whl:
Publisher:
ci.yml on jsenecal/fastpki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastpki-0.3.1-py3-none-any.whl -
Subject digest:
905c1c1ffce9ecae1bebccc778760ac2a8b935ae7deb2b25c06336689a406604 - Sigstore transparency entry: 1292339428
- Sigstore integration time:
-
Permalink:
jsenecal/fastpki@914dd6337bb198aeec9cbe9317ceb2b6416c2166 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/jsenecal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@914dd6337bb198aeec9cbe9317ceb2b6416c2166 -
Trigger Event:
release
-
Statement type: