Skip to main content

ninja-level deployments designed to simplify infrastructure management and automate common tasks

Project description

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.

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

infraninja-0.5.0.tar.gz (114.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infraninja-0.5.0-py3-none-any.whl (183.2 kB view details)

Uploaded Python 3

File details

Details for the file infraninja-0.5.0.tar.gz.

File metadata

  • Download URL: infraninja-0.5.0.tar.gz
  • Upload date:
  • Size: 114.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for infraninja-0.5.0.tar.gz
Algorithm Hash digest
SHA256 51902b4db8b0608cf5294b681b96671f8398f68c0d231d2b81141e1f2b82e42c
MD5 cb1291f61f0f65cdbabf5b27cf87e338
BLAKE2b-256 5f7d0b6407067603580febc72d09b48d8b71a6582fb90a1d6594d5a92e727823

See more details on using hashes here.

File details

Details for the file infraninja-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: infraninja-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 183.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for infraninja-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6515e1ceb95d09ce075ab9bd762677b78876415fd4d2594ef07709eba97d1e2
MD5 2a412fe9c99f76289f95a10dd262bdc6
BLAKE2b-256 36828f573e27848c5c9940e3ac4a33a5560bfc0208aa71df1610ea2334b1bdff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page