Skip to main content

InfraNinja

A modern infrastructure automation framework built on PyInfra, providing reusable deployment tasks used by Kalvad teams and made publicly available via PyPI.

InfraNinja simplifies infrastructure management through Actions (reusable deployment tasks), Facts (read-only server information gathering), and Inventories (dynamic server management).

Features

  • Action-Based Architecture: 26 pre-built actions covering security hardening, firewall setup, malware protection, auditing, and system maintenance
  • Composite Actions: Group related actions together (e.g. FullSecuritySetup runs 7 sub-actions in sequence)
  • Facts: Gather read-only server information (hardware specs, OS details) without making changes
  • Dynamic Inventories: Automated server discovery from Jinn API and Coolify
  • Multi-OS Support: Ubuntu, Debian, Alpine Linux, FreeBSD, RHEL, CentOS, Fedora, and Arch Linux
  • Multilingual: Actions support English, Arabic, and French metadata
  • Compliance: UAE IA compliance modules and security auditing tools (Lynis, Auditd)

Getting Started

Requirements: Python 3.10+

pip install infraninja

Or using uv:

uv add infraninja

Quick Examples

Using Actions

from infraninja import SSHHardening, UpdateAndUpgrade

# Update system packages
UpdateAndUpgrade().execute()

# Harden SSH with custom settings
SSHHardening(permit_root_login="no").execute()

Composite Actions

from infraninja import FullSecuritySetup

# Run full security setup (updates, packages, hardening, firewall, fail2ban, malware, audit)
result = FullSecuritySetup().execute()

for action_result in result.results:
    print(f"  {action_result.action}: {'OK' if action_result.success else 'FAILED'}")

Gathering Facts

from infraninja import Hardware, SystemInfo

# Get hardware information
hw = Hardware()
hw.execute()

# Get system information
sys_info = SystemInfo()
sys_info.execute()

Using Inventories

from infraninja.inventories import Jinn, Coolify

# Jinn API integration
jinn = Jinn(
    api_url="https://jinn-api.kalvad.cloud",
    api_key="your-api-key",
    groups=["production", "web"],
    tags=["nginx", "database"]
)
servers = jinn.get_servers()

# Coolify integration
coolify = Coolify(
    api_url="https://coolify.example.com/api",
    api_key="your-api-key",
    tags=["prod", "staging"]
)
servers = coolify.get_servers()

Available Actions

Security & Hardening

Action Description
SSHHardening SSH server hardening with security best practices
KernelHardening Kernel security parameters via sysctl
DisableServices Disable unnecessary services to reduce attack surface
MediaAutorunProtection Disable media autorun
ARPProtection ARP poisoning protection
ACLSetup Access Control Lists for file permissions
SmtpHardening SMTP server hardening
AppArmorSetup AppArmor mandatory access control (Ubuntu/Debian)
NTPHardening NTP configuration hardening with security patches
RoutingControls Network routing controls (Ubuntu/Debian)

Firewall

Action Description
IPTablesSetup IPTables firewall rules
NFTablesSetup NFTables firewall rules
PFSetup PF packet filter (FreeBSD)

Intrusion Prevention & Malware Detection

Action Description
Fail2BanSetup Fail2Ban intrusion prevention
ChkrootkitSetup Chkrootkit rootkit detection
RkhunterSetup Rkhunter rootkit detection (FreeBSD)
ClamAVSetup ClamAV antivirus
SuricataSetup Suricata IDS/IPS

Auditing & Compliance

Action Description
AuditdSetup System auditing with auditd/BSM
LynisSetup Lynis security audit tool
UAEComplianceAudit UAE IA compliance audit (T3.6.3)

System & Packages

Action Description
UpdateAndUpgrade System package updates
SecurityPackageInstall Install security packages and tools
SSHKeys SSH key management and deployment
RedisAuthPatch Enable Redis authentication
RebootSystem Conditional system reboot

Composite Actions

Action Sub-Actions
SecurityHardening KernelHardening, SSHHardening, DisableServices, MediaAutorunProtection, ARPProtection
FirewallSetup IPTablesSetup, NFTablesSetup
MalwareProtection ChkrootkitSetup, RkhunterSetup, ClamAVSetup
SecurityAudit AuditdSetup, LynisSetup, UAEComplianceAudit
FullSecuritySetup UpdateAndUpgrade, SecurityPackageInstall, SecurityHardening, FirewallSetup, Fail2BanSetup, MalwareProtection, SecurityAudit
FullSetup UpdateAndUpgrade, SSHHardening, SSHKeys

Development

Setup

git clone https://github.com/KalvadTech/infraninja.git
cd infraninja
uv sync

Running Tests

uv run pytest

# With coverage
uv run pytest --cov=infraninja tests/

Building the Package

uv build

Building the Documentation

The documentation is generated from action/fact metadata using MkDocs:

# Install MkDocs and theme
pip install mkdocs mkdocs-material

# Regenerate docs from action metadata
python generate_docs.py

# Serve locally at http://127.0.0.1:8000
mkdocs serve

# Build static site to site/
mkdocs build

Contributions

Contributions are welcome! If you spot any bugs or have ideas for new features, feel free to open an issue or submit a pull request.

Maintainers

Community & Support

License

This project is licensed under the MIT License.

Metadata

Release files for infraninja 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infraninja 0.5.0
File Size Uploaded
infraninja-0.5.0.tar.gz 114.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for infraninja 0.5.0
File Interpreter ABI Platform
infraninja-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 298.1 kB

Release files / infraninja-0.5.0.tar.gz

Download URL infraninja-0.5.0.tar.gz
Size 114.9 kB
Tags Source
SHA-256 checksum
How to use checksums
51902b4db8b0608cf5294b681b96671f8398f68c0d231d2b81141e1f2b82e42c
BLAKE2b-256 checksum
How to use checksums
5f7d0b6407067603580febc72d09b48d8b71a6582fb90a1d6594d5a92e727823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / infraninja-0.5.0-py3-none-any.whl

Download URL infraninja-0.5.0-py3-none-any.whl
Size 183.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6515e1ceb95d09ce075ab9bd762677b78876415fd4d2594ef07709eba97d1e2
BLAKE2b-256 checksum
How to use checksums
36828f573e27848c5c9940e3ac4a33a5560bfc0208aa71df1610ea2334b1bdff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page