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 - Runner context: Send client context for dynamic configuration routing
- 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;
With Runner Context (Dynamic Configuration)
For ephemeral applications that need dynamic configuration routing:
use ;
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
- Optionally sends a runner request with client context (instance_id, timestamp, etc.)
- 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
- Returns identity with a
runnerobject containing merged client + server fields
Identity Response
The Identity struct contains:
| Field | Type | Description |
|---|---|---|
identity |
String |
Application-level identity name |
idm_url |
String |
Identity Management (Kanidm) OAuth2/OIDC URL |
config_url |
String |
Application configuration endpoint URL |
token |
String |
Pre-shared authentication token |
runner |
Runner |
Combined client context + server identity |
Runner Object
The runner object is designed to be passed directly to a config server:
| Field | Source | Description |
|---|---|---|
identity |
server | Application-level identity name |
hostname |
server | Machine hostname |
process |
server | Process name |
pid |
server | Process ID (kernel-verified) |
uid |
server | User ID (kernel-verified) |
gid |
server | Group ID (kernel-verified) |
instance_id |
client | Client-provided instance identifier (optional) |
timestamp |
client | Client-provided timestamp (optional) |
extra |
client | Additional custom fields |
Example Output
Identity retrieved successfully!
Identity: TRUSTEE_AGENT
IDM URL: https://auth.example.com/oauth2/trustee
Config URL: https://config.example.com/api/trustee
Token: tok_trustee_xxx
Runner:
Hostname: worker-node-03
Process: trustee
PID: 26567
UID: 1000
GID: 1000
Instance ID: 42
Timestamp: 1738512000
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.