Skip to content

๐ŸŽŒ TORII (้ณฅๅฑ…) - The Ultimate Git Control Plane. Policy-driven governance for Git at scale. Zero-trust enforcement, multi-tenancy, and comprehensive audit trails. Built in Rust.

License

Notifications You must be signed in to change notification settings

copyleftdev/torii

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TORII ้ณฅๅฑ…

TORII Logo

The Ultimate Git Control Plane

ๅฎˆ่ญท่€…ใฎ้–€ - Guardian of the Gate

Rust Tests License GitHub Stars GitHub Issues


๐ŸŽŒ Philosophy

"Just as the sacred torii gate marks the boundary between the mundane and the divine, TORII stands as the guardian between chaos and order in your Git infrastructure."

TORII embodies three core principles:

  • ๐Ÿ›ก๏ธ Zero Trust - Every operation is validated, no exceptions
  • ๐Ÿ“œ Policy as Code - Governance defined in version-controlled YAML
  • โšก Git-Native - Enforcement at the protocol level, not post-facto

๐Ÿ“– What is TORII?

TORII is a production-ready Git Control Plane built in Rust that enforces policy-driven governance for Git operations. Unlike traditional Git hosting solutions that rely on webhooks and post-receive validation, TORII intercepts operations at the pre-receive stage, providing true zero-trust enforcement.

Why TORII?

Modern enterprises face critical challenges with Git governance:

  • โŒ No Central Control - Teams push directly to production branches
  • โŒ Post-Facto Validation - Webhooks catch violations too late
  • โŒ Inconsistent Policies - Rules differ across repositories
  • โŒ Audit Gaps - No comprehensive record of who did what

TORII solves these problems by acting as a policy enforcement point for all Git operations.


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         TORII Ecosystem                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                     โ”‚
โ”‚  Developer              Admin Interface          CI/CD System      โ”‚
โ”‚      โ”‚                        โ”‚                        โ”‚           โ”‚
โ”‚      โ”‚ git push              โ”‚ manage policies        โ”‚           โ”‚
โ”‚      โ–ผ                        โ–ผ                        โ–ผ           โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚  SSH   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚  torii-  โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚  HTTP   โ”‚       โ”‚
โ”‚  โ”‚ (Port  โ”‚            โ”‚  server  โ”‚             โ”‚  API    โ”‚       โ”‚
โ”‚  โ”‚  22)   โ”‚            โ”‚ :3000    โ”‚             โ”‚         โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜            โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚       โ”‚                      โ”‚                                     โ”‚
โ”‚       โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚       โ”‚ โ”‚  Control Plane     โ”‚                     โ”‚              โ”‚
โ”‚       โ”‚ โ”‚                    โ–ผ                     โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”‚  Policy Engine   โ”‚           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”‚  (torii-core)    โ”‚           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚                   โ”‚                     โ”‚              โ”‚
โ”‚       โ”‚ โ”‚                   โ–ผ                     โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”‚  Storage Layer   โ”‚           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ”‚  SQLite/Postgres โ”‚           โ”‚              โ”‚
โ”‚       โ”‚ โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚              โ”‚
โ”‚       โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚       โ”‚                                                            โ”‚
โ”‚       โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚       โ”‚ โ”‚  Enforcement Layer                       โ”‚              โ”‚
โ”‚       โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚       โ”‚                                                            โ”‚
โ”‚       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ  torii-hook (pre-receive)                      โ”‚
โ”‚                    โ”œโ”€ Validates refs                              โ”‚
โ”‚                    โ”œโ”€ Checks policies                             โ”‚
โ”‚                    โ””โ”€ Allows/Denies push                          โ”‚
โ”‚                                                                     โ”‚
โ”‚  Authentication: torii-auth โ—€โ”€โ”€โ”€โ”€ sshd (AuthorizedKeysCommand)   โ”‚
โ”‚                                                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Key Features

๐Ÿ›ก๏ธ Policy-Driven Enforcement

Define governance rules as declarative YAML policies:

apiVersion: torii.io/v1beta1
kind: RepositoryPolicy
metadata:
  name: "protect-production"
spec:
  defaultAction: "deny"
  rules:
    - name: "senior-engineers-only"
      scope:
        refs: ["refs/heads/main", "refs/heads/production"]
      conditions:
        - field: "actor.group"
          operator: "in"
          value: ["senior-engineers", "platform-team"]
      decision: "allow"

๐Ÿ” Real SSH Authentication

  • Integrated with OpenSSH's AuthorizedKeysCommand
  • Automatic identity injection via environment variables
  • No custom Git clients required

๐Ÿ’พ Multi-Database Support

  • SQLite - Perfect for edge deployments and single-node setups
  • PostgreSQL - Production-grade for multi-node clusters

โšก High Performance

  • Written in Rust for memory safety and speed
  • Async/await for concurrent request handling
  • Zero-copy policy evaluation

๐Ÿงช Production Ready

  • Comprehensive E2E test suite with Testcontainers
  • Docker support for Postgres integration tests
  • CI/CD validated across multiple database backends

๐ŸŽฏ Use Cases

1. Enterprise Branch Protection

Problem: Developers accidentally push to production branches.

Solution: TORII enforces strict branch policies at the Git protocol level.

# Only allow releases from CI/CD
- name: "production-from-ci-only"
  scope:
    refs: ["refs/heads/production"]
  conditions:
    - field: "actor.type"
      operator: "equals"
      value: "service-account"
  decision: "allow"

2. Multi-Tenant Platforms

Problem: SaaS platforms need to isolate customer repositories.

