Skip to content

Commit

Permalink
Add serial numbers in role, regenerate documentation and upgrade depe… (
Browse files Browse the repository at this point in the history
#143)

* add serial numbers in role, regenerate documentation and upgrade dependencies,fixing policy-infra and policy-tunnel update check.
  • Loading branch information
nareshkakubal authored Oct 31, 2023
1 parent a35718e commit 00e8728
Show file tree
Hide file tree
Showing 24 changed files with 248 additions and 86 deletions.
9 changes: 8 additions & 1 deletion banyan/resource_policy_infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,15 @@ func resourcePolicyInfraRead(ctx context.Context, d *schema.ResourceData, m inte
}

func resourcePolicyInfraUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) (diagnostics diag.Diagnostics) {
diagnostics = resourcePolicyInfraCreate(ctx, d, m)
c := m.(*client.Holder)
resp, err := c.Policy.Update(policyInfraFromState(d))
if err != nil {
return diag.FromErr(errors.WithMessage(err, "couldn't create new infra policy"))
}
d.SetId(resp.ID)
diagnostics = resourcePolicyInfraRead(ctx, d, m)
return

}

func resourcePolicyInfraDelete(ctx context.Context, d *schema.ResourceData, m interface{}) (diagnostics diag.Diagnostics) {
Expand Down
15 changes: 14 additions & 1 deletion banyan/resource_policy_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,20 @@ func resourcePolicyTunnelCreate(ctx context.Context, d *schema.ResourceData, m i
}

func resourcePolicyTunnelUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) (diagnostics diag.Diagnostics) {
diagnostics = resourcePolicyTunnelCreate(ctx, d, m)
c := m.(*client.Holder)

// ValidateFunc is not supported on lists or sets, so use this method instead
err := invalidL4AccessRules(d)
if err != nil {
return diag.FromErr(errors.WithMessage(err, "invalid l4_access block"))
}

createdPolicy, err := c.Policy.Update(policyTunnelFromState(d))
if err != nil {
return diag.FromErr(errors.WithMessage(err, "couldn't create new tunnel policy"))
}
d.SetId(createdPolicy.ID)
diagnostics = resourcePolicyTunnelRead(ctx, d, m)
return
}

Expand Down
2 changes: 1 addition & 1 deletion banyan/resource_policy_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func resourcePolicyWebUpdate(ctx context.Context, d *schema.ResourceData, m inte
if err != nil {
return diag.FromErr(errors.WithMessage(err, "invalid l7_access block"))
}
updatedPolicy, err := c.Policy.Update(d.State().ID, policyWebFromState(d))
updatedPolicy, err := c.Policy.Update(policyWebFromState(d))
if err != nil {
return diag.FromErr(errors.WithMessage(err, "couldn't create new web policy"))
}
Expand Down
20 changes: 13 additions & 7 deletions banyan/resource_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"container_fqdn": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "FQDN for the container",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -55,7 +54,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"image": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Image",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -64,7 +62,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"repo_tag": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Repo Tag",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -81,7 +78,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"user_group": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Names of the groups (from your IdP) which will be included in the role",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -90,7 +86,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"email": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Email addresses for the users in the role",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -99,7 +94,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"device_ownership": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Device ownership specification for the role",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -109,7 +103,6 @@ func RoleSchema() (s map[string]*schema.Schema) {
"platform": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "Platform type which is required by the role",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -126,6 +119,14 @@ func RoleSchema() (s map[string]*schema.Schema) {
Optional: true,
Description: "Enforces whether the role requires an MDM to be present on the device",
},
"serial_numbers": {
Type: schema.TypeSet,
Optional: true,
Description: "Serial Numbers of devices to be applicable for role",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
return
}
Expand Down Expand Up @@ -155,6 +156,7 @@ func RoleFromState(d *schema.ResourceData) (r role.CreateRole) {
Platform: convertSchemaSetToStringSlice(d.Get("platform").(*schema.Set)),
KnownDeviceOnly: d.Get("known_device_only").(bool),
MDMPresent: d.Get("mdm_present").(bool),
SerialNumbers: convertSchemaSetToStringSlice(d.Get("serial_numbers").(*schema.Set)),
},
}
return
Expand Down Expand Up @@ -232,6 +234,10 @@ func resourceRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}
if err != nil {
return diag.FromErr(err)
}
err = d.Set("serial_numbers", resp.UnmarshalledSpec.Spec.SerialNumbers)
if err != nil {
return diag.FromErr(err)
}
return
}

Expand Down
5 changes: 5 additions & 0 deletions banyan/resource_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestSchemaRole_device_ownership(t *testing.T) {
"description": "[TF] Admins on corporate devices",
"user_group": []interface{}{"Admins"},
"device_ownership": []interface{}{"Corporate Dedicated", "Corporate Shared"},
"platform": []interface{}{"Windows"},
"serial_numbers": []interface{}{"DeviceSerial1"},
}
d := schema.TestResourceDataRaw(t, RoleSchema(), role_device_ownership)
role_obj := RoleFromState(d)
Expand Down Expand Up @@ -166,6 +168,7 @@ resource "banyan_role" "acceptance" {
known_device_only = true
mdm_present = true
platform = ["Windows", "macOS", "Linux", "iOS", "Android", "Unregistered"]
serial_numbers = ["First","Second","Third"]
}
`, name)
}
Expand All @@ -182,6 +185,7 @@ resource "banyan_role" "acceptance" {
email = ["john@marsha.com"]
device_ownership = ["Corporate Dedicated", "Employee Owned"]
mdm_present = true
serial_numbers = ["First"]
}
`, name)
}
Expand All @@ -199,6 +203,7 @@ resource "banyan_role" "acceptance" {
email = ["john@marsha.com"]
device_ownership = ["Corporate Dedicated", "Employee Owned"]
mdm_present = true
serial_numbers = ["First"]
}
`, name)
}
5 changes: 3 additions & 2 deletions banyan/specs/role/device-ownership.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"Corporate Dedicated",
"Corporate Shared"
],
"platform": null,
"platform": ["Windows"],
"known_device_only": false,
"mdm_present": false
"mdm_present": false,
"serial_numbers": ["DeviceSerial1"]
}
}
4 changes: 2 additions & 2 deletions client/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Client interface {
Get(id string) (spec GetPolicy, err error)
GetName(name string) (spec GetPolicy, err error)
Create(policy Object) (created GetPolicy, err error)
Update(id string, policy Object) (updated GetPolicy, err error)
Update(policy Object) (updated GetPolicy, err error)
Delete(id string) (err error)
Detach(paClient policyattachment.Client, id string) (err error)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (p *policy) Create(policy Object) (created GetPolicy, err error) {
return
}

func (p *policy) Update(id string, policy Object) (updated GetPolicy, err error) {
func (p *policy) Update(policy Object) (updated GetPolicy, err error) {
log.Printf("[INFO] Updating policy %s", policy.Name)
body, err := json.Marshal(policy)
if err != nil {
Expand Down
42 changes: 2 additions & 40 deletions client/role/model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package role

import "sync"

// Info represents the specification of a role populated by json.Unmarshal.
type Info struct {
Kind string `json:"kind"`
Expand Down Expand Up @@ -39,49 +37,13 @@ type Spec struct {
Platform []string `json:"platform"`
KnownDeviceOnly bool `json:"known_device_only"`
MDMPresent bool `json:"mdm_present"`

SerialNumbers []string `json:"serial_numbers"`
}

// RepoTagList is a list of repo:tag strings within a role.Spec.
type RepoTagList []string

// Records keeps track of role definitions and the record of
// which containers can take on which roles.
type Records struct {
sync.RWMutex
}

// ServiceAccounter is any type that implements the ServiceAccount() method.
type ServiceAccounter interface {
ServiceAccount(containerID string) string
}

// Diff is returned by Records.CheckNonExistentRoles() and is used to report a new set of roles (could be empty) for a container.
type Diff struct {
// ContainerID identifies a container
ContainerID string
// Roles are all the roles the corresponding container can take on
Roles []string
// Versions are the corresponding role versions : len(Versions) == len(Roles)
Versions []int
}

type UserClaims struct {
Name string
Email string
Phone string
Groups []string
}

type DeviceClaims struct {
DeviceID string
SerialNumber string
DeviceOwnership string
Platform string
MDMPresent bool
IsStagedInstall bool
Unregistered bool
}

// LabSel represents a label map within a role.Spec.
type LabSel map[string]string

Expand Down
9 changes: 9 additions & 0 deletions docs/data-sources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Obtains information describing the role from banyan
```terraform
data "banyan_role" "example" {
name = "my-example-policy"
description = "realdescription"
container_fqdn = ["asdf.asdf"]
known_device_only = true
platform = ["macOS", "Android"]
user_group = ["group1", "group2"]
email = ["john@marsha.com"]
device_ownership = ["Corporate Dedicated", "Employee Owned"]
mdm_present = true
serial_numbers = ["DeviceSerial1"]
}
resource "banyan_service_web" "example" {
Expand Down
29 changes: 28 additions & 1 deletion docs/resources/accesstier.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,31 @@ resource "banyan_policy_tunnel" "anyone-high" {
- `id` (String) ID of the access tier in Banyan
## Import
Import is supported using the following syntax:
{{codefile "shell" "/Users/naresh/banyan/banyansecurity-terraform-provider-banyan/examples/resources/banyan_accesstier/import.sh"}}
```shell
# For importing a resource we require resource Id, which can be obtained from console for the resource we are importing
# And we need to create an entry in .tf file which represents the resource which would be imported.
# for e.g adding an entry into main.tf
# main.tf:
# resource "banyan_accesstier" "myexample" {
# name = "myexample"
# }

terraform import banyan_accesstier.myexample 46f3a708-2a9a-4c87-b18e-b11b6c92bf24

terraform show
# update thw show output configuration into above main.tf file, then resource is managed.
# BE CAUTIOUS before terraform apply, do terraform plan and verify there are no changes to be applied.

# Terraform Version 1.5.x or Later:
# We can create Import tf files
# for e.g
# import.tf:
# import {
# to = banyan_accesstier.myexample
# id = "46f3a708-2a9a-4c87-b18e-b11b6c92bf24"
# }
# Then execute
terraform plan -generate-config-out=generated.tf
# Configurations are imported into generated.tf edit and verify
# BE CAUTIOUS before terraform apply, do terraform plan and verify there are no changes to be applied.
```
29 changes: 28 additions & 1 deletion docs/resources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,31 @@ resource "banyan_service_tunnel" "example" {
- `id` (String) ID of the connector in Banyan
## Import
Import is supported using the following syntax:
{{codefile "shell" "/Users/naresh/banyan/banyansecurity-terraform-provider-banyan/examples/resources/banyan_connector/import.sh"}}
```shell
# For importing a resource we require resource Id, which can be obtained from console for the resource we are importing
# And we need to create an entry in .tf file which represents the resource which would be imported.
# for e.g adding an entry into main.tf
# main.tf:
# resource "banyan_connector" "myexample" {
# name = "myexample"
# }

terraform import banyan_connector.myexample 46f3a708-2a9a-4c87-b18e-b11b6c92bf24

terraform show
# update thw show output configuration into above main.tf file, then resource is managed.
# BE CAUTIOUS before terraform apply, do terraform plan and verify there are no changes to be applied.

# Terraform Version 1.5.x or Later:
# We can create Import tf files
# for e.g
# import.tf:
# import {
# to = banyan_connector.myexample
# id = "46f3a708-2a9a-4c87-b18e-b11b6c92bf24"
# }
# Then execute
terraform plan -generate-config-out=generated.tf
# Configurations are imported into generated.tf edit and verify
# BE CAUTIOUS before terraform apply, do terraform plan and verify there are no changes to be applied.
```
1 change: 1 addition & 0 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ resource "banyan_role" "example" {
- `mdm_present` (Boolean) Enforces whether the role requires an MDM to be present on the device
- `platform` (Set of String) Platform type which is required by the role
- `repo_tag` (Set of String) Repo Tag
- `serial_numbers` (Set of String) Serial Numbers of devices to be applicable for role
- `service_account` (Set of String) Service accounts to be included in the role
- `user_group` (Set of String) Names of the groups (from your IdP) which will be included in the role

Expand Down
17 changes: 17 additions & 0 deletions docs/resources/service_db.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ Optional:

- `cidrs` (List of String)
- `hostnames` (List of String)
- `ports` (Block Set, Max: 1) (see [below for nested schema](#nestedblock--allow_patterns--ports))

<a id="nestedblock--allow_patterns--ports"></a>
### Nested Schema for `allow_patterns.ports`

Optional:

- `port_list` (List of Number)
- `port_range` (Block List) (see [below for nested schema](#nestedblock--allow_patterns--ports--port_range))

<a id="nestedblock--allow_patterns--ports--port_range"></a>
### Nested Schema for `allow_patterns.ports.port_range`

Required:

- `max` (Number)
- `min` (Number)

## Import

Expand Down
Loading

0 comments on commit 00e8728

Please sign in to comment.