The Manticore Search Management Tool is a PHP-based CLI application designed as a sidecar for Manticore Search, facilitating high-level authentication tasks such as user and permission management. It interacts with Manticore Search’s configuration and authentication files (auth.json
, auth.tmp
) to manage users, tokens, passwords, and permissions, supporting both standard and real-time (RT) modes. The tool logs operations to searchd.log.auth
and ensures secure file handling with 0600
permissions, as specified in Manticore Search Spec v1.4.0.
- User Management: Add, delete, list users, generate tokens, and update passwords.
- Permission Management: Add, delete, and list permissions with support for actions (e.g., read, write), targets (e.g., table names,
*
), and budgets. - RT Mode Support: Handles real-time updates via
auth.tmp
for integration with Manticore Buddy. - Secure Operations: Uses file locking (
auth.lock
) and0600
permissions for secure file access. - Logging: Records all operations and errors to
searchd.log.auth
using Monolog. - HTTP Status Checks: Verifies Manticore Search instance status via HTTP requests (status codes 200, 400).
- PHP >= 7.4
- Composer
- Dependencies:
symfony/console:^5.4
symfony/filesystem:^5.4
guzzlehttp/guzzle:^7.5
monolog/monolog:^2.9
- For development:
phpunit/phpunit:^9.5
slevomat/coding-standard:^8.0
squizlabs/php_codesniffer:^3.7
-
Clone the Repository:
git clone <repository-url> cd manticore-management-tool
-
Install Dependencies:
composer install
-
Ensure Manticore Search Configuration:
- Place a
manticore.conf
file in one of the default locations (/etc/manticoresearch/manticore.conf
,/usr/local/etc/manticore.conf
,./manticore.conf
) or specify a custom path using the--config
option. - Example
manticore.conf
:searchd { listen = 127.0.0.1:9308:http auth = true }
- Place a
Run the CLI tool using:
php src/main.php [options] <command>
-
User Management:
- Add a user:
php src/main.php user add <username>
- Generate/update token:
php src/main.php user token <username>
- Update password:
php src/main.php user password <username>
- Delete user:
php src/main.php user delete <username>
- List users:
php src/main.php user list
- Add a user:
-
Permission Management:
- Add permission:
php src/main.php permission add --user <username> --action <action> --target <target> --allow <true|false> [--budget <json>]
- Delete permission:
php src/main.php permission delete --user <username> --action <action> --target <target>
- List permissions:
php src/main.php permission list
- Add permission:
-
Options:
-c, --config <path>
: Specify the Manticore Search configuration file path.-h, --help
: Display help information.
-
Add a user interactively:
php src/main.php user add admin # Prompts for password
-
Add a user with piped password:
echo "mypassword" | php src/main.php user add admin
-
Generate a token:
php src/main.php user token admin
-
Add a permission:
php src/main.php permission add --user admin --action read --target "*" --allow true --budget '{"queries_per_minute":1000}'
-
List all permissions:
php src/main.php permission list
The project includes a comprehensive test suite covering unit, integration, functional, and error scenarios.
-
Run Tests:
vendor/bin/phpunit tests/
-
Run Specific Tests:
vendor/bin/phpunit tests/Unit/ManticoreCommandUnitTest.php vendor/bin/phpunit tests/Integration/ManticoreCommandIntegrationTest.php vendor/bin/phpunit tests/Functional/ManticoreCommandFunctionalTest.php vendor/bin/phpunit tests/Error/ManticoreCommandErrorTest.php
-
Code Quality Checks:
- Run PHPStan (Level 9):
vendor/bin/phpstan analyse --level=9
- Run PHP_CodeSniffer:
vendor/bin/phpcs --standard=ruleset.xml src tests
- Fix CodeSniffer issues:
vendor/bin/phpcbf --standard=ruleset.xml src tests
- Run PHPStan (Level 9):
-
src/main.php: Entry point for the CLI application.
-
src/Command/ManticoreCommand.php: Handles CLI command execution and user input processing.
-
src/Service/AuthService.php: Manages authentication file operations (users, permissions, RT Mode).
-
src/Service/HttpService.php: Checks Manticore Search instance status via HTTP.
-
tests/: Contains unit, integration, functional, and error tests.
The project adheres to strict coding standards defined in phpstan.neon
(Level 9) and ruleset.xml
:
- Strict type declarations (
declare(strict_types=1)
). - Alphabetically sorted imports.
- Trailing commas in arrays.
- No forbidden functions (e.g.,
count
,print
). - Maximum line length of 120 characters.
- CamelCaps naming for variables and methods.
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature
). - Commit changes (
git commit -m 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
Ensure all code passes PHPStan and PHP_CodeSniffer checks.
This project is licensed under the MIT License.