Security architecture
This page describes security mechanisms at the architectural level and how they fit into HieraChain. The scope of each check depends on the runtime path and caller integration.
Main security pillars
The defense is organized into six coordinated areas:
-
Authorization and access control:
hierachain/security/{msp.py, identity.py}manages organizations, users, roles and lightweight internal certificates.hierachain/security/policy_engine.pyhandles permission control (ABAC).hierachain/security/verify/api_key_verifier.pyhandles API key authentication.
-
Logging and integrity:
hierachain/security/secure_logging.pywrites structured JSON logs and masks sensitive named fields; it has no tamper-verification mechanism.hierachain/risk_management/audit_logger.pyrecords operational audit events and supports verification against a separately trusted manifest.
-
Fault tolerance and integrity:
hierachain/error_mitigation/{consensus_validator.py, resource_validator.py}andhierachain/cluster/lockdown_types.pyprovide validation, resource checks and HMAC lockdown. There is nosecurity/resource_guard.pyorsecurity/integrity.py; those paths were removed or never existed.
-
Input sanitization:
hierachain/security/sanitization.pyhelps prevent injection by neutralizing HTML/templates and enforcing a filename allowlist.
-
Encryption and keys:
hierachain/security/{key_manager.py, key_provider.py}andhierachain/security/msp.py(Certificate/CertificateAuthority) provide Ed25519 support andFileVaultProvider(Fernet/PBKDF2, dev only). There is nokey_backup_manager.pyorcertificate.pyand no mTLS.
-
Decentralized zero-knowledge proofs:
hierachain/security/zk_prover.pyandhierachain/security/verify/zk_verifier.pyprovide development mocks. Production ZK proving/verifying is unimplemented.
Authentication, CORS and rate limits are configured in hierachain/config/settings.py. HSTS settings are declared there but do not add an HTTP header; configure HSTS at the HTTPS reverse proxy.
System integration
- API Server (
hierachain/api/server.py) uses payload/rate-limit middleware,CORSMiddlewareandAPIKeyVerifierwhen authentication is enabled. There is no CPU/RAM guard on every request. - API-key authentication and scopes apply at HTTP handlers. Direct Python calls require a trusted caller and do not pass through HTTP middleware; domain/channel policies are checked by their respective paths.
- Secure logging:
security/secure_logging.pyandsecurity/sanitization.pyreduce leakage of sensitive data.
Related configuration (excerpt)
Variables in settings.py (all use the HRC_* prefix):
HRC_AUTH_ENABLED,HRC_API_KEY_LOCATION,HRC_API_KEY_NAMEHRC_CORS_ALLOW_ALL,HRC_CORS_ORIGINSHRC_HSTS_ENABLED,HRC_HSTS_MAX_AGEHRC_RATE_LIMIT,HRC_RATE_LIMIT_RPM,HRC_RATE_LIMIT_BACKEND,HRC_TRUSTED_PROXIES
Typical flow
sequenceDiagram
participant Client
participant API as FastAPI
participant Auth as APIKeyVerifier
participant Handler as Route handler
Client->>API: Request
API->>API: Payload/rate limits and CORS
API->>Auth: Verify API key when authentication enabled
Auth-->>API: Verified user or rejection
API->>Handler: Route permission and domain checks
Handler-->>Client: Result or error
- Payload/rate limits and API-key verification run at the API; scope/role checks depend on the route. Redis rate-limit errors return 503 for non-exempt requests.
- Signed blocks are verified against trusted keys. ZK checks apply when enabled; mocks do not prove business correctness.
Related
- Security Module: Security
- Config Reference: Config
- API Ledger: API Ledger