Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1ay1 Agentty OS Native Keystore

From Leeroopedia
Knowledge Sources
Domains Security, Platform
Last Updated 2026-10-28 12:00 GMT

Overview

Optional OS-native secret storage abstraction (libsecret on Linux, Keychain on macOS) backing credential files so tokens never sit on disk in a form any same-user process can decrypt.

Description

The agentty::auth::keystore module is the optional OS-native secret storage layer. When enabled via `AGENTTY_USE_KEYSTORE`, it holds the sealed encryption envelope and the on-disk file becomes a cache/fallback only. The machine-bound at-rest encryption in `cred_crypt` stays as defense in depth.

Backends are chosen at runtime with no new link-time dependencies: Linux uses libsecret via the `secret-tool` CLI (GNOME Keyring / KWallet through the Secret Service D-Bus API), macOS uses the `security` CLI (login keychain, generic password items). Windows is not yet implemented — retrieve/store report `Unsupported` and the caller transparently falls back to the encrypted file.

Opt-in by default so existing installs are unchanged and no keychain-unlock prompt appears for users who don't want it.

Usage

Import this when you need to store/retrieve/remove secrets in the OS keystore. Callers gate on `available()` before using it and fall back to the encrypted file on `Unsupported`.

Code Reference

Source Location

Signature

namespace agentty::auth::keystore {

enum class Status { Ok, NotFound, Unsupported, Error };

// True iff a keystore backend is available AND enabled via AGENTTY_USE_KEYSTORE.
bool available();

// Human label: "libsecret", "macos-keychain", "disabled", "unavailable"
std::string backend_name();

Status store(const std::string& key, const std::string& secret);
Status retrieve(const std::string& key, std::string& out);
Status remove(const std::string& key);
}

Import

#include "agentty/auth/keystore.hpp"

I/O Contract

Inputs

Name Type Required Description
key std::string Yes Lookup key for the secret
secret std::string Yes (store) The secret value to store
AGENTTY_USE_KEYSTORE env var Yes Must be truthy to enable the keystore

Outputs

Name Type Description
Status enum Ok, NotFound, Unsupported, Error
out std::string& (retrieve) The retrieved secret on Ok

Usage Examples

Store and Retrieve a Secret

#include "agentty/auth/keystore.hpp"

if (agentty::auth::keystore::available()) {
    // Store the sealed envelope in the OS keystore
    auto status = agentty::auth::keystore::store("agentty.credentials", envelope);
    if (status == agentty::auth::keystore::Status::Ok) {
        // On-disk file is now a fallback only
    }
}

// Retrieve at next startup
std::string secret;
auto status = agentty::auth::keystore::retrieve("agentty.credentials", secret);
if (status == agentty::auth::keystore::Status::Ok) {
    // Use the keystore copy — decrypt and proceed
} else {
    // Unsupported/NotFound/Error → fall back to the encrypted file
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment