Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add resolve action to allowed gateway rules #1615

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1615.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
teams_rules: add "resolve" to allowable actions
```
11 changes: 7 additions & 4 deletions teams_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ type TeamsFilterType string
type TeamsGatewayAction string

const (
HttpFilter TeamsFilterType = "http"
DnsFilter TeamsFilterType = "dns"
L4Filter TeamsFilterType = "l4"
EgressFilter TeamsFilterType = "egress"
HttpFilter TeamsFilterType = "http"
DnsFilter TeamsFilterType = "dns"
L4Filter TeamsFilterType = "l4"
EgressFilter TeamsFilterType = "egress"
DnsResolverFilter TeamsFilterType = "dns_resolver"
)

const (
Expand All @@ -167,6 +168,7 @@ const (
L4Override TeamsGatewayAction = "l4_override" // l4
Egress TeamsGatewayAction = "egress" // egress
AuditSSH TeamsGatewayAction = "audit_ssh" // l4
Resolve TeamsGatewayAction = "resolve" // resolve
)

func TeamsRulesActionValues() []string {
Expand All @@ -185,6 +187,7 @@ func TeamsRulesActionValues() []string {
string(L4Override),
string(Egress),
string(AuditSSH),
string(Resolve),
}
}

Expand Down
69 changes: 69 additions & 0 deletions teams_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,75 @@ func TestTeamsCreateL4Rule(t *testing.T) {
}
}

func TestTeamsCreateResolverPolicy(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"name": "resolve 4.4.4.4",
"description": "rule description",
"precedence": 1000,
"enabled": true,
"action": "resolve",
"filters": [
"dns_resolver"
],
"traffic": "any(dns.domains[*] == \"scottstots.com\")",
"identity": "",
"rule_settings": {
"audit_ssh": { "command_logging": true },
"resolve_dns_through_cloudflare": true
}
}
}
`)
}

want := TeamsRule{
Name: "resolve 4.4.4.4",
Description: "rule description",
Precedence: 1000,
Enabled: true,
Action: Resolve,
Filters: []TeamsFilterType{DnsResolverFilter},
Traffic: `any(dns.domains[*] == "scottstots.com")`,
Identity: "",
DevicePosture: "",
RuleSettings: TeamsRuleSettings{
BlockPageEnabled: false,
BlockReason: "",
OverrideIPs: nil,
OverrideHost: "",
L4Override: nil,
AddHeaders: nil,
BISOAdminControls: nil,
CheckSession: nil,
InsecureDisableDNSSECValidation: false,
EgressSettings: nil,
AuditSSH: &AuditSSHRuleSettings{
CommandLogging: true,
},
ResolveDnsThroughCloudflare: BoolPtr(true),
},
DeletedAt: nil,
}

mux.HandleFunc("/accounts/"+testAccountID+"/gateway/rules", handler)

actual, err := client.TeamsCreateRule(context.Background(), testAccountID, want)

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}

func TestTeamsUpdateRule(t *testing.T) {
setup()
defer teardown()
Expand Down