-
-
Notifications
You must be signed in to change notification settings - Fork 5
adds imp for azure using filtertype security group #17
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
base: master
Are you sure you want to change the base?
Changes from all commits
17e0902
97287b6
1f85924
6aa9ba5
8620cfb
916d1fe
10f68b9
fcdf1b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| Whitelister | ||
| Whitelister | ||
| .vscode | ||
| .idea |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| syncInterval: 10s | ||
| filter: | ||
| filterType: InCorrectType | ||
| labelName: whitelister | ||
| labelValue: true | ||
| ipProviders: | ||
| - name: kubernetes | ||
| params: | ||
| FromPort: 0 | ||
| ToPort: 65535 | ||
| IpProtocol: tcp | ||
| provider: | ||
| name: azure | ||
| params: | ||
| KeepRuleDescriptionPrefix: "DO NOT REMOVE -" | ||
| RemoveRule: true | ||
| SubscriptionID: "47c9180a-967d-4ba0-bfc0-7b12762f0779" | ||
| ClientID: "4ab0b7f2-197f-4b14-bf22-1856a6f095aa" | ||
| ClientSecret: "thisisthesecret" | ||
| TenantID: "73cf1f9c-03d0-4709-8434-b50bc8440454" | ||
| ResourceGroupName: "my-resource-group" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| syncInterval: 10s | ||
| filter: | ||
| filterType: SecurityGroup | ||
| labelName: whitelister | ||
| labelValue: true | ||
| ipProviders: | ||
| - name: git | ||
| params: | ||
| AccessToken: "access-token" | ||
| URL: "http://github.com/stakater/whitelister-config.git" | ||
| Config: "config.yaml" | ||
| provider: | ||
| name: azure | ||
| params: | ||
| KeepRuleDescriptionPrefix: "DO NOT REMOVE -" | ||
| RemoveRule: true | ||
| SubscriptionID: "47c9180a-967d-4ba0-bfc0-7b12762f0779" | ||
| ClientID: "4ab0b7f2-197f-4b14-bf22-1856a6f095aa" | ||
| ClientSecret: "thisisthesecret" | ||
| TenantID: "73cf1f9c-03d0-4709-8434-b50bc8440454" | ||
| ResourceGroupName: "my-resource-group" | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Azure | ||
|
|
||
| Azure can be used as a cloud provider where your servers reside. The current provider can add a list of IP rules to the security group and optionally remove previously added security rules. If you wish to keep some of the hard coded rules then you can add a certain prefix to their description and Whitelister will not remove them. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Azure provider supports the following configuration | ||
|
|
||
| |Key |Status |Description| | ||
| |----------|--------|-----------| | ||
| |SubscriptionID |required|The subscription ID is a unique uuid string that identifies the Azure subscription| | ||
| |ClientID |required|ID required to connect to Azure| | ||
| |ClientSecret |required|Secret used for establishing connection with Azure| | ||
| |TenantID |required|Unique identifier of the Azure active directory instance| | ||
| |RemoveRule|required|Whether to remove un-recognized rules or not. Accepts `true` or `false`| | ||
| |KeepRuleDescriptionPrefix|optional|A string value, which when found as a prefix in the description of a security rule then the security rule is not removed| |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package azure | ||
|
|
||
| import ( | ||
| "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/network/mgmt/network" | ||
| "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources" | ||
| "github.com/Azure/go-autorest/autorest" | ||
|
|
||
| "github.com/mitchellh/mapstructure" | ||
| "github.com/sirupsen/logrus" | ||
| "github.com/stakater/Whitelister/internal/pkg/config" | ||
| clientset "k8s.io/client-go/kubernetes" | ||
|
|
||
| "github.com/stakater/Whitelister/internal/pkg/utils" | ||
| ) | ||
|
|
||
| // Azure provider class implementing the Provider interface | ||
| type Azure struct { | ||
| ClientSet clientset.Interface | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe keep clients in this structure instead of credentials? e.g |
||
| resourcesClient resources.Client | ||
| securityGroupClient network.SecurityGroupsClient | ||
| securityRulesClient network.SecurityRulesClient | ||
| authorizer autorest.Authorizer | ||
| SubscriptionID string | ||
| ClientID string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ClientSecret string | ||
| TenantID string | ||
| ResourceGroupName string | ||
| RemoveRule bool | ||
| KeepRuleDescriptionPrefix string | ||
| } | ||
|
|
||
| // GetName Returns name of provider | ||
| func (a *Azure) GetName() string { | ||
| return "Azure" | ||
| } | ||
|
|
||
| // Init initializes the Azure Provider Configuration like client id and client secret | ||
| func (a *Azure) Init(params map[interface{}]interface{}, clientSet clientset.Interface) error { | ||
| err := mapstructure.Decode(params, &a) //Converts the params to Azure struct fields | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = a.initializeAzureClients() // initializes azure clients for whitelisting ips | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // WhiteListIps - Get List of IP addresses to whitelist | ||
| func (a *Azure) WhiteListIps(filter config.Filter, ipPermissions []utils.IpPermission) error { | ||
|
|
||
| resources, err := a.fetchResources(filter) | ||
| if err != nil { | ||
| logrus.Error("Error fetching resources for the given filter") | ||
| return err | ||
| } | ||
|
|
||
| for _, resource := range resources { | ||
| logrus.Infof("Name of the security group %s", *resource.Name) | ||
| securityGroup, err := a.fetchSecurityGroup(*resource.Name) | ||
| if err != nil { | ||
| logrus.Errorf("Error fetching security group for resource %s", *resource.Name) | ||
| return err | ||
| } | ||
| err = a.updateSecurityRules(*securityGroup, ipPermissions) | ||
| if err != nil { | ||
| logrus.Errorf("Error whitelisting ips for security group %s", *resource.Name) | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes these are dummy