Skip to main content

Secure tool signing system for automatically adding project-specific tools to PATH

Project description

Signed Binary Directory

A secure tool signing system that automatically adds project-specific tools to your PATH when you navigate into directories. This ensures that only cryptographically signed and verified tools are executed, providing security against malicious scripts while maintaining convenience.

Features

  • ๐Ÿ” Cryptographic Signing: Uses your SSH private key to sign executable files
  • ๐Ÿ›ก๏ธ Automatic Verification: Verifies signatures before adding directories to PATH
  • ๐Ÿš Shell Integration: Works with both Fish and Bash shells
  • ๐Ÿ“ Hierarchical Discovery: Finds signed bin directories in current and parent directories
  • โšก Fast: Minimal overhead when changing directories
  • ๐Ÿ” Transparent: Optional notifications when signed tools are discovered
  • ๐Ÿ› ๏ธ Easy Setup: Automatic shell integration installer

Security Model

This tool uses your existing SSH key pair for signing and verification:

  • Signing: Uses your SSH private key (~/.ssh/id_rsa by default) to create cryptographic signatures
  • Verification: Uses the corresponding public key to verify signatures before trusting executables
  • Manifest: Creates a .signed-manifest.json file containing hashes and signatures of all executables
  • Trust: Only directories with valid signatures from your key are added to PATH

Installation

Install from PyPI

# Install the latest version from PyPI
pip install signed-bin-dir

# Or install in development mode from source
git clone https://github.com/igutekunst/signed-bin-dir.git
cd signed-bin-dir
pip install -e .

Shell Integration (Automatic)

The easiest way to set up shell integration:

# Auto-detect and install for all available shells
sign-bin-dir install

# Install for a specific shell
sign-bin-dir install --shell fish
sign-bin-dir install --shell bash

# Check installation status
sign-bin-dir status

# Uninstall if needed
sign-bin-dir uninstall --all

The shell integration files are automatically included with the pip package, so no additional setup is required.

Shell Integration (Manual)

If you prefer manual setup, you can find the integration files in your Python environment after installation:

# Find the integration files
python3 -c "import signed_bin_dir; from pathlib import Path; print(Path(signed_bin_dir.__file__).parent.parent / 'share' / 'signed-bin-dir' / 'shell_integrations')"

Fish Shell

Add to your ~/.config/fish/config.fish:

# Source the signed-bin-dir integration (adjust path as needed)
source /path/to/shell_integrations/signed_bin_dir.fish

Bash Shell

Add to your ~/.bashrc:

# Source the signed-bin-dir integration (adjust path as needed)
source /path/to/shell_integrations/signed_bin_dir.bash

Usage

Basic Workflow

  1. Create a bin directory in your project with executable tools
  2. Sign the directory using sign-bin-dir
  3. Navigate into the project - tools are automatically added to PATH
  4. Navigate away - tools are automatically removed from PATH

Command Line Interface

Shell Integration Management

# Check which shells are available and integration status
sign-bin-dir status

# Install integration for all detected shells
sign-bin-dir install

# Install for specific shell
sign-bin-dir install --shell fish

# Uninstall integration
sign-bin-dir uninstall --shell fish
sign-bin-dir uninstall --all

Sign a bin directory

# Sign all executables in a bin directory
sign-bin-dir sign ./bin

# Use a specific private key
sign-bin-dir sign ./bin --private-key ~/.ssh/my_key

# Verbose output
sign-bin-dir sign ./bin --verbose

Verify signatures

# Verify all signatures in a bin directory
sign-bin-dir verify ./bin

# Verify with verbose output
sign-bin-dir verify ./bin --verbose

List signed files

# List all signed files in a bin directory
sign-bin-dir list-files ./bin

Convenience Functions

The shell integrations provide helpful functions:

# Sign the bin directory in current project
sign-current-bin

# Verify the bin directory in current project
verify-current-bin

Example Project Structure

my-project/
โ”œโ”€โ”€ bin/
โ”‚   โ”œโ”€โ”€ my-tool
โ”‚   โ”œโ”€โ”€ deploy-script
โ”‚   โ””โ”€โ”€ .signed-manifest.json  # Created by sign-bin-dir
โ”œโ”€โ”€ src/
โ””โ”€โ”€ README.md

Quick Start

  1. Install the package:

    pip install signed-bin-dir
    
  2. Set up shell integration:

    sign-bin-dir install
    
  3. Restart your shell or source your config file

  4. Try with a project:

    mkdir my-project && cd my-project
    mkdir bin
    echo '#!/bin/bash\necho "Hello from my tool!"' > bin/my-tool
    chmod +x bin/my-tool
    sign-bin-dir sign bin
    my-tool    # Works!
    cd ..
    my-tool    # Command not found (removed from PATH)
    

How It Works

  1. Directory Change Detection: Shell hooks detect when you change directories
  2. Discovery: Searches current and parent directories for bin/ folders with .signed-manifest.json
  3. Verification: Validates signatures against your SSH public key
  4. PATH Management: Adds verified directories to PATH, removes them when you leave

Security Considerations

  • Key Security: Protect your SSH private key as it's used for signing
  • Trust Model: Only trust signatures from keys you control
  • Verification: Always verify signatures before executing tools
  • Isolation: Each project's tools are isolated and only available in that context

Configuration

Custom SSH Key

By default, the tool uses ~/.ssh/id_rsa. To use a different key:

sign-bin-dir sign ./bin --private-key ~/.ssh/my_project_key

Shell Integration Options

You can customize the shell integration behavior:

# In your Fish config, uncomment this line to show notifications
__signed_bin_dir_check_current

Development

Setup Development Environment

# Clone and install in development mode
git clone https://github.com/igutekunst/signed-bin-dir.git
cd signed-bin-dir
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black signed_bin_dir/
isort signed_bin_dir/

# Type checking
mypy signed_bin_dir/

Project Structure

signed-bin-dir/
โ”œโ”€โ”€ signed_bin_dir/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py              # Command-line interface
โ”‚   โ”œโ”€โ”€ signer.py           # Core signing/verification logic
โ”‚   โ”œโ”€โ”€ path_manager.py     # PATH management functionality
โ”‚   โ””โ”€โ”€ installer.py        # Shell integration installer
โ”œโ”€โ”€ shell_integrations/
โ”‚   โ”œโ”€โ”€ signed_bin_dir.fish # Fish shell integration
โ”‚   โ””โ”€โ”€ signed_bin_dir.bash # Bash shell integration
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ README.md

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Author

Isaac Harrison Gutekunst isaac@supercortex.io

Troubleshooting

Common Issues

"Private key not found"

  • Ensure you have an SSH key pair generated: ssh-keygen -t rsa
  • Check the key path: ls -la ~/.ssh/

"Signature verification failed"

  • Re-sign the directory: sign-bin-dir sign ./bin
  • Check file permissions: ls -la bin/

"Command not found: sign-bin-dir"

  • Ensure the package is installed: pip list | grep signed-bin-dir
  • Check your PATH includes pip's bin directory

Shell integration not working

  • Check installation status: sign-bin-dir status
  • Reinstall integration: sign-bin-dir install
  • Restart your shell or source the config file

Integration installer issues

  • Make sure you have write permissions to your shell config files
  • Check if your shell config directory exists (e.g., ~/.config/fish/)
  • Use manual installation if automatic installation fails

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

signed_bin_dir-0.1.4.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

signed_bin_dir-0.1.4-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file signed_bin_dir-0.1.4.tar.gz.

File metadata

  • Download URL: signed_bin_dir-0.1.4.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for signed_bin_dir-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4852097517e236ca6413ecf8be8938ddb0b9b5fcaabd7a1b078acf5ad78f2af0
MD5 6e17dc172bf06b8a609200ed8654caab
BLAKE2b-256 c6bb5590d5a8cb2a08cb07ce019b608e5d5fe8e8d5ac5a83873ef2498bedc1fe

See more details on using hashes here.

File details

Details for the file signed_bin_dir-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: signed_bin_dir-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for signed_bin_dir-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 eb0af10f1fdada0f54cf30e1b2ee19f6267e3faf804a20dcd6436691ae4e983a
MD5 a5d75b4a8c94bbd825c806466f385ab6
BLAKE2b-256 e33703ac286016b48e638f8fac5f8f4a9e1fce3fbe0095b3047aa1a6fcd09667

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