feat: add ScottyShellProvider for shell command execution in scotty containers#371
feat: add ScottyShellProvider for shell command execution in scotty containers#371
Conversation
Add complete design documentation for implementing ScottyShellProvider to enable shell command execution in scotty containers via scottyctl. Issue: phab-93f21d
- Add ScottyShellProvider extending LocalShellProvider - Register ScottyShellProvider in ShellProviderFactory - Set 'shellProvider: scotty' as default in ScottyMethod - Add 'shellService' validation to ScottyMethod - Update test fabfile with shellService configuration - File operations (putFile/getFile) throw RuntimeException The ScottyShellProvider enables shell command execution in scotty containers via scottyctl app:shell. All phabalicious commands can now run inside scotty services. Issue: phab-93f21d
- Add shellService to required configuration table - Add new 'Shell Provider Integration' section explaining automatic shellProvider setup - Document shell command usage with scotty - Note file operation limitations - Update all example configurations with shellService Issue: phab-93f21d
…turn type - Fix CompletionCommand::configure() to add void return type for PHP 8+ compatibility - Fix ScottyShellProvider to place global options (--server, --access-token) before subcommand - Add hostShellProvider test host that uses scotty shell provider exclusively - Keep existing test hosts with local shell provider for tests without scotty server Issue: phab-93f21d
Use Utilities::mergeData() to properly merge global scotty configuration
with host-specific scotty configuration. This ensures that global settings
like shellService are available when not explicitly set at the host level.
Before: Global scotty config was assigned but got overwritten during merge
After: Global scotty config is properly merged with host config
Example:
scotty:
shellService: nginx # Now available to all hosts
hosts:
production:
needs: [scotty]
scotty:
app-name: my-app # Inherits shellService from global
Issue: phab-93f21d
Pull Request Review: ScottyShellProvider ImplementationI've reviewed this PR and overall it's a solid implementation that follows the project's conventions well. Here are my findings: ✅ Strengths
🐛 Issues Found1. Critical: Logic Error in CompletionCommand.php:96Missing else keyword causes both branches to execute when both option and argument are set. Line 96 should be elseif not if. Current code has two consecutive if statements when it should be if/elseif. 2. Potential Issue: Shell Escaping in ScottyShellProviderFile: src/ShellProvider/ScottyShellProvider.php:83 The program_to_call array is imploded with spaces without proper escaping. If any element contains spaces or special characters, this could lead to command injection or unexpected behavior. Recommendation: Either properly escape each element before imploding, pass the array through a shell escaping function, or document that callers are responsible for escaping. 3. Error Handling: RuntimeException for File OperationsFiles: src/ShellProvider/ScottyShellProvider.php:97,102 The method signature returns bool but always throws an exception. This could cause confusion. Recommendations:
|
Add comment explaining that when both local and scotty are in needs, scotty's shellProvider setting takes precedence. This is the intended behavior - if a host uses scotty, commands should run in scotty containers. Users can still override by explicitly setting shellProvider in their host configuration. Note: Configuration cache may need to be cleared (--skip-cache) to see the effect after upgrading. Issue: phab-93f21d
Code Review: ScottyShellProvider IntegrationI've reviewed PR #371 and overall this is a well-implemented feature that adds shell provider support for Scotty containers. Here's my detailed feedback: Strengths
Issues Found1. Critical: Logic error in CompletionCommand.php:96 Missing else - if both option and argument are set, return gets overwritten. Change line 96 from if to elseif. 2. Security: Potential command injection in ScottyShellProvider.php:83 The implode of program_to_call without escaping could lead to command injection. Compare with DockerExecShellProvider.php:64-66 which adds elements individually, or ensure proper escaping if scottyctl requires a single string. 3. Code Quality: TODO comment in ScottyMethod.php:65 IDE-generated TODO comment should be removed. Suggestions
SummaryMust Fix Before Merge:
Overall, this is a solid implementation that follows project conventions well. The critical issues are fixable and once addressed, this will be a valuable addition to phabalicious. |
|
PR Review: ScottyShellProvider Integration CRITICAL: Command Injection Vulnerability MEDIUM: Logic Bug in CompletionCommand MEDIUM: Undefined array key in ScottyCtlOptions.php:30 MINOR: Remove TODO comment in ScottyMethod.php:67 Overall: 7.5/10 - Solid PR with good architecture but must fix command injection before merge |
Secret placeholders like %secret.scotty-token% were not being resolved in ScottyCtlOptions::build() before passing to scottyctl commands. Changes: - Add resolveSecrets() call in ScottyCtlOptions::build() - Add test for secret resolution with environment variable - Update documentation to explain OAuth vs token auth methods - Document secret management for access tokens
Pull Request Review - ScottyShellProviderThank you for this comprehensive PR! This is a well-structured feature addition with good test coverage. Strengths
Critical Issues1. Missing elseif in CompletionCommand.php line 96Both if blocks can execute, causing logic bug. Should be elseif. 2. Command Injection in ScottyShellProvider line 83program_to_call joined without escaping. Use array_map with escapeshellarg. 3. File path injection in exists() line 91File parameter not escaped in stat command. Security Concerns
RecommendationsMust Fix: elseif bug, command injection, test config Overall: Approve with required changes. Great implementation! |
Changed logger output to use io()->comment() and io()->success() instead of logger->debug/info, making authentication verification visible during command execution without requiring verbose flags.
Pull Request Review: ScottyShellProvider IntegrationThank you for this comprehensive feature addition! Overall, this is a well-structured implementation that follows phabalicious patterns. StrengthsArchitecture and Design
Code Quality
Testing
Security Concerns1. Command Injection Risk (HIGH PRIORITY)Location: src/ShellProvider/ScottyShellProvider.php:83 The program_to_call array is joined with spaces and passed as a single string. If any element contains shell metacharacters, this could lead to command injection. Recommendation: Use escapeshellarg() around the implode result. 2. Token Exposure in LogsLocation: src/ShellProvider/ScottyShellProvider.php:55-65 Access tokens appear in command arrays that may be logged. Recommendation: Consider using environment variables for tokens or redact in logs. 3. exists() ImplementationLocation: src/ShellProvider/ScottyShellProvider.php:91 Missing shell escaping on file parameter - potential command injection if filename contains special characters. Fix: Use escapeshellarg() on the file variable. Potential Bugs1. Missing elseifLocation: src/Command/CompletionCommand.php:96 Second condition should be elseif, not if - otherwise both branches execute. 2. TODO CommentLocation: src/Method/ScottyMethod.php:67 Remove the TODO comment. 3. Test Coverage GapMissing unit tests specifically for ScottyShellProvider. Consider adding tests/ScottyShellProviderTest.php Recommendations PriorityMust Fix (Before Merge)
Should Fix (Before Merge)
Nice to Have (Future PR)
SummaryOverall Assessment: This is a solid, well-architected addition to phabalicious. The main concerns are security-related that should be addressed before merge. Code Quality: 4/5 Recommendation: Request changes to address security issues, then approve once fixed. Great work on this feature! The integration is clean and follows phabalicious patterns well. |
Extract command building logic into a reusable static helper method that both ScottyCtlOptions and ScottyShellProvider can use. This: - Eliminates code duplication between the two classes - Ensures consistent command structure across all scottyctl invocations - Maintains proper secret handling (LocalShellProvider resolves secrets for shell commands automatically) Benefits: - Single source of truth for scottyctl command structure - Easier to maintain and extend scottyctl command building - Future scottyctl features only need to be added in one place
Pull Request Review - ScottyShellProviderThank you for this comprehensive implementation! This is a well-structured addition that follows existing patterns in the codebase. StrengthsArchitecture & Design:
Security:
Code Quality:
Testing:
Documentation:
Issues Found1. Logic Error in CompletionCommand.php:96 (MEDIUM) 2. Missing Null Check in ScottyCtlOptions.php:30 (LOW) 3. Inconsistent Null Handling (LOW) 4. Hardcoded Path in Test Config (LOW - Test Only) 5. Command Injection Note (INFO) 6. URL Validation Missing (LOW) 7. Documentation Gap RecommendationAPPROVE with minor fixes Only blocking issue is the CompletionCommand logic error. Others are minor improvements. Before Merging:
Post-Merge:
Great work! The core functionality is solid and well-tested. |
Array commands passed to Process don't go through expandCommand(), so secrets must be resolved directly in getShellCommand(). This fixes the issue where %secret.scotty-token% was passed unresolved to scottyctl. The fix uses PasswordManager::resolveSecrets() on the command array before returning it from getShellCommand().
Code Review - PR #371: ScottyShellProviderOverall, this is a well-implemented feature with good test coverage and documentation. The code follows existing architecture patterns and integrates cleanly with the shell provider system. Strengths
Issues FoundCRITICAL: Missing elseif in CompletionCommand.php:96 Line 96 has: } if ($argument) { Impact: When $option is set, the code will still check $argument and potentially overwrite the result, breaking shell completion logic. Minor: Unused TODO Comment in ScottyMethod.php:67 Remove the TODO comment - the implementation is complete. Design Considerations
Test CoverageExcellent coverage for configuration validation, inheritance, secret resolution, and ScottyCtlOptions building. Missing: No unit tests for ScottyShellProvider itself. Recommend adding tests for putFile/getFile exceptions, getShellCommand() structure, and exists() method. Security ReviewNo security concerns identified:
PerformanceNo performance issues:
ConclusionThis is a high-quality PR that adds valuable functionality. After fixing the critical elseif bug in CompletionCommand.php:96, this should be ready to merge. Recommendation: Approve after fixing the CompletionCommand bug Great work on the implementation, documentation, and test coverage! |
The inherited LocalShellProvider::wrapCommandInLoginShell() does not quote the argument to bash -c. Since getShellCommand() flattens the array via implode(), the command string after -c was split by the shell, breaking interactive commands like drush.
Summary
Add ScottyShellProvider to enable shell command execution in scotty containers via scottyctl app:shell. This allows all phabalicious commands (deploy, backup, shell, etc.) to execute inside scotty services.
Changes
Configuration
Hosts with needs: [scotty] automatically get shellProvider: scotty
Global configuration is properly inherited by all hosts.
Testing
Documentation
Updated docs/scotty.md with shell provider integration section, shellService configuration, and usage examples.
Issue: phab-93f21d