11#include <nlohmann/json.hpp>
25 std::lock_guard<std::mutex> lock(auth_mutex_);
44 std::lock_guard<std::mutex> lock(auth_mutex_);
61 std::lock_guard<std::mutex> lock(auth_mutex_);
63 if (
it == key_sets_.end()) {
81 std::lock_guard<std::mutex> lock(auth_mutex_);
83 if (
it == key_sets_.end()) {
110 const std::string& tool_name,
112 std::lock_guard<std::mutex> lock(auth_mutex_);
114 if (
it == key_sets_.end()) {
115 logger->info(
"Auth ALLOW: {} on {} (no enforcement)",
120 logger->info(
"Auth {}: {} on {} (required={})",
142 std::lock_guard<std::mutex> lock(auth_mutex_);
145 if (
granter == key_sets_.end() ||
150 logger->warn(
"{} lacks {}:{} — cannot grant to {}",
170 std::lock_guard<std::mutex> lock(auth_mutex_);
172 if (
it == key_sets_.end()) {
175 return it->second.list();
185 std::lock_guard<std::mutex> lock(auth_mutex_);
186 nlohmann::json obj = nlohmann::json::object();
187 for (
const auto& [name,
key_set] : key_sets_) {
189 obj[name] = nlohmann::json::parse(
keys_json);
202 const std::string& json) {
205 obj = nlohmann::json::parse(json);
206 }
catch (
const nlohmann::json::exception&
e) {
207 logger->warn(
"Deserialize failed: {}",
e.what());
210 if (!obj.is_object()) {
211 logger->warn(
"Deserialize: expected JSON object");
214 std::lock_guard<std::mutex> lock(auth_mutex_);
216 for (
const auto& [name,
keys_arr] : obj.items()) {
217 auto [
it,
_] = key_sets_.try_emplace(name);
231 std::lock_guard<std::mutex> lock(auth_mutex_);
entropic_error_t grant(const std::string &identity_name, const std::string &pattern, MCPAccessLevel level)
Grant a tool key to an identity.
void register_identity(const std::string &identity_name)
Register an empty key set for an identity.
void unregister_identity(const std::string &identity_name)
Remove an identity's key set (disables enforcement).
bool deserialize_all(const std::string &json)
Deserialize all identity key sets from JSON.
bool is_enforced(const std::string &identity_name) const
Check if an identity has authorization enforcement enabled.
entropic_error_t revoke(const std::string &identity_name, const std::string &pattern)
Revoke a tool key from an identity.
std::string serialize_all() const
Serialize all identity key sets to JSON.
std::vector< MCPKey > list_keys(const std::string &identity_name) const
List all keys for an identity.
entropic_error_t grant_from(const std::string &granter_name, const std::string &grantee_name, const std::string &pattern, MCPAccessLevel level)
One identity grants a key to another identity.
bool check_access(const std::string &identity_name, const std::string &tool_name, MCPAccessLevel required_level) const
Check if a tool call is authorized for an identity.
entropic_error_t
Error codes returned by all C API functions.
@ ENTROPIC_ERROR_IDENTITY_NOT_FOUND
Identity name not in config (v1.8.9)
@ ENTROPIC_ERROR_PERMISSION_DENIED
Tool call blocked by permission manager.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Per-identity MCP authorization with runtime grant/revoke.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
const char * mcp_access_level_name(MCPAccessLevel level)
Convert MCPAccessLevel to string representation.
MCPAccessLevel
MCP tool access level for per-identity authorization.