43 if ((proc_name !=
"kea-dhcp4") && (proc_name !=
"kea-dhcp6") &&
44 (proc_name !=
"kea-dhcp-ddns")) {
46 <<
", expected kea-dhcp4, kea-dhcp6 or kea-dhcp-ddns");
53 }
catch (
const std::exception& ex) {
98 auto failwith = [](
string msg) {
105 failwith(
"disabled: no role assigned");
118 .arg(response->toBriefString());
119 failwith(
"response already exists");
124 bool updated =
false;
130 failwith(
"no request");
137 failwith(
"TLS required but not used");
144 boost::dynamic_pointer_cast<PostHttpRequestJson>(request);
146 failwith(
"request is not a JSON one");
153 failwith(
"request body is empty");
161 failwith(
"request body is not a map");
168 failwith(
"no command found in request");
174 failwith(
"request command is not a string");
177 string command = elem->stringValue();
183 const string& role =
roleAssign->assign(request);
192 if (role_config->match(command)) {
195 .arg(role_config->name_)
198 if ((command ==
"config-set") || (command ==
"config-reload")) {
202 }
else if (!role_config->response_filters_.empty()) {
205 handle.
setContext(
"role_config", role_config);
209 .arg(role_config->name_)
215 }
catch (
const std::exception& ex) {
229 .arg(response->toBriefString());
242 auto failwith = [](
string msg) {
249 failwith(
"disabled: no role assigned");
259 if (!request || !response) {
262 if (!request && !response) {
263 failwith(
"no request nor response");
264 }
else if (!request) {
265 failwith(
"no request");
267 failwith(
"no response");
277 failwith(
"response body is empty");
284 failwith(
"response body is not a list");
287 if (body->size() < 1) {
290 failwith(
"response body is an empty list");
299 if (!role_config || (role_config->response_filters_.empty())) {
306 .arg(role_config->name_);
309 bool modified =
false;
310 for (
auto const& answer : body->listValue()) {
311 if (role_config->filter(command, answer)) {
318 response->setBodyAsJson(body);
319 response->resetContentLength();
@ NEXT_STEP_SKIP
skip the next processing step
A generic exception that is thrown when an unexpected error condition occurs.
Per-packet callout handle.
void setContext(const std::string &name, T value)
Set context.
void setStatus(const CalloutNextStep next)
Sets the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
void setArgument(const std::string &name, T value)
Set argument.
bool getOptionalContext(const std::string &name, T &value) const
Fetch an optional named element from the current library context.
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
static void parse(data::ConstElementPtr cfg)
Parse the configuration.
static http::HttpResponseJsonPtr createReject(const http::HttpRequestPtr &request, const http::HttpStatusCode &status_code)
Create a reject response.
static RoleConfigPtr getConfig(const std::string &role)
Return the role config.
static bool requireTls(const http::HttpRequestPtr &request)
Require TLS.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const char * CONTROL_COMMAND
String used for commands ("command").
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
boost::shared_ptr< RoleConfig > RoleConfigPtr
Type of shared pointers to role configurations.
RolePtr roleAssign
The role assignment.
isc::log::Logger rbac_logger("rbac-hooks")
set< string > apiHooks
The API hook list.
ResponseFilterTable responseFilterTable
The response filter table.
ApiTable apiTable
The API command table.
set< string > apiAccesses
The API access list (should be "read" and "write").
RoleConfigPtr defaultRoleConfig
The default (role is "") role configuration.
RoleConfigPtr unknownRoleConfig
The unknown (role is not in the table) role configuration.
AclTable aclTable
The access control list table.
Config rbacConfig
The configuration.
RoleConfigTable roleConfigTable
The role configurations table.
Defines the logger used by the top-level component of kea-lfc.
int http_response(CalloutHandle &handle)
This callout is called at the "http_response" hook.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int unload()
This function is called when the library is unloaded.
int http_auth(CalloutHandle &handle)
This callout is called at the "http_auth" callout.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_RESPONSE
const isc::log::MessageID RBAC_LOAD_FAILED
const isc::log::MessageID RBAC_HTTP_AUTH_REJECT
const isc::log::MessageID RBAC_HTTP_AUTH_FAILED
const isc::log::MessageID RBAC_UNLOAD_OK
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_BAD_COMMAND_TYPE
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_NO_TLS_REJECT
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_EMPTY_BODY
const isc::log::MessageID RBAC_HTTP_AUTH_RESPONSE
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_NO_COMMAND
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_CONTEXT
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_DISABLED
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_BAD_BODY_TYPE
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_ACCEPT
const isc::log::MessageID RBAC_LOAD_OK
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_NO_JSON
const isc::log::MessageID RBAC_HTTP_AUTH_ERROR
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_EMPTY_BODY
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_ROLE
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_COMMAND
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_DISABLED
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_EMPTY_BODY_LIST
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_BAD_BODY_TYPE
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_NO_ARGUMENTS
const isc::log::MessageID RBAC_TRACE_HTTP_AUTH_NO_REQUEST
const isc::log::MessageID RBAC_TRACE_HTTP_RESPONSE_MODIFIED
const isc::log::MessageID RBAC_HTTP_RESPONSE_FAILED