CactuseSecurity / firewall-orchestrator

Network Security data repository for automation, reporting and compliance of firewall rules
https://fwo.cactus.de
Apache License 2.0
32 stars 11 forks source link

import - review & rework database incl. import in stored-procedures #1509

Open tpurschke opened 2 years ago

tpurschke commented 2 years ago

for current stored procedure and error handling structure overview, see roles/database/files/sql/idempotent/fworch-import-main.sql

Challenges

Import

Rule order calculation

Section header handling

traffic query simulation

Others

Immediate tasks

Midterm tasks

Rename columns

management

Others

exception when others then

raise notice 'The transaction is in an uncommittable state. '
             'Transaction was rolled back';

raise notice '% %', SQLERRM, SQLSTATE;

end;


first ideas:
- [x] archive (data older than 3 years)
- [ ] non-active data (changed objects, rules)
- [ ] active (current) data
tpurschke commented 2 years ago

sample import times prod

Mar  4 04:49:12 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 04:49:12,983 - INFO - import_management: import no. 68423 for management fwmforti211__AnonAAAY (id=44) successful, change_count: 0, duration: 2302s
Mar  4 05:06:01 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:06:01,412 - INFO - import_management: import no. 68424 for management fwmforti211__AnonAABS (id=45) successful, change_count: 0, duration: 1008s
Mar  4 05:06:18 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:06:18,864 - INFO - import_management: import no. 68425 for management fwmforti211__AnonAABX (id=46) successful, change_count: 0, duration: 17s
Mar  4 05:06:32 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:06:32,505 - INFO - import_management: import no. 68426 for management fwmforti211__AnonAABX-Myra (id=47) successful, change_count: 0, duration: 14s
Mar  4 05:06:58 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:06:58,019 - INFO - import_management: import no. 68427 for management fwmforti211__AnonAABX-Service (id=48) successful, change_count: 0, duration: 26s
Mar  4 05:07:17 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:07:17,669 - INFO - import_management: import no. 68428 for management fwmforti211__AnonAACF (id=49) successful, change_count: 0, duration: 19s
Mar  4 05:07:23 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:07:23,551 - INFO - import_management: import no. 68429 for management fwmforti211__AnonAACF_V6-2 (id=50) successful, change_count: 0, duration: 6s
Mar  4 05:07:34 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:07:34,901 - INFO - import_management: import no. 68430 for management fwmforti211__AnonAACR (id=51) successful, change_count: 0, duration: 11s
Mar  4 05:22:24 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 05:22:24,006 - INFO - import_management: import no. 68431 for management fwmforti211__AnonAACXS (id=52) successful, change_count: 0, duration: 890s
Mar  4 08:48:17 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 08:48:17,997 - INFO - import_management: import no. 68432 for management fwmforti211__AnonAACXS-fpdc300 (id=56) successful, change_count: 7, duration: 12353s
Mar  4 09:03:05 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:03:05,176 - INFO - import_management: import no. 68433 for management fwmforti211__AnonAACXS-Internet (id=53) successful, change_count: 54, duration: 887s
Mar  4 09:04:43 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:04:43,375 - INFO - import_management: import no. 68434 for management fwmforti211__AnonAACXS-PublicCloud (id=54) successful, change_count: 0, duration: 98s
Mar  4 09:05:47 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:05:47,697 - INFO - import_management: import no. 68435 for management fwmforti211__AnonAACXS-Testnetz-6-0 (id=55) successful, change_count: 0, duration: 64s
Mar  4 09:17:46 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:17:46,297 - INFO - import_management: import no. 68436 for management fwmforti211__AnonAACXS_V6-0 (id=57) successful, change_count: 0, duration: 719s
Mar  4 09:18:06 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:18:06,973 - INFO - import_management: import no. 68437 for management fwmforti211__AnonAADL (id=59) successful, change_count: 0, duration: 20s
Mar  4 09:21:43 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:21:43,816 - INFO - import_management: import no. 68438 for management fwmforti211__AnonAAEJW (id=60) successful, change_count: 0, duration: 216s
Mar  4 09:21:54 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:21:54,611 - INFO - import_management: import no. 68439 for management fwmforti211__AnonAAEQ-IT (id=61) successful, change_count: 0, duration: 11s
Mar  4 09:24:12 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:24:12,819 - INFO - import_management: import no. 68440 for management fwmforti211__root (id=62) successful, change_count: 0, duration: 138s
Mar  4 09:31:14 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:31:14,543 - INFO - import_management: import no. 68441 for management fwmsmarttest21 (id=125) successful, change_count: 4, duration: 422s
Mar  4 09:31:15 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:31:15,253 - INFO - import_management: import no. 68442 for management AnonAAEJW_America_sckp091 (id=9) threw errors, change_count: 0, duration: 1s, ERRORS:   login failed: mgm_id=9, mgm_name=AnonAAEJW_America_sckp091, Login to FW management failed
Mar  4 09:31:15 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:31:15,463 - INFO - import_management - import disabled for mgm 76
Mar  4 09:31:16 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:31:16,068 - INFO - import_management: import no. 68443 for management AnonAAEJW_MDS__Mgmt-Cluster_America (id=124) threw errors, change_count: 0, duration: 1s, ERRORS:   login failed: mgm_id=124, mgm_name=AnonAAEJW_MDS__Mgmt-Cluster_America, Login to FW management failed
Mar  4 09:33:24 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:24,258 - INFO - import_management: import no. 68444 for management fwmcp21 (id=75) successful, change_count: 0, duration: 3s
Mar  4 09:33:26 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:26,399 - INFO - import_management: import no. 68445 for management fwmcp21__AnonAAAZ (id=104) successful, change_count: 0, duration: 2s
Mar  4 09:33:28 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:28,683 - INFO - import_management: import no. 68446 for management fwmcp21__AnonAABT (id=105) successful, change_count: 0, duration: 2s
Mar  4 09:33:30 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:30,688 - INFO - import_management: import no. 68447 for management fwmcp21__AnonAACGbank (id=106) successful, change_count: 0, duration: 2s
Mar  4 09:33:33 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:33,071 - INFO - import_management: import no. 68448 for management fwmcp21__fi (id=107) successful, change_count: 0, duration: 3s
Mar  4 09:33:35 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:35,081 - INFO - import_management: import no. 68449 for management fwmcp21__AnonAACT (id=108) successful, change_count: 0, duration: 2s
Mar  4 09:33:35 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:35,286 - ERROR - import_management - failed to get import lock for management id 109
Mar  4 09:33:37 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 09:33:37,490 - INFO - import_management: import no. 68451 for management fwmcp21__fwras21_maindomain (id=110) successful, change_count: 0, duration: 2s
Mar  4 11:48:31 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:48:31,706 - INFO - import_management: import no. 68452 for management fwmcp21__AnonAADN (id=111) successful, change_count: 11, duration: 8094s
Mar  4 11:48:34 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:48:34,275 - INFO - import_management: import no. 68453 for management fwmcp21__AnonAAEF (id=112) successful, change_count: 0, duration: 2s
Mar  4 11:57:11 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:11,932 - INFO - import_management: import no. 68454 for management fwmcp21__AnonAAEL (id=113) successful, change_count: 4, duration: 517s
Mar  4 11:57:14 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:14,100 - INFO - import_management: import no. 68455 for management fwmcp21__AnonAAENbayern (id=115) successful, change_count: 0, duration: 2s
Mar  4 11:57:16 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:16,176 - INFO - import_management: import no. 68456 for management fwmcp21__AnonAAEN_it (id=114) successful, change_count: 0, duration: 2s
Mar  4 11:57:18 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:18,216 - INFO - import_management: import no. 68457 for management fwmcp21__AnonAAFD (id=116) successful, change_count: 0, duration: 2s
Mar  4 11:57:20 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:20,286 - INFO - import_management: import no. 68458 for management fwmcp21__AnonAAFW (id=117) successful, change_count: 0, duration: 2s
Mar  4 11:57:22 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:22,350 - INFO - import_management: import no. 68459 for management fwmcp21__ras_wartung (id=118) successful, change_count: 0, duration: 2s
Mar  4 11:57:24 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:24,417 - INFO - import_management: import no. 68460 for management fwmcp21__AnonAAFY (id=119) successful, change_count: 0, duration: 2s
Mar  4 11:57:26 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:26,730 - INFO - import_management: import no. 68461 for management fwmcp21__AnonAAGV (id=120) successful, change_count: 0, duration: 2s
Mar  4 11:57:28 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:28,890 - INFO - import_management: import no. 68462 for management fwmcp21__AnonAAGX (id=121) successful, change_count: 0, duration: 2s
Mar  4 11:57:30 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:30,925 - INFO - import_management: import no. 68463 for management fwmcp21__test (id=122) successful, change_count: 0, duration: 2s
Mar  4 11:57:33 orctstAnonAACZ202 fworch-importer-api[1700471]: 2022-03-04 11:57:33,090 - INFO - import_management: import no. 68464 for management fwmcp21__AnonAAHN (id=123) successful, change_count: 0, duration: 2s