Solution: Dynamic policies per repository with tenant-specific rules.

# Tenant isolation
- name: "tenant-a-only"
  conditions:
    - field: "actor.tenant_id"
      operator: "equals"
      value: "tenant-a"
  decision: "allow"

3. Compliance & Audit

Problem: Financial institutions require immutable audit trails.

Solution: TORII logs every Git operation with policy decisions.

# Query audit logs
SELECT * FROM audit_log 
WHERE repository_id = 'trading-system' 
  AND action = 'git-receive-pack' 
  AND timestamp > NOW() - INTERVAL '7 days';

4. Secure CI/CD Pipelines

Problem: Pull requests bypass security checks via force-push.

Solution: Enforce linear history and required checks.

- name: "no-force-push"
  conditions:
    - field: "ref_update.forced"
      operator: "equals"
      value: "true"
  decision: "deny"

๐Ÿš€ Quick Start

Prerequisites

  • Rust 1.70+ (rustup)
  • PostgreSQL or SQLite
  • OpenSSH (for SSH auth)

Installation

# Clone the repository
git clone https://github.com/copyleftdev/torii.git
cd torii

# Build all components
cargo build --release

# Binaries are in target/release/
ls target/release/torii-*

1. Start the Server

# With SQLite (development)
TORII_DB_URL="sqlite:///tmp/torii.db" \
  cargo run -p torii-server

# With PostgreSQL (production)
TORII_DB_URL="postgres://user:pass@localhost/torii" \
  cargo run -p torii-server

Server will start on http://localhost:3000

2. Create Your First Policy

# Create a policy file
cat > policy.yaml <<EOF
apiVersion: torii.io/v1beta1
kind: RepositoryPolicy
metadata:
  name: "basic-protection"
  description: "Protect main branch"
spec:
  defaultAction: "allow"
  rules:
    - name: "protect-main"
      scope:
        refs: ["refs/heads/main"]
      conditions: []
      decision: "deny"
EOF

# Apply the policy
./target/release/torii-cli policy apply -f policy.yaml

3. Create and Configure a Repository

# Create repository
./target/release/torii-cli repo create \
  --name "my-app" \
  --owner "platform-team"

# Bind policy to repository
./target/release/torii-cli binding add \
  --repo "my-app" \
  --policy "basic-protection"

4. Install Git Hook

# In your bare Git repository
cd /path/to/my-app.git

# Install pre-receive hook
ln -s /path/to/torii/target/release/torii-hook \
  hooks/pre-receive

# Make it executable
chmod +x hooks/pre-receive

# Configure environment
export TORII_REPO_ID="my-app"
export TORII_CONTROL_PLANE="http://localhost:3000"

5. Test It!

# Try to push to main (should be denied)
cd /tmp
git clone /path/to/my-app.git
cd my-app
git checkout -b main
echo "test" > README.md
git commit -am "test"

# Set actor identity
export TORII_ACTOR_ID="alice"

git push origin main
# โŒ Denied by policy 'basic-protection'

๐Ÿ”ง Configuration

Environment Variables

Variable Description Default
TORII_DB_URL Database connection string sqlite::memory:
TORII_CONTROL_PLANE API endpoint for hooks http://localhost:3000
TORII_REPO_ID Repository identifier (required)
TORII_ACTOR_ID User identifier (from SSH env)
RUST_LOG Log level info

SSH Integration

Add to /etc/ssh/sshd_config:

AuthorizedKeysCommand /usr/local/bin/torii-auth
AuthorizedKeysCommandUser git
PermitUserEnvironment TORII_ACTOR_ID

๐Ÿ“ฆ Components

Crate Purpose Lines of Code
torii-core Domain models, policy engine ~600
torii-server Control Plane API & web service ~400
torii-storage Persistence (SQLite/Postgres) ~500
torii-hook Git pre-receive enforcement ~150
torii-cli Administrative CLI ~250
torii-auth SSH key resolver ~50
torii-e2e End-to-end tests ~200

Total: ~2,150 lines of Rust (excluding tests)


๐Ÿงช Testing

# Run all tests
cargo test --workspace

# Run E2E tests (requires Docker)
cargo test -p torii-e2e

# Run with coverage
cargo tarpaulin --workspace

# Integration tests only
cargo test -p torii-storage

Test Coverage: 85%+ across critical paths


๐Ÿ›ฃ๏ธ Roadmap

  • Phase 1-4: Core Policy Engine & Server
  • Phase 5: Persistent Storage (SQLite)
  • Phase 6: Management CLI
  • Phase 7: SSH Authentication
  • Phase 8: E2E Testing (PostgreSQL)
  • Phase 9: Event Plane (AsyncAPI webhooks)
  • Phase 10: Observability (Prometheus metrics)
  • Phase 11: HA Deployment (Kubernetes)
  • Phase 12: Web UI Dashboard

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Clone and build
git clone https://github.com/copyleftdev/torii.git
cd torii
cargo build

# Run tests
cargo test

# Check formatting
cargo fmt --check

# Run linter
cargo clippy

๐Ÿ“„ License

MIT License - see LICENSE for details.


๐Ÿ™ Acknowledgments

Inspired by:


Built with โค๏ธ and โš™๏ธ in Rust

"ๅฎˆ่ญท่€…ใฎ้–€" - Guardian of the Gate

Documentation โ€ข Architecture โ€ข API Spec โ€ข Roadmap

About

๐ŸŽŒ TORII (้ณฅๅฑ…) - The Ultimate Git Control Plane. Policy-driven governance for Git at scale. Zero-trust enforcement, multi-tenancy, and comprehensive audit trails. Built in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages