osquery-rust
By providing Rust bindings for Osquery this crate facilitates the implementation of Osquery extensions.
Features
- ✅ Table plugins - Create custom tables to query system information
- ✅ Logger plugins - Implement custom logging backends for osquery
- ✅ Writable tables - Support for INSERT, UPDATE, and DELETE operations
- 🦀 Pure Rust - No C/C++ dependencies, just safe Rust code
- 🚀 High performance - Minimal overhead for extensions
- 📦 Easy to use - Simple API with examples to get started quickly
Building
Clone the repository and build the workspace:
Run tests:
The project uses a workspace structure with the main library and several examples. All examples are built automatically when you build the workspace.
Quick Start
Here's a simple example of creating a table plugin that reports system uptime:
use *;
;
Usage Guide
Creating Table Plugins
Table plugins allow you to expose data as SQL tables in osquery. There are two types:
- Read-only tables - Implement the
ReadOnlyTable
trait - Writable tables - Implement the
Table
trait for full CRUD operations
See the examples directory for complete implementations.
Creating Logger Plugins
Logger plugins receive log data from osquery and can forward it to various backends:
use ;
;
Integration with osquery
There are three ways to run your extension:
- Direct loading:
osqueryi --extension /path/to/extension
- Socket connection: Run extension separately with
--socket /path/to/osquery.sock
- Auto-loading: Place extension in osquery's autoload directory
See the examples README for detailed integration instructions.
Examples
The repository includes several complete examples:
- table-proc-meminfo - Exposes
/proc/meminfo
as a queryable table - writeable-table - Demonstrates INSERT, UPDATE, DELETE operations
- two-tables - Shows how to register multiple tables in one extension
- logger-file - Logger plugin that writes to files
- logger-syslog - Logger plugin that sends logs to syslog
Each example includes its own README with specific build and usage instructions.
Contributing
We welcome contributions! Here's how to get started:
Development Setup
- Fork and clone the repository
- Install the pre-commit hook:
Code Quality Standards
This project maintains high code quality standards:
- All code must pass
cargo fmt
- No clippy warnings allowed (enforced by CI)
- All tests must pass
- Unsafe code must be documented
The pre-commit hook automatically runs these checks.
Testing
Run the full test suite:
Pull Request Process
- Create a feature branch from
main
- Write tests for new functionality
- Ensure all checks pass
- Submit a PR with a clear description
- Address review feedback
Reporting Issues
Please report issues on GitHub with:
- osquery version
- Rust version
- Operating system
- Steps to reproduce
- Expected vs actual behavior
Project Structure
The project is organized as a Cargo workspace:
- osquery-rust/ - The main library crate with Thrift bindings and plugin framework
- examples/ - Working examples demonstrating different plugin types:
table-proc-meminfo/
- Read-only table examplewriteable-table/
- Full CRUD table exampletwo-tables/
- Multiple tables in one extensionlogger-file/
- File logger pluginlogger-syslog/
- Syslog logger pluginconfig-file/
- An example that loads a config from a json fileconfig-static/
- An example that provides a static config
Additional Resources
- Tutorial: osquery-rust tutorial
- Examples: osquery-rust by example
- Documentation: docs.rs/osquery-rust
Related Projects
This project contributed the support for Unix Domain Sockets to Apache Thrift's Rust crate.