Import Tests

2022-03-16 16:22:16,532 - DEBUG - writing debug config json files took 165s (debug level 4)

2022-03-16 16:30:39,464 - DEBUG - import_management: get_config completed (including normalization), duration: 5s
2022-03-16 16:30:43,187 - DEBUG - import_management - writing debug config json files duration 4s
2022-03-16 16:30:43,187 - DEBUG - import_management - getting config total duration 9s
2022-03-16 16:32:43,524 - DEBUG - import_management - writing config to API and stored procedure import duration: 120s
2022-03-16 16:32:44,770 - INFO - import_management: import no. 33223 for management cp4k (id=55) successful, change_count: 0, duration: 130s

Test new (manual)

fworch@debian11:~/importer$ ./import-mgm.py -m55 -i /home/tim/mgm_id_106_config_native.json.anon -d4
2022-03-27 11:08:13 [INFO ] [common.py :import_man: 169] starting import of management cp4k(55), import_id=38296
2022-03-27 11:08:15 [DEBUG] [common.py :get_config: 267] has_config_changed: changes found or forced mode -> go ahead with getting config, Force = False
2022-03-27 11:08:16 [DEBUG] [fwcommon.p:get_config:  79] parsing layer fwdwp21_prod Security
2022-03-27 11:08:16 [WARNI] [fwcommon.p:get_config:  90] get_config - found 6 nat rulebases and 3 rulebases
2022-03-27 11:08:16 [DEBUG] [fwcommon.p:get_config:  79] parsing layer xxx-Policy Security
2022-03-27 11:08:16 [WARNI] [fwcommon.p:get_config:  90] get_config - found 6 nat rulebases and 3 rulebases
2022-03-27 11:08:16 [DEBUG] [fwcommon.p:get_config:  79] parsing layer xxx-Policy Security
2022-03-27 11:08:16 [WARNI] [fwcommon.p:get_config:  90] get_config - found 6 nat rulebases and 3 rulebases
2022-03-27 11:08:16 [DEBUG] [common.py :get_config: 289] import_management: get_config completed (including normalization), duration: 3s
2022-03-27 11:08:23 [DEBUG] [common.py :get_config: 310] import_management - writing debug config json files duration 7s
2022-03-27 11:08:23 [DEBUG] [common.py :import_man: 195] import_management - getting config total duration 10s
2022-03-27 11:09:44 [INFO ] [common.py :complete_i: 344] import_management: import no. 38296 for management cp4k (id=55) successful, change_count: 0, duration: 91s
fworch@debian11:~/importer$ 
tpurschke commented 2 years ago

