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

Add support for breached_password_detection.stage on auth0_attack_protection resource #445

Merged
merged 12 commits into from
Jan 27, 2023
13 changes: 13 additions & 0 deletions docs/resources/attack_protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ resource "auth0_attack_protection" "my_protection" {
enabled = true
method = "standard"
shields = ["admin_notification", "block"]

pre_user_registration {
shields = ["block"]
}
}
}
```
Expand All @@ -66,8 +70,17 @@ Optional:
- `admin_notification_frequency` (Set of String) When "admin_notification" is enabled, determines how often email notifications are sent. Possible values: `immediately`, `daily`, `weekly`, `monthly`.
- `enabled` (Boolean) Whether breached password detection is active.
- `method` (String) The subscription level for breached password detection methods. Use "enhanced" to enable Credential Guard. Possible values: `standard`, `enhanced`.
- `pre_user_registration` (Block List, Max: 1) Configuration options that apply before every user registration attempt. Only available on public tenants. (see [below for nested schema](#nestedblock--breached_password_detection--pre_user_registration))
- `shields` (Set of String) Action to take when a breached password is detected.

<a id="nestedblock--breached_password_detection--pre_user_registration"></a>
### Nested Schema for `breached_password_detection.pre_user_registration`

Optional:

- `shields` (Set of String) Action to take when a breached password is detected during a signup. Possible values: `block`, `admin_notification`.
nialdaly marked this conversation as resolved.
Show resolved Hide resolved



<a id="nestedblock--brute_force_protection"></a>
### Nested Schema for `brute_force_protection`
Expand Down
4 changes: 4 additions & 0 deletions examples/resources/auth0_attack_protection/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ resource "auth0_attack_protection" "my_protection" {
enabled = true
method = "standard"
shields = ["admin_notification", "block"]

pre_user_registration {
shields = ["block"]
}
}
}
52 changes: 52 additions & 0 deletions internal/provider/resource_auth0_attack_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ func newAttackProtection() *schema.Resource {
Description: "The subscription level for breached password detection methods. " +
"Use \"enhanced\" to enable Credential Guard. Possible values: `standard`, `enhanced`.",
},
"pre_user_registration": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: "Configuration options that apply before every user registration attempt. " +
"Only available on public tenants.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"shields": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"block",
"admin_notification",
}, false),
},
Description: "Action to take when a breached password is detected during " +
"a signup. Possible values: `block`, `admin_notification`.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -371,6 +397,11 @@ func flattenBreachedPasswordProtection(bpd *management.BreachedPasswordDetection
"method": bpd.GetMethod(),
"admin_notification_frequency": bpd.GetAdminNotificationFrequency(),
"shields": bpd.GetShields(),
nialdaly marked this conversation as resolved.
Show resolved Hide resolved
"pre_user_registration": []interface{}{
map[string][]string{
"shields": bpd.GetStage().GetPreUserRegistration().GetShields(),
},
},
},
}
}
Expand Down Expand Up @@ -490,6 +521,27 @@ func expandBreachedPasswordDetection(d *schema.ResourceData) *management.Breache
AdminNotificationFrequency: value.Strings(breach.GetAttr("admin_notification_frequency")),
}

pur := breach.GetAttr("pre_user_registration")
if !pur.IsNull() {
pur.ForEachElement(
func(_ cty.Value, preUserReg cty.Value) (stop bool) {
preUserRegistration := &management.BreachedPasswordDetectionPreUserRegistration{
Shields: value.Strings(preUserReg.GetAttr("shields")),
}

if bpd.Stage != nil {
bpd.Stage.PreUserRegistration = preUserRegistration
} else {
bpd.Stage = &management.BreachedPasswordDetectionStage{
PreUserRegistration: preUserRegistration,
}
}

return stop
},
)
}

return stop
},
)
Expand Down
18 changes: 14 additions & 4 deletions internal/provider/resource_auth0_attack_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ resource "auth0_attack_protection" "my_protection" {
shields = ["admin_notification","block"]
admin_notification_frequency = ["daily", "monthly"]
method = "standard"

pre_user_registration {
shields = ["block"]
}
}
}
`
Expand All @@ -34,6 +38,10 @@ resource "auth0_attack_protection" "my_protection" {
shields = ["user_notification", "block", "admin_notification"]
admin_notification_frequency = ["daily", "monthly", "immediately", "weekly"]
method = "standard"

pre_user_registration {
shields = ["admin_notification"]
}
}
}
`
Expand All @@ -58,7 +66,7 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "brute_force_protection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "suspicious_ip_throttling.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "4"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "5"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.enabled", "true"),
),
},
Expand All @@ -68,13 +76,14 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "brute_force_protection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "suspicious_ip_throttling.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "4"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "5"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.enabled", "true"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.shields.*", "admin_notification"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.shields.*", "block"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.admin_notification_frequency.*", "daily"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.admin_notification_frequency.*", "monthly"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.method", "standard"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.pre_user_registration.0.shields.*", "block"),
),
},
{
Expand All @@ -83,7 +92,7 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "brute_force_protection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "suspicious_ip_throttling.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "4"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "5"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.enabled", "true"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.shields.*", "admin_notification"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.shields.*", "block"),
Expand All @@ -93,6 +102,7 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) {
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.admin_notification_frequency.*", "immediately"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.admin_notification_frequency.*", "weekly"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.method", "standard"),
resource.TestCheckTypeSetElemAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.pre_user_registration.0.shields.*", "admin_notification"),
),
},
{
Expand All @@ -101,7 +111,7 @@ func TestAccAttackProtectionBreachedPasswordDetection(t *testing.T) {
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "brute_force_protection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "suspicious_ip_throttling.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.#", "1"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "4"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.%", "5"),
resource.TestCheckResourceAttr("auth0_attack_protection.my_protection", "breached_password_detection.0.enabled", "false"),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["daily","monthly"],"method":"standard"}
{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["daily","monthly"],"method":"standard","stage":{"pre-user-registration":{"shields":["block"]}}}
form: { }
headers:
Content-Type:
Expand All @@ -390,7 +390,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["block","admin_notification"],"admin_notification_frequency":["daily","monthly"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["block","admin_notification"],"admin_notification_frequency":["daily","monthly"],"method":"standard","stage":{"pre-user-registration":{"shields":["block"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -426,7 +426,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":["block"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -534,7 +534,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":["block"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -642,7 +642,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","block"],"admin_notification_frequency":["monthly","daily"],"method":"standard","stage":{"pre-user-registration":{"shields":["block"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -733,7 +733,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"enabled":true,"shields":["admin_notification","block","user_notification"],"admin_notification_frequency":["daily","immediately","monthly","weekly"],"method":"standard"}
{"enabled":true,"shields":["admin_notification","block","user_notification"],"admin_notification_frequency":["daily","immediately","monthly","weekly"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}
form: { }
headers:
Content-Type:
Expand All @@ -750,7 +750,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["block","user_notification","admin_notification"],"admin_notification_frequency":["daily","immediately","monthly","weekly"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["block","user_notification","admin_notification"],"admin_notification_frequency":["daily","immediately","monthly","weekly"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -786,7 +786,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -894,7 +894,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -1002,7 +1002,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":true,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -1110,7 +1110,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -1146,7 +1146,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -1254,7 +1254,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
nialdaly marked this conversation as resolved.
Show resolved Hide resolved
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -1362,7 +1362,7 @@ interactions:
trailer: { }
content_length: -1
uncompressed: true
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":[]}}}'
body: '{"enabled":false,"shields":["admin_notification","user_notification","block"],"admin_notification_frequency":["weekly","monthly","daily","immediately"],"method":"standard","stage":{"pre-user-registration":{"shields":["admin_notification"]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down