ACLs¶
netutils.acl
¶
Classes to help manage ACLs .
ACLRule
¶
A class that helps you imagine an acl rule via methodologies.
Source code in netutils/acl.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
__init__(data, *args, **kwargs)
¶
Initialize and load data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Any
|
A dictionary with string keys and either string or list of string values |
required |
Examples:
>>> from netutils.acl import ACLRule
>>>
>>> acl_data = dict(
... name="Check no match",
... src_ip=["10.1.1.1"],
... dst_ip="172.16.0.10",
... dst_port="tcp/www-http",
... action="permit",
... )
>>>
>>> rule = ACLRule(acl_data)
>>>
>>> rule.expanded_rules
[{'name': 'Check no match', 'src_ip': '10.1.1.1', 'dst_ip': '172.16.0.10', 'dst_port': '6/80', 'action': 'permit'}]
>>>
Source code in netutils/acl.py
__repr__()
¶
enforce()
¶
Run through any method that startswith('enforce_') and run that method.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
A list of dictionaries that explains the results of the enforcement. |
Source code in netutils/acl.py
enforce_matrix()
¶
A simple matrix
or grid style check of a rule.
Returns:
Type | Description |
---|---|
Union[List[Dict[str, Any]], None]
|
A list of dictionaries that explains the results of the matrix being enforced. |
Source code in netutils/acl.py
input_data_check()
¶
Verify the input data against the specified JSONSchema or using a simple dictionary check.
load_data()
¶
Load the data into the rule while verifying input data, result data, and processing data.
Source code in netutils/acl.py
match(match_rule)
¶
Simple boolean way of verifying match or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
match_rule |
ACLRule
|
The rule which you are testing against. |
required |
Returns:
Type | Description |
---|---|
bool
|
A boolean if there was a full match or not. |
Source code in netutils/acl.py
match_action(existing_action, check_action)
¶
Match the action for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_action |
str
|
The existing action value to be matched. |
required |
check_action |
str
|
The action value to be checked against the existing action. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
match_details(match_rule)
¶
Verbose way of verifying match details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
match_rule |
ACLRule
|
The rule which you are testing against. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary with root keys of |
Source code in netutils/acl.py
match_dst_ip(existing_ip, check_ip)
¶
Determined if destination check_ip
is within `existing_ip.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_ip |
str
|
The existing destination IP address or IP range to be matched against. |
required |
check_ip |
str
|
The destination IP address to be checked. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
match_dst_port(existing_port, check_port)
¶
Match the destination port for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_port |
str
|
The existing destination port value to be matched. |
required |
check_port |
str
|
The destination port value to be checked against the existing port. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
match_dst_zone(existing_dst_zone, check_dst_zone)
¶
Match the destination zone for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_dst_zone |
str
|
The existing destination zone value to be matched. |
required |
check_dst_zone |
str
|
The destination zone value to be checked against the existing zone. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
match_src_ip(existing_ip, check_ip)
¶
Determined if source check_ip
is within existing_ip
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_ip |
str
|
The existing source IP address or IP range to be matched against. |
required |
check_ip |
str
|
The source IP address to be checked. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
match_src_zone(existing_src_zone, check_src_zone)
¶
Match the source zone for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
existing_src_zone |
str
|
The existing source zone value to be matched. |
required |
check_src_zone |
str
|
The source zone value to be checked against the existing zone. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if |
Source code in netutils/acl.py
process_dst_port(dst_port)
¶
Convert port and protocol information.
Method supports a single format of {protocol}/{port}
, and will translate the
protocol for all IANA defined protocols. The port will be translated for TCP and
UDP ports only. For all other protocols should use port of 0, e.g. ICMP/0
for ICMP
or 50/0
for ESP. Similarly, IANA defines the port mappings, while these are mostly
staying unchanged, but sourced from
https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv.
Source code in netutils/acl.py
result_data_check()
¶
Verify the result data against the specified JSONSchema or using a simple dictionary check.
validate()
¶
Run through any method that startswith('validate_') and run that method.
Source code in netutils/acl.py
ACLRules
¶
Class to help match multiple ACLRule objects.
Source code in netutils/acl.py
__init__(data, *args, **kwargs)
¶
Class to help match multiple ACLRule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Any
|
A list of |
required |
Source code in netutils/acl.py
load_data()
¶
match(rule)
¶
Check the rules loaded in load_data
match against a new rule
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
ACLRule
|
The |
required |
Returns:
Type | Description |
---|---|
str
|
The response from the rule that matched, or |
Source code in netutils/acl.py
match_details(rule)
¶
Verbosely check the rules loaded in load_data
match against a new rule
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
ACLRule
|
The |
required |
Returns:
Type | Description |
---|---|
Any
|
The details from the |