Import without indexes takes 189s:

    fworch@debian11:~/importer$ ./import-mgm.py -m55 -i /home/tim/mgm_id_106_config_native.json.anon -d3
    ...
    2022-03-27 18:00:42 [INFO ] [common.py :complete_i: 344] import_management: import no. 38555 for management cp4k (id=55) successful, change_count: 0, duration: 189s

Import with Indexes takes only 92s

    fworch@debian11:~/importer$ ./import-mgm.py -m55 -i /home/tim/mgm_id_106_config_native.json.anon -d3
    ...
    2022-03-27 18:04:03 [INFO ] [common.py :complete_i: 344] import_management: import no. 38562 for management cp4k (id=55) successful, change_count: 0, duration: 92s
    fworch@debian11:~/importer$ 

Import with 3 additional indexes takes only 20s:

    Create index FwoIndex001 on import_rule (rule_id);
    Create index FwoIndex002 on zone (zone_name,mgm_id);
    Create index FwoIndex003 on rule (rule_uid,mgm_id,dev_id,active,nat_rule,xlate_rule);

    fworch@debian11:~/importer$ ./import-mgm.py -m55 -i /home/tim/mgm_id_106_config_native.json.anon -d3
    ...
    2022-03-27 18:24:05 [INFO ] [common.py :complete_i: 344] import_management: import no. 38584 for management cp4k (id=55) successful, change_count: 0, duration: 20s
    fworch@debian11:~/importer$