getmyid
A Rust client library for the whoami Identity-by-PID daemon.
Overview
getmyid provides a type-safe, ergonomic Rust interface for querying process identity from the whoami daemon. The whoami daemon uses the Linux kernel's SO_PEERCRED mechanism to securely identify local processes without passwords - the kernel vouches for their identity.
Features
- Synchronous client: Default, no additional dependencies
- Asynchronous client: Enable the
tokiofeature for async support - Builder pattern: Flexible client configuration
- Type-safe: Strongly typed identity and error types
- Zero-copy parsing: Efficient JSON deserialization
Installation
Add to your Cargo.toml:
[]
= "0.1"
# For async support:
= { = "0.1", = ["tokio"] }
Quick Start
Synchronous Usage
use Client;
Convenience Function
let identity = get_identity?;
println!;
Asynchronous Usage
use AsyncClient;
async
Custom Configuration
use Duration;
use Client;
let client = builder
.socket_path
.timeout
.build;
How It Works
- Your application connects to the whoami daemon's Unix Domain Socket
- The daemon uses
SO_PEERCREDto get your process's PID, UID, and GID from the kernel - The daemon reads additional info from
/proc/[PID]/(process name, executable path) - The daemon matches your identity against configured rules
- If a match is found, returns the application-level identity and Kanidm OAuth2 URL
Identity Response
The Identity struct contains:
| Field | Type | Description |
|---|---|---|
identity |
String |
Application-level identity name |
kanidm_url |
String |
Kanidm OAuth2 URL for this identity |
pid |
u32 |
Process ID |
uid |
u32 |
User ID |
gid |
u32 |
Group ID |
process |
String |
Process name |
Error Handling
All errors are represented by GetMyIdError:
ConnectionFailed- Socket connection failedReadError/WriteError- I/O errorsInvalidJson- Response parsing failedDaemonError- Daemon returned an error (e.g., no matching rule)SocketNotFound- Socket path doesn't existTimeout- Operation timed out
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.