Skip to content

adds imp for azure using filtertype security group#17

Open
fahad-rauf wants to merge 8 commits intomasterfrom
sec-group-azure
Open

adds imp for azure using filtertype security group#17
fahad-rauf wants to merge 8 commits intomasterfrom
sec-group-azure

Conversation

@fahad-rauf
Copy link
Copy Markdown
Contributor

No description provided.

@fahad-rauf fahad-rauf requested a review from hamza3202 August 21, 2020 15:55
@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-1

@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-2

@rasheedamir
Copy link
Copy Markdown
Member

@fahad-rauf plz add tests

@rasheedamir
Copy link
Copy Markdown
Member

also add in the readme

Copy link
Copy Markdown

@hamza3202 hamza3202 left a comment

Choose a reason for hiding this comment

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

Needs some refactoring


// Azure provider class implementing the Provider interface
type Azure struct {
ClientSet clientset.Interface
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe keep clients in this structure instead of credentials? e.g securityRulesClient, securityGroupClient etc. Then we don't need to create new clients on each reconcile loop.

// WhiteListIps - Get List of IP addresses to whitelist
func (a *Azure) WhiteListIps(filter config.Filter, ipPermissions []utils.IpPermission) error {

resourceGroups, err := fetchResourceGroups(a, filter)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't we fetch the resource group based on resourceGroupName that the user provides?

}
for _, resourceGroup := range resourceGroups.Values() {
resourceName := *resourceGroup.Name
logrus.Infof("Name of the resource %s", *resourceGroup.Name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this statement would get logged every few seconds and I don't see much use for it. Better to log resource group name when something actually happens, like rule added or removed or some other error.

logrus.Error("Error fetching resource groups for given filter")
return err
}
for _, resourceGroup := range resourceGroups.Values() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need for this loop.

return &nsgClient, nil
}

func createSecurityRule(a *Azure, rulesClient network.SecurityRulesClient, resourceName string, ipDescription *string, fromPortStr string, toPortStr string, ipRange *string, ipProtocol string) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be better to move to create separate files for wrapper methods of clients e.g securityRuleClient and securityGroupClient.


var networkProtocol network.SecurityRuleProtocol

switch ipProtocol {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps move this to a new method like validateSecurityRuleProtocol to keep this method small.

return err
}
for _, resourceGroup := range resourceGroups.Values() {
resourceName := *resourceGroup.Name
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think its alright to access the property of an object instead of putting it in a variable.

return nil
}

func isSecurityRuleToBeRetained(existingRuleName string, ipPermissions []utils.IpPermission, keepRuleDescriptionPrefix string, removeRule bool) bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method should be replaced with two methods.

  • One that verifies if this rule should be deleted based on the rules that user has provided i.e git repo.
  • Second that verifies that the rule doesn't have the description to prevent it from being deleted.

Also these two methods should be wrapped in a third method which prevents these methods from being executed if removeRule is false.

@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-3

@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-4

@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-5

@fahad-rauf
Copy link
Copy Markdown
Contributor Author

@hamza3202 kindly review it when you have time

Copy link
Copy Markdown

@hamza3202 hamza3202 left a comment

Choose a reason for hiding this comment

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

Looks almost done. @kahootali please deploy and verify with a working kubernetes cluster to make sure it works as expected.
Please verify that it doesn't delete and add the same rule again and again in each reconciliation cycle.

params:
KeepRuleDescriptionPrefix: "DO NOT REMOVE -"
RemoveRule: true
SubscriptionID: "47c9180a-967d-4ba0-bfc0-7b12762f0779"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These are not real values right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes these are dummy

securityGroupClient network.SecurityGroupsClient
securityRulesClient network.SecurityRulesClient
SubscriptionID string
ClientID string
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 should not keep fields that will not be used in future in this structure, e.g ClientID, ClientSecret, TenantID and subscriptionID.


func (a *Azure) updateSecurityRules(securityGroup network.SecurityGroup, ipPermissions []utils.IpPermission) error {
if a.RemoveRule {
err := deleteRedundantSecurityRules(a, securityGroup, ipPermissions)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Method name can be improved IMO. The rules are not redundant but perhaps expired or old or extra or invalid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

redundant means : not or no longer needed or useful; superfluous.


func getSecurityGroupsClient(a *Azure) (*network.SecurityGroupsClient, error) {

authorizer, err := auth.NewClientCredentialsConfig(a.ClientID, a.ClientSecret, a.TenantID).Authorizer()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

authorizer should be created once and passed to all client creators.

@stakater-user
Copy link
Copy Markdown
Contributor

@fahad-rauf Image is available for testing. docker pull stakater/whitelister:SNAPSHOT-PR-17-6

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants