Kea 3.3.4
rbac_config.cc
Go to the documentation of this file.
1// Copyright (C) 2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <rbac/rbac.h>
10#include <rbac/rbac_config.h>
11#include <rbac_log.h>
12
13using namespace isc;
14using namespace isc::data;
15using namespace isc::log;
16using namespace isc::rbac;
17using namespace std;
18
19namespace isc {
20namespace rbac {
21
23
25 { "access-control-lists", Element::list },
26 { "assign-role-method", Element::string },
27 { "api-files", Element::string },
28 { "commands", Element::list },
29 { "default-role", Element::map },
30 { "require-tls", Element::boolean },
31 { "roles", Element::list },
32 { "unknown-role", Element::map },
33 { "comment", Element::string }
34};
35
37 "api-files",
38 "assign-role-method"
39};
40
41void
43 api_files_ = ".../share/kea/api";
44 require_tls_ = false;
47}
48
49void
51 if (!cfg) {
52 isc_throw(BadValue, "null config");
53 }
54 if (cfg->getType() != Element::map) {
55 isc_throw(BadValue, "config is not a map");
56 }
57
58 // Check keywords.
61
62 // Role assignment method.
63 roleAssign = Role::parse(cfg->get("assign-role-method"));
64 if (!roleAssign) {
65 isc_throw(Unexpected, "role assignment parsing failed");
66 }
67 roleAssign->setup(true);
68
69 // Require TLS flag.
70 ConstElementPtr require_tls = cfg->get("require-tls");
71 if (require_tls) {
72 rbacConfig.setRequireTls(require_tls->boolValue());
73 } else if ((roleAssign->getName() == "subject") ||
74 (roleAssign->getName() == "issuer")) {
75 rbacConfig.setRequireTls(true);
76 }
77
78 // API files directory.
79 const string& api_files = cfg->get("api-files")->stringValue();
80 rbacConfig.setApiFiles(api_files);
81 Api::fillApiTable(api_files);
82
83 // Command definitions.
84 ConstElementPtr commands = cfg->get("commands");
85 if (commands) {
86 size_t count(0);
87 for (auto const& command : commands->listValue()) {
88 Api::parse(command);
89 ++count;
90 }
92 .arg(count);
93 }
94
95 // ACL definitions.
96 ConstElementPtr acls = cfg->get("access-control-lists");
97 if (acls) {
98 size_t count(0);
99 for (auto const& acl : acls->listValue()) {
100 AliasAcl::parse(acl);
101 ++count;
102 }
104 .arg(count);
105 }
106
107 // Roles definitions.
108 ConstElementPtr roles = cfg->get("roles");
109 if (roles) {
110 size_t count(0);
111 for (auto const& elem : roles->listValue()) {
112 RoleConfigPtr role = RoleConfig::parse(elem);
113 if (!role) {
114 isc_throw(Unexpected, "role config parsing error for "
115 << elem->str());
116 }
117 const string& name = role->name_;
118 if (roleConfigTable.count(name) != 0) {
119 isc_throw(BadValue, "role '" << name
120 << "' is already defined");
121 }
122 roleConfigTable[name] = role;
123 ++count;
124 }
126 .arg(count);
127 }
128
129 // Default role (use when role assignment returns the empty string).
130 ConstElementPtr default_elem = cfg->get("default-role");
131 if (default_elem) {
132 defaultRoleConfig = RoleConfig::parse(default_elem, "default");
133 } else {
134 defaultRoleConfig.reset(new RoleConfig("default/reject",
135 AclPtr(new NoneAcl()),
136 AclPtr(new AllAcl()),
137 false, true,
139 }
140
141 // Unknown role (use when role assignment returns a role not in the table).
142 ConstElementPtr unknown_elem = cfg->get("unknown-role");
143 if (unknown_elem) {
144 unknownRoleConfig = RoleConfig::parse(unknown_elem, "unknown");
145 } else {
146 unknownRoleConfig.reset(new RoleConfig("unknown/reject",
147 AclPtr(new NoneAcl()),
148 AclPtr(new AllAcl()),
149 false, true,
151 }
152}
153
154} // end of namespace rbac
155} // end of namespace isc
@ map
Definition data.h:160
@ boolean
Definition data.h:155
@ list
Definition data.h:159
@ string
Definition data.h:157
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static void checkRequired(const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope)
Checks that all required keywords are present.
static void initTable()
Initialize the access control list table.
Definition rbac_acl.cc:26
static void parse(data::ConstElementPtr def)
Parse an access control list definition.
Definition rbac_acl.cc:134
All access control list.
Definition rbac_acl.h:280
static void parse(data::ConstElementPtr cfg, bool others=false)
Parse a command config.
Definition rbac_api.cc:96
static void fillApiTable(const std::string &dirname)
Fill the API command table.
Definition rbac_api.cc:44
RBAC Configuration class.
Definition rbac_config.h:17
void init()
Initialization.
static const data::SimpleRequiredKeywords RBAC_REQUIRED_PARAMETERS
Configuration required parameters.
Definition rbac_config.h:27
static void parse(data::ConstElementPtr cfg)
Parse the configuration.
static const data::SimpleKeywords RBAC_PARAMETERS
Configuration parameters.
Definition rbac_config.h:24
None access control list.
Definition rbac_acl.h:296
static void initResponseFilterTable()
Initialize the response filter table.
Per role configuration class.
Definition rbac.h:34
static RoleConfigPtr parse(data::ConstElementPtr cfg, std::string name="")
Parse a role config.
Definition rbac.cc:53
static RolePtr parse(data::ConstElementPtr cfg)
Parse a role assignment value.
Definition rbac_role.cc:22
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
std::vector< std::string > SimpleRequiredKeywords
This specifies all required keywords.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
boost::shared_ptr< RoleConfig > RoleConfigPtr
Type of shared pointers to role configurations.
Definition rbac.h:23
RolePtr roleAssign
The role assignment.
Definition rbac.cc:22
isc::log::Logger rbac_logger("rbac-hooks")
Definition rbac_log.h:18
boost::shared_ptr< Acl > AclPtr
Type of shared pointers to Acl.
Definition rbac_acl.h:29
std::list< ResponseFilterPtr > ResponseFilterList
The type of list of shared pointers to response filters.
RoleConfigPtr defaultRoleConfig
The default (role is "") role configuration.
Definition rbac.cc:26
RoleConfigPtr unknownRoleConfig
The unknown (role is not in the table) role configuration.
Definition rbac.cc:28
Config rbacConfig
The configuration.
RoleConfigTable roleConfigTable
The role configurations table.
Definition rbac.cc:24
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID RBAC_CONFIGURED_ROLES
const isc::log::MessageID RBAC_CONFIGURED_ACLS
const isc::log::MessageID RBAC_CONFIGURED_COMMANDS