Skip to content

Commit 408588a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#61467 from feiskyer/azure-service-tags
Automatic merge from submit-queue (batch tested with PRs 61434, 61501, 59609, 61467, 61531). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add support of specifying service tags for Azure cloud provider **What this PR does / why we need it**: This PR adds support of specifying service tags for Azure cloud provider by annotation `service.beta.kubernetes.io/azure-allowed-service-tags`. Refer https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#service-tags for more information about this feature. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes kubernetes#57914 **Special notes for your reviewer**: **Release note**: ```release-note Azure cloud provider now supports specifying allowed service tags by annotation `service.beta.kubernetes.io/azure-allowed-service-tags` ```
2 parents 99fb416 + b7813b1 commit 408588a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

pkg/cloudprovider/providers/azure/azure_loadbalancer.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ const (
6969
// ServiceAnnotationLoadBalancerResourceGroup is the annotation used on the service
7070
// to specify the resource group of load balancer objects that are not in the same resource group as the cluster.
7171
ServiceAnnotationLoadBalancerResourceGroup = "service.beta.kubernetes.io/azure-load-balancer-resource-group"
72+
73+
// ServiceAnnotationAllowedServiceTag is the annotation used on the service
74+
// to specify a list of allowed service tags separated by comma
75+
ServiceAnnotationAllowedServiceTag = "service.beta.kubernetes.io/azure-allowed-service-tags"
76+
)
77+
78+
var (
79+
// supportedServiceTags holds a list of supported service tags on Azure.
80+
// Refer https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#service-tags for more information.
81+
supportedServiceTags = sets.NewString("VirtualNetwork", "VIRTUAL_NETWORK", "AzureLoadBalancer", "AZURE_LOADBALANCER",
82+
"Internet", "INTERNET", "AzureTrafficManager", "Storage", "Sql")
7283
)
7384

7485
// GetLoadBalancer returns whether the specified load balancer exists, and
@@ -838,15 +849,22 @@ func (az *Cloud) reconcileSecurityGroup(clusterName string, service *v1.Service,
838849
if err != nil {
839850
return nil, err
840851
}
852+
serviceTags, err := getServiceTags(service)
853+
if err != nil {
854+
return nil, err
855+
}
841856
var sourceAddressPrefixes []string
842-
if sourceRanges == nil || serviceapi.IsAllowAll(sourceRanges) {
857+
if (sourceRanges == nil || serviceapi.IsAllowAll(sourceRanges)) && len(serviceTags) == 0 {
843858
if !requiresInternalLoadBalancer(service) {
844859
sourceAddressPrefixes = []string{"Internet"}
845860
}
846861
} else {
847862
for _, ip := range sourceRanges {
848863
sourceAddressPrefixes = append(sourceAddressPrefixes, ip.String())
849864
}
865+
for _, serviceTag := range serviceTags {
866+
sourceAddressPrefixes = append(sourceAddressPrefixes, serviceTag)
867+
}
850868
}
851869
expectedSecurityRules := []network.SecurityRule{}
852870

@@ -1319,3 +1337,23 @@ func useSharedSecurityRule(service *v1.Service) bool {
13191337

13201338
return false
13211339
}
1340+
1341+
func getServiceTags(service *v1.Service) ([]string, error) {
1342+
if serviceTags, found := service.Annotations[ServiceAnnotationAllowedServiceTag]; found {
1343+
tags := strings.Split(strings.TrimSpace(serviceTags), ",")
1344+
for _, tag := range tags {
1345+
// Storage and Sql service tags support setting regions with suffix ".Region"
1346+
if strings.HasPrefix(tag, "Storage.") || strings.HasPrefix(tag, "Sql.") {
1347+
continue
1348+
}
1349+
1350+
if !supportedServiceTags.Has(tag) {
1351+
return nil, fmt.Errorf("only %q are allowed in service tags", supportedServiceTags.List())
1352+
}
1353+
}
1354+
1355+
return tags, nil
1356+
}
1357+
1358+
return nil, nil
1359+
}

0 commit comments

Comments
 (0)