Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Add feature to create a Network Security Group in Azure - #200

Open
escortnotice wants to merge 11 commits into
crossplane-contrib:masterfrom
escortnotice:feature-nsg
Open

Add feature to create a Network Security Group in Azure#200
escortnotice wants to merge 11 commits into
crossplane-contrib:masterfrom
escortnotice:feature-nsg

Conversation

@escortnotice

@escortnotice escortnotice commented Nov 23, 2020

Copy link
Copy Markdown

Description of your changes

Create a Network Security Group, which can restrict inbound and outgoing traffic using 5tuple rules. Also restrict traffic based on Service tagging and Application Security Group.

Issue: #168

Fixes #

I have:

  • Read and followed Crossplane's [contribution process].
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Currently we have tested the code manually on azure cloud, all the configuration files (.yaml) are in the examples folder which can be referred for use.

Signed-off-by: shreya <shreynamdeo@gmail.com>
Signed-off-by: shreya <shreynamdeo@gmail.com>
Signed-off-by: shreya <shreynamdeo@gmail.com>
Signed-off-by: shreya <shreynamdeo@gmail.com>
@escortnotice escortnotice changed the title Feature nsg Add feature to create a Network Security Group in Azure #168 Nov 23, 2020
@escortnotice escortnotice changed the title Add feature to create a Network Security Group in Azure #168 Add feature to create a Network Security Group in Azure Nov 23, 2020
@muvaf
muvaf requested review from hasheddan and kasey November 23, 2020 14:58

@hasheddan hasheddan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@escortnotice thanks for your work here :) I have given a first pass review below, but also wanted to point you to these resources:

Also, I believe you will need an update to crossplane-runtime version here 👍 The errors in CI should give you some indication about other existing issues. Let me know if you have any questions!

Comment thread apis/network/v1alpha3/types.go Outdated

Spec SecurityGroupSpec `json:"spec"`
Status SecurityGroupStatus `json:"status,omitempty"`
///Properties SecurityGroupPropertiesFormat `json:"properties,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///Properties SecurityGroupPropertiesFormat `json:"properties,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change

}

// A SecurityGroupSpec defines the desired state of a SecurityGroup.
type SecurityGroupSpec struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious to know what is the significance of adding forProvider as it seems to be a level addition to me , and this is also not present in Virtualnetwork Resource.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have added forProvided in the SecurityGroupSpec Struct also.

Comment thread apis/network/v1alpha3/types.go Outdated
// SecurityRulePropertiesFormat security rule resource.
type SecurityRulePropertiesFormat struct {
// Description - A description for this rule. Restricted to 140 chars.
Description string `json:"description,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All optional spec fields should be pointer types.

Suggested change
Description string `json:"description,omitempty"`
Description *string `json:"description,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change

Comment thread apis/network/v1alpha3/types.go Outdated
SourcePortRange string `json:"sourcePortRange,omitempty"`
// DestinationPortRange - The destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.
DestinationPortRange string `json:"destinationPortRange,omitempty"`
// SourceAddressPrefix - The CIDR or source IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer that comments be wrapped at 80 chars :)

Comment thread apis/network/v1alpha3/register.go Outdated
SchemeBuilder.Register(&VirtualNetwork{}, &VirtualNetworkList{})
SchemeBuilder.Register(&Subnet{}, &SubnetList{})
SchemeBuilder.Register(&SecurityGroup{}, &SecurityGroupList{})
SchemeBuilder.Register(&SecurityRule{})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing there should also be a SecurityRuleList?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it intended that a SecurityRule just be in the spec of a SecurityGroup? If so, it should not be its own object, but it they are separate APIs on Azure then they should be separate Crossplane objects and the SecurityGroup should reference SecurityRule.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored SecurityRule as it is just a part of Security Group not a independent entity.

Comment thread pkg/controller/azure.go Outdated
package controller

import (
SecurityGroup "github.com/crossplane/provider-azure/pkg/controller/network/securitygroup"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SecurityGroup "github.com/crossplane/provider-azure/pkg/controller/network/securitygroup"
"github.com/crossplane/provider-azure/pkg/controller/network/securitygroup"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change

Comment thread pkg/controller/azure.go Outdated
resourcegroup.Setup,
account.Setup,
container.Setup,
SecurityGroup.Setup,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SecurityGroup.Setup,
securitygroup.Setup,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change

Comment on lines +24 to +26
//"github.com/crossplane/provider-azure/pkg/clients/network"

//"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-12-01/network/networkapi"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//"github.com/crossplane/provider-azure/pkg/clients/network"
//"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-12-01/network/networkapi"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change


type external struct {
client networkapi.SecurityGroupsClientAPI
//client azurenetwork.SecurityGroupsClient

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//client azurenetwork.SecurityGroupsClient

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have implemented this change

@@ -0,0 +1,470 @@
package SecurityGroup

import (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am unable to understand this statement , could you please share more details what changes are expected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We require imports to be structured in groups separated by a blank line in the following order:

  1. stdlib packages
  2. external packages (i.e. not from crossplane org)
  3. other crossplane org packages (i.e. crossplane-runtime)
  4. provider-azure packages (i.e. from within this repo)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First running:
goimports -local github.com/crossplane/provider-azure -w pkg/controller/network/securitygroup/managed_test.go pkg/controller/network/securitygroup/managed_test.go,
and then running:
goimports -local github.com/crossplane/crossplane-runtime -w pkg/controller/network/securitygroup/managed_test.go pkg/controller/network/securitygroup/managed_test.go,
should put them into shape.

SchemeBuilder.Register(&VirtualNetwork{}, &VirtualNetworkList{})
SchemeBuilder.Register(&Subnet{}, &SubnetList{})
SchemeBuilder.Register(&SecurityGroup{}, &SecurityGroupList{})
//SchemeBuilder.Register(&SecurityRule{})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed? Is it possible to create a SecurityRule independent of a SecurityGroup? If so, it should be a separate resource type.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants