Skip to content

Commit

Permalink
Add PUSH and PURGE denial to mid tier caches. (#5292) (#5302)
Browse files Browse the repository at this point in the history
(cherry picked from commit 97382c9)

Co-authored-by: alficles <[email protected]>
  • Loading branch information
rawlinp and alficles authored Nov 18, 2020
1 parent 6e0a5e7 commit 817a702
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/go-atscfg/ipallowdotconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ func MakeIPAllowDotConfig(
// order matters, so sort before adding the denys
sort.Sort(IPAllowDatas(ipAllowData))

// start with a deny for PUSH and PURGE - TODO CDL: parameterize
if isMid { // Edges already deny PUSH and PURGE
ipAllowData = append([]IPAllowData{
{
Src: `0.0.0.0-255.255.255.255`,
Action: ActionDeny,
Method: `PUSH|PURGE`,
},
{
Src: `::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff`,
Action: ActionDeny,
Method: `PUSH|PURGE`,
},
}, ipAllowData...)
}

// end with a deny
ipAllowData = append(ipAllowData, IPAllowData{
Src: `0.0.0.0-255.255.255.255`,
Expand Down
20 changes: 20 additions & 0 deletions lib/go-atscfg/ipallowdotconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ func TestMakeIPAllowDotConfig(t *testing.T) {

lines = lines[1:] // remove comment line

/* Test that PUSH and PURGE are denied ere the allowance of anything else. */
{
ip4deny := false
ip6deny := false
eachLine:
for i, line := range lines {
switch {
case strings.Contains(line, `0.0.0.0-255.255.255.255`) && strings.Contains(line, `ip_deny`) && strings.Contains(line, `PUSH`) && strings.Contains(line, `PURGE`):
ip4deny = true
case strings.Contains(line, `::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff`) && strings.Contains(line, `ip_deny`) && strings.Contains(line, `PUSH`) && strings.Contains(line, `PURGE`):
ip6deny = true
case strings.Contains(line, `ip_allow`):
if !(ip4deny && ip6deny) {
t.Errorf("Expected denies for PUSH and PURGE before any ips are allowed; pre-denial allowance on line %d.", i+1)
}
break eachLine
}
}
}

for _, expected := range expecteds {
if !strings.Contains(txt, expected) {
t.Errorf("expected %+v actual '%v'\n", expected, txt)
Expand Down

0 comments on commit 817a702

Please sign in to comment.