Skip to content

Commit

Permalink
feat(Policies.Security): Adding group-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Nov 24, 2021
1 parent 50e89f7 commit a3aef92
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions poli/security/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Entry struct {
FileBlocking string
WildFireAnalysis string
DataFiltering string
GroupTag string // PAN-OS 9.0+
Uuid string // PAN-OS 9.0+
SourceDevices []string // PAN-OS 10.0+
DestinationDevices []string // PAN-OS 10.0+
Expand Down Expand Up @@ -153,6 +154,7 @@ func (o *Entry) Copy(s Entry) {
o.FileBlocking = s.FileBlocking
o.WildFireAnalysis = s.WildFireAnalysis
o.DataFiltering = s.DataFiltering
o.GroupTag = s.GroupTag
o.SourceDevices = util.CopyStringSlice(s.SourceDevices)
o.DestinationDevices = util.CopyStringSlice(s.DestinationDevices)
}
Expand Down Expand Up @@ -405,6 +407,7 @@ func (o *entry_v2) normalize() Entry {
Disabled: util.AsBool(o.Disabled),
Schedule: o.Schedule,
IcmpUnreachable: util.AsBool(o.IcmpUnreachable),
GroupTag: o.GroupTag,
}
if o.Options != nil {
ans.DisableServerResponseInspection = util.AsBool(o.Options.DisableServerResponseInspection)
Expand Down Expand Up @@ -457,6 +460,7 @@ type entry_v2 struct {
Options *secOptions `xml:"option"`
TargetInfo *targetInfo `xml:"target"`
ProfileSettings *profileSettings `xml:"profile-setting"`
GroupTag string `xml:"group-tag,omitempty"`
}

func (e *entry_v2) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
Expand Down Expand Up @@ -497,6 +501,7 @@ func specify_v2(e Entry) interface{} {
Schedule: e.Schedule,
IcmpUnreachable: util.YesNo(e.IcmpUnreachable),
Options: &secOptions{util.YesNo(e.DisableServerResponseInspection)},
GroupTag: e.GroupTag,
}
if e.Targets != nil || e.NegateTarget {
nfo := &targetInfo{
Expand Down Expand Up @@ -574,6 +579,7 @@ func (o *entry_v3) normalize() Entry {
Disabled: util.AsBool(o.Disabled),
Schedule: o.Schedule,
IcmpUnreachable: util.AsBool(o.IcmpUnreachable),
GroupTag: o.GroupTag,
SourceDevices: util.MemToStr(o.SourceDevices),
DestinationDevices: util.MemToStr(o.DestinationDevices),
}
Expand Down Expand Up @@ -628,6 +634,7 @@ type entry_v3 struct {
Options *secOptions `xml:"option"`
TargetInfo *targetInfo `xml:"target"`
ProfileSettings *profileSettings `xml:"profile-setting"`
GroupTag string `xml:"group-tag,omitempty"`
SourceDevices *util.MemberType `xml:"source-hip"`
DestinationDevices *util.MemberType `xml:"destination-hip"`
}
Expand Down Expand Up @@ -670,6 +677,7 @@ func specify_v3(e Entry) interface{} {
Schedule: e.Schedule,
IcmpUnreachable: util.YesNo(e.IcmpUnreachable),
Options: &secOptions{util.YesNo(e.DisableServerResponseInspection)},
GroupTag: e.GroupTag,
SourceDevices: util.StrToMem(e.SourceDevices),
DestinationDevices: util.StrToMem(e.DestinationDevices),
}
Expand Down
49 changes: 49 additions & 0 deletions poli/security/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ func getTests() []testCase {
Action: "allow",
LogEnd: true,
}},
{version.Number{9, 0, 0, ""}, "rule with group tag", "", "", Entry{
Name: "rule1",
Type: "universal",
SourceZones: []string{"sz1", "sz2"},
SourceAddresses: []string{"sa1", "sa2"},
SourceUsers: []string{"su1", "su2"},
HipProfiles: []string{"hp3", "hp2", "hp1"},
DestinationZones: []string{"dz1", "dz2"},
DestinationAddresses: []string{"da1", "da2"},
Applications: []string{"app1"},
Services: []string{"s2", "s1"},
Categories: []string{"cat1"},
Action: "allow",
LogEnd: false,
GroupTag: "oneTime",
}},
{version.Number{10, 0, 0, ""}, "basic rule", "", "", Entry{
Name: "rule1",
Type: "universal",
Expand Down Expand Up @@ -217,5 +233,38 @@ func getTests() []testCase {
Action: "allow",
LogEnd: false,
}},
{version.Number{10, 0, 0, ""}, "rule with group tag", "", "", Entry{
Name: "rule1",
Type: "universal",
SourceZones: []string{"sz1", "sz2"},
SourceAddresses: []string{"sa1", "sa2"},
SourceUsers: []string{"su1", "su2"},
HipProfiles: []string{"hp3", "hp2", "hp1"},
DestinationZones: []string{"dz1", "dz2"},
DestinationAddresses: []string{"da1", "da2"},
Applications: []string{"app1"},
Services: []string{"s2", "s1"},
Categories: []string{"cat1"},
Action: "allow",
LogEnd: true,
GroupTag: "oneTime",
}},
{version.Number{10, 0, 0, ""}, "rule with source and dst devices", "", "", Entry{
Name: "rule1",
Type: "universal",
SourceZones: []string{"sz1", "sz2"},
SourceAddresses: []string{"sa1", "sa2"},
SourceUsers: []string{"su1", "su2"},
HipProfiles: []string{"hp3", "hp2", "hp1"},
DestinationZones: []string{"dz1", "dz2"},
DestinationAddresses: []string{"da1", "da2"},
Applications: []string{"app1"},
Services: []string{"s2", "s1"},
Categories: []string{"cat1"},
Action: "allow",
LogEnd: true,
SourceDevices: []string{"src2", "src1"},
DestinationDevices: []string{"dstDev"},
}},
}
}

0 comments on commit a3aef92

Please sign in to comment.