palo_alto 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +1 -0
- data/examples/test_config.rb +31 -15
- data/examples/test_op.rb +52 -73
- data/lib/palo_alto/config.rb +75269 -51836
- data/lib/palo_alto/op.rb +59 -38
- data/lib/palo_alto/version.rb +1 -1
- data/lib/palo_alto.rb +120 -56
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d9a8a70e1915fa8ed130e98c55d91a5851d385d7adcc1c13a18077771c3a0b2
|
4
|
+
data.tar.gz: 41ef6c1bcfc5021a949bd4636bf18821912afc5f2e71e6e941bcd27ff55ee03a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96efd9b2de4059173e9ec726481a5ef2c931a302e8bef4e1ab54cb7655771cbcbb6460165ebe30c0912a089dbbcf16d635af2c9189f345c979312a8fc60cf92f
|
7
|
+
data.tar.gz: 0d9eb96a1be8439b55b5a56e3d60fb40935b86cf950c2c329074b930ac14cd70f79594931e5aacfda3793fb16a0d78c3062c6a5b2db76496900188dbe383a196
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
Version 0.5.1: Breaking changes for op commands, to be able to build more complex scenarios
|
2
|
+
Version 0.5.0: Update schema for Panorama 11.0
|
1
3
|
Version 0.4.1: Update schema for Panorama 10.2 for op commands
|
2
4
|
Version 0.4.0: Update schema for Panorama 10.2 for config
|
3
5
|
Version 0.3.0: Update schema for Panorama 10.1
|
data/README.md
CHANGED
data/examples/test_config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'palo_alto'
|
2
4
|
|
3
5
|
client = PaloAlto::XML.new(host: 'panorama-test', username: 'admin', password: 'Admin123!',
|
@@ -6,11 +8,11 @@ dg = 'PLAYGROUND'
|
|
6
8
|
|
7
9
|
# create a tag
|
8
10
|
tag_name = 'test'
|
9
|
-
|
10
11
|
new_tag = client.config.devices.entry(name: 'localhost.localdomain').device_group.entry(name: dg).tag.entry(name: tag_name).create!
|
11
12
|
new_tag.color = 'color23'
|
12
|
-
new_tag.
|
13
|
+
new_tag.set!
|
13
14
|
|
15
|
+
# get rules
|
14
16
|
# filtered rules:
|
15
17
|
# rules = client.config.devices.entry(name:'localhost.localdomain').device_group.entry(name: 'PLAYGROUND').pre_rulebase.security.rules
|
16
18
|
# .entry{ (child(:source).child(:member).text == "Net_10.1.1.0-24").or(child(:destination).child(:member).text == 'Net_10.1.1.0-24') }
|
@@ -19,46 +21,60 @@ new_tag.push!
|
|
19
21
|
# or:
|
20
22
|
#
|
21
23
|
# filter = (PaloAlto.child(:source).child(:member).text == "Net_10.1.1.0-24").or(PaloAlto.child(:destination).child(:member).text == 'Net_10.1.1.0-24')
|
22
|
-
# puts filter.to_xpath
|
24
|
+
# puts filter.to_xpath # prints generated Xpath filter
|
23
25
|
# => ./source/member/text()='Net_10.1.1.0-24'or./destination/member/text()='Net_10.1.1.0-24'
|
24
26
|
#
|
25
27
|
# rules = client.config.devices.entry(name:'localhost.localdomain').device_group.entry(name: 'PLAYGROUND').pre_rulebase.security.rules
|
26
28
|
# .entry{filter}.get_all
|
27
|
-
|
29
|
+
|
28
30
|
# also more advanced filters are possible:
|
29
|
-
# PaloAlto.not(PaloAlto.child(:'profile-setting').child(:group).child(:member) == 'IPS-Policy').and(
|
31
|
+
# filter = PaloAlto.not(PaloAlto.child(:'profile-setting').child(:group).child(:member) == 'IPS-Policy').and(
|
30
32
|
# PaloAlto.parenthesis(
|
31
33
|
# (PaloAlto.child(:tag).child(:member) == 'ips_enabled').or(
|
32
34
|
# PaloAlto.child(:tag).child(:member) == 'ips_force_enabled'
|
33
35
|
# )
|
34
36
|
# )
|
35
|
-
# )
|
36
|
-
#
|
37
|
+
# )
|
38
|
+
# puts filter.to_xpath
|
37
39
|
# => not(./profile-setting/group/member='IPS-Policy')and(./tag/member='ips_enabled'or./tag/member='ips_force_enabled')
|
38
40
|
|
39
41
|
rules = client.config.devices.entry(name: 'localhost.localdomain').device_group.entry(name: dg).pre_rulebase.security.rules.entry{}.get_all
|
40
42
|
|
41
|
-
rules.
|
43
|
+
rules.select! { |rule| rule.api_attributes['loc'] == dg } # filter rules inherited from upper device groups
|
42
44
|
|
43
45
|
pp rules
|
44
46
|
pp rules.length
|
45
47
|
|
46
|
-
pp rules.first.api_attributes # attributes like uuid and loc
|
47
|
-
pp rules.first.values # values as hash
|
48
|
-
|
49
48
|
rule = rules.first
|
49
|
+
|
50
|
+
pp rule.api_attributes # attributes like uuid and loc
|
51
|
+
pp rule.values # values as hash
|
52
|
+
|
50
53
|
rule.tag.member = [new_tag.name]
|
51
54
|
rule.group_tag = new_tag.name
|
52
55
|
rule.description += '....'
|
53
|
-
rule.
|
56
|
+
rule.edit!
|
54
57
|
|
58
|
+
# renaming rules
|
55
59
|
puts rule.to_xpath
|
56
60
|
rule.rename!('Test 1')
|
57
61
|
puts rule.to_xpath
|
58
|
-
|
62
|
+
puts rule.name
|
59
63
|
|
60
|
-
|
64
|
+
# Bulk changes on multiple rules:
|
65
|
+
rules = client.config.devices.entry(name: 'localhost.localdomain').device_group.entry(name: dg).pre_rulebase.security.rules.get
|
66
|
+
|
67
|
+
rules.entries.each do |name, rule|
|
68
|
+
next unless rule.values.dig('profile-setting', 'group', 'member') == ['Internal-detect']
|
69
|
+
|
70
|
+
rule.profile_setting.group.member = ['Internal']
|
71
|
+
# to remove profile-setting: rule.delete_child('profile-setting')
|
72
|
+
end
|
73
|
+
puts "Pushing all rules to #{rules.to_xpath}"
|
74
|
+
rules.edit!
|
61
75
|
|
62
76
|
# create a new template
|
63
77
|
new_template = client.config.devices.entry(name: 'localhost.localdomain').template.entry(name: 'testtemplate').create!
|
64
|
-
new_template.
|
78
|
+
new_template.set!
|
79
|
+
|
80
|
+
exit 0
|
data/examples/test_op.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
require 'palo_alto'
|
4
|
+
load '/usr/share/panorama-api/new_op.rb'
|
5
|
+
|
6
|
+
a = { commit: { partial:
|
7
|
+
{ admin: ['admin'],
|
8
|
+
'no-template': true,
|
9
|
+
'no-template-stack': true,
|
10
|
+
'no-log-collector': true,
|
11
|
+
'no-log-collector-group': true,
|
12
|
+
'no-wildfire-appliance': true,
|
13
|
+
'no-wildfire-appliance-cluster': true,
|
14
|
+
'device-and-network': 'excluded',
|
15
|
+
'shared-object': 'excluded' } } }
|
14
16
|
|
15
17
|
b = { show: { devices: 'all' } }
|
16
18
|
|
17
19
|
c = { revert: { config: {
|
18
|
-
partial:
|
19
|
-
|
20
|
-
'no-template',
|
21
|
-
'no-template-stack',
|
22
|
-
'no-log-collector',
|
23
|
-
'no-log-collector-group',
|
24
|
-
'no-wildfire-appliance',
|
25
|
-
'no-wildfire-appliance-cluster',
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
partial: {
|
21
|
+
admin: ['admin'],
|
22
|
+
'no-template': true,
|
23
|
+
'no-template-stack': true,
|
24
|
+
'no-log-collector': true,
|
25
|
+
'no-log-collector-group': true,
|
26
|
+
'no-wildfire-appliance': true,
|
27
|
+
'no-wildfire-appliance-cluster': true,
|
28
|
+
'device-and-network': 'excluded',
|
29
|
+
'shared-object': 'excluded'
|
30
|
+
}
|
29
31
|
} } }
|
30
32
|
|
31
33
|
d = { commit: nil }
|
@@ -44,18 +46,20 @@ k = { check: 'full-commit-required' }
|
|
44
46
|
|
45
47
|
l = { show: { config: { 'commit-scope': { partial: { admin: ['admin'] } } } } }
|
46
48
|
|
49
|
+
m = { show: { config: { 'commit-scope': { partial: { admin: %w[admin1 admin2] } } } } }
|
50
|
+
|
47
51
|
push_to_device = { 'commit-all': { 'shared-policy': { 'device-group': [{ name: 'TEST-DG' }] } } }
|
48
52
|
|
49
53
|
# validate:
|
50
54
|
p = { 'commit-all':
|
51
55
|
{
|
52
|
-
'shared-policy':
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
'shared-policy': {
|
57
|
+
'device-group': [{ name: 'PLAYGROUND' }],
|
58
|
+
'include-template': 'yes',
|
59
|
+
'merge-with-candidate-cfg': 'yes',
|
60
|
+
'force-template-values': 'no',
|
61
|
+
'validate-only': 'yes'
|
62
|
+
}
|
59
63
|
} }
|
60
64
|
|
61
65
|
i = { show: { query: { result: { id: 10_438 } } } }
|
@@ -63,64 +67,39 @@ i = { show: { query: { result: { id: 10_438 } } } }
|
|
63
67
|
# hit counts:
|
64
68
|
device_group = 'PLAYGROUND'
|
65
69
|
|
66
|
-
|
70
|
+
hc1 = {
|
67
71
|
show: {
|
68
|
-
'rule-hit-count':
|
72
|
+
'rule-hit-count': {
|
69
73
|
'device-group': [{
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
entry: [{
|
75
|
-
name: 'security'
|
76
|
-
}, {
|
77
|
-
rules: 'all'
|
78
|
-
}]
|
79
|
-
}]
|
74
|
+
name: device_group,
|
75
|
+
'pre-rulebase': [{
|
76
|
+
name: 'security',
|
77
|
+
rules: ['all']
|
80
78
|
}]
|
81
79
|
}]
|
82
|
-
}
|
80
|
+
}
|
83
81
|
}
|
84
82
|
}
|
85
83
|
|
86
84
|
# hit count for one rule, with more details:
|
87
85
|
rule_name = 'Rule 27'
|
88
|
-
|
86
|
+
hc2 = {
|
89
87
|
show: {
|
90
|
-
'rule-hit-count':
|
88
|
+
'rule-hit-count': {
|
91
89
|
'device-group': [{
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
'
|
96
|
-
entry: [{
|
97
|
-
name: 'security'
|
98
|
-
}, {
|
99
|
-
rules: {
|
100
|
-
'rule-name': [{
|
101
|
-
entry: [{
|
102
|
-
name: rule_name
|
103
|
-
}]
|
104
|
-
}]
|
105
|
-
}
|
106
|
-
}]
|
107
|
-
}]
|
90
|
+
name: device_group,
|
91
|
+
'pre-rulebase': [{
|
92
|
+
name: 'security',
|
93
|
+
rules: { 'rule-name': [{ name: rule_name }] }
|
108
94
|
}]
|
109
95
|
}]
|
110
|
-
}
|
96
|
+
}
|
111
97
|
}
|
112
98
|
}
|
113
99
|
|
114
100
|
client = PaloAlto::XML.new(host: 'panorama-test', username: 'admin', password: 'Admin123!', debug: %i[sent received])
|
115
101
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
puts '---------------------------'
|
121
|
-
pp client.op.execute(e)
|
122
|
-
puts '---------------------------'
|
123
|
-
|
124
|
-
# pp client.op.execute(f)
|
125
|
-
|
126
|
-
pp client.op.execute(k)
|
102
|
+
[a, b, c, d, e, f, g, h, j, k, l, m, push_to_device, p, i, hc1, hc2].each do |cmd|
|
103
|
+
puts client.op.to_xml(cmd)
|
104
|
+
puts '---------------------------'
|
105
|
+
end
|