Skip to content

Conversation

f0ssel
Copy link
Collaborator

@f0ssel f0ssel commented Sep 10, 2025

Refactors the jail architecture to use the new jail.Jail type as a unified orchestration layer.

Key Changes

  • Integrated jail services: Combines proxy server, certificate manager, rule engine into single jail.Jail instance
  • Optimized environment handling: Map-based storage with SetEnv() interface, setup moved to Open() phase for better performance
  • Enhanced namespace implementations: Migrated Execute() logic to Command() methods with prepared environments and credentials
  • Simplified TLS management: Added SetupTLSAndWriteCACert() method for cleaner CLI integration
  • Dependency injection: CLI constructs components and passes to jail, better separation of concerns

Benefits

  • Better performance (setup once, use many)
  • Cleaner architecture with unified lifecycle management
  • Improved testability through dependency injection
  • All existing functionality preserved

All tests pass and binary builds successfully.

@blink-so blink-so bot changed the title start Refactor jail to use integrated services architecture Sep 10, 2025
f0ssel and others added 16 commits September 10, 2025 15:06
- Updated namespace implementations to include environment setup in Command method
- Migrated Execute function logic from namespaces into Command method with proper env, credentials, and I/O setup
- Enhanced jail.Jail to integrate proxy server, certificate manager, rule engine, and auditor
- Simplified CLI to use unified jail.Jail instead of managing separate components
- Maintained all existing functionality while improving code organization
- All tests pass and binary builds successfully

Co-authored-by: f0ssel <[email protected]>
- Move environment preparation from Command() to Open() method in both Linux and macOS namespaces
- Add preparedEnv field to store the prepared environment once during setup
- Simplify Command() methods to just inject the prepared environment
- Improves performance by avoiding repeated environment setup on each command
- Maintains all existing functionality while improving efficiency

Co-authored-by: f0ssel <[email protected]>
- Move sudo credential preparation from Command() to Open() method in both Linux and macOS namespaces
- Add procAttr field to store prepared syscall.SysProcAttr with credentials
- Simplify Command() methods to just use the prepared process attributes
- Eliminates repeated sudo environment checks and credential parsing on each command
- Further improves performance and code organization
- All credential handling now happens once during setup phase

Co-authored-by: f0ssel <[email protected]>
- Simplify jail.Config to only contain dependencies (Commander, ProxyServer, etc)
- Move all component construction logic from jail.New into CLI
- jail.New now only accepts pre-constructed dependencies and assembles them
- CLI handles rule parsing, certificate manager creation, proxy server setup
- Better separation of concerns: jail package focuses on orchestration, CLI handles construction
- Eliminates error handling in jail.New since dependencies are pre-validated
- Makes jail package more testable with dependency injection

Co-authored-by: f0ssel <[email protected]>
- Remove RuleEngine, Auditor, and CertManager from jail.Config
- These dependencies are only needed by ProxyServer, not by Jail directly
- Simplify jail.Config to only contain CommandExecutor, ProxyServer, and Logger
- Remove GetCACertPEM method since CertManager is no longer available in Jail
- Clean up unused imports (audit, rules, tls packages)
- CA certificate handling remains in CLI where CertManager is constructed
- Further simplifies the Jail orchestration layer

Co-authored-by: f0ssel <[email protected]>
- Convert preparedEnv from []string to map[string]string for better environment management
- Implement SetEnv methods in both Linux and macOS namespace implementations
- Add CommandExecutor accessor method to Jail for SetEnv access
- Update CLI to use SetEnv method for CA certificate environment variables
- Remove Env field from namespace.Config since SetEnv is used instead
- Environment variables now properly managed through SetEnv interface
- Allows dynamic environment variable setting after initialization
- Better encapsulation and control over environment variables

Co-authored-by: f0ssel <[email protected]>
- Add SetupTLSAndWriteCACert method to CertificateManager
- Combines getting TLS config, CA cert PEM, and writing CA cert to file
- Returns TLS config, CA cert path, and CA cert PEM in one call
- Update CLI to use the new method instead of separate calls
- Reduces complexity in CLI Run function
- Better encapsulation of TLS-related setup logic
- Remove unused filepath import from CLI
- Clean separation between TLS setup and CLI orchestration

Co-authored-by: f0ssel <[email protected]>
…rn value

- Update SetupTLSAndWriteCACert to call tls.GetConfigDir() internally
- Return config directory as part of the method's return values
- Remove unused []byte (CA cert PEM) from return values since it's never used
- Update CLI to handle new return signature with configDir
- Remove separate GetConfigDir call from CLI
- Pass empty string to NewCertificateManager since configDir is determined internally
- Further simplifies CLI by removing another external dependency call
- Better encapsulation of config directory management within TLS package

Co-authored-by: f0ssel <[email protected]>
@blink-so blink-so bot changed the title Refactor jail to use integrated services architecture Complete jail architecture refactoring with integrated services and optimized environment handling Sep 10, 2025
@blink-so blink-so bot changed the title Complete jail architecture refactoring with integrated services and optimized environment handling Refactor jail architecture with integrated services Sep 10, 2025
@f0ssel f0ssel merged commit 0bd5438 into main Sep 10, 2025
7 checks passed
@f0ssel f0ssel deleted the f0ssel/interfaces branch September 16, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant