/
azure.go
113 lines (103 loc) · 4.64 KB
/
azure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
np "github.com/gardener/gardener/extensions/test/e2e/framework/networkpolicies"
)
// azureNetworkPolicy holds Azure-specific network policy settings.
type azureNetworkPolicy struct {
np.Agnostic
// metadata points to Azure-specific Metadata service.
metadata *np.Host
}
// NewCloudAware returns Azure-specific policies.
func NewCloudAware() np.CloudAware {
return &azureNetworkPolicy{
metadata: &np.Host{
Description: "Metadata service",
HostName: "169.254.169.254",
Port: 80,
},
}
}
// Sources returns list of all Azure-specific sources and targets.
func (a *azureNetworkPolicy) Rules() []np.Rule {
ag := a.Agnostic
return []np.Rule{
a.newSource(ag.KubeAPIServer()).AllowPod(ag.EtcdMain(), ag.EtcdEvents()).AllowHost(ag.SeedKubeAPIServer(), ag.External()).Build(),
a.newSource(ag.EtcdMain()).AllowHost(ag.External()).Build(),
a.newSource(ag.EtcdEvents()).AllowHost(ag.External()).Build(),
a.newSource(ag.CloudControllerManagerNotSecured()).AllowPod(ag.KubeAPIServer()).AllowHost(ag.External()).Build(),
a.newSource(ag.CloudControllerManagerSecured()).AllowPod(ag.KubeAPIServer()).AllowHost(ag.External()).Build(),
a.newSource(ag.ElasticSearch()).Build(),
a.newSource(ag.Grafana()).AllowPod(ag.Prometheus()).Build(),
a.newSource(ag.Kibana()).AllowTargetPod(ag.ElasticSearch().FromPort("http")).Build(),
a.newSource(ag.AddonManager()).AllowPod(ag.KubeAPIServer()).AllowHost(ag.SeedKubeAPIServer(), ag.External()).Build(),
a.newSource(ag.KubeControllerManagerNotSecured()).AllowPod(ag.KubeAPIServer()).AllowHost(a.metadata, ag.External()).Build(),
a.newSource(ag.KubeControllerManagerSecured()).AllowPod(ag.KubeAPIServer()).AllowHost(a.metadata, ag.External()).Build(),
a.newSource(ag.KubeSchedulerNotSecured()).AllowPod(ag.KubeAPIServer()).Build(),
a.newSource(ag.KubeSchedulerSecured()).AllowPod(ag.KubeAPIServer()).Build(),
a.newSource(ag.KubeStateMetricsShoot()).AllowPod(ag.KubeAPIServer()).Build(),
a.newSource(ag.KubeStateMetricsSeed()).AllowHost(ag.SeedKubeAPIServer(), ag.External()).Build(),
a.newSource(ag.MachineControllerManager()).AllowPod(ag.KubeAPIServer()).AllowHost(ag.SeedKubeAPIServer(), ag.External()).Build(),
a.newSource(ag.Prometheus()).AllowPod(
ag.CloudControllerManagerNotSecured(),
ag.CloudControllerManagerSecured(),
ag.EtcdEvents(),
ag.EtcdMain(),
ag.KubeAPIServer(),
ag.KubeControllerManagerNotSecured(),
ag.KubeControllerManagerSecured(),
ag.KubeSchedulerNotSecured(),
ag.KubeSchedulerSecured(),
ag.KubeStateMetricsSeed(),
ag.KubeStateMetricsShoot(),
ag.MachineControllerManager(),
).AllowTargetPod(ag.ElasticSearch().FromPort("metrics")).AllowHost(ag.SeedKubeAPIServer(), ag.External(), ag.GardenPrometheus()).Build(),
}
}
// EgressFromOtherNamespaces returns list of all azure-specific sources and targets.
func (a *azureNetworkPolicy) EgressFromOtherNamespaces(sourcePod *np.SourcePod) np.Rule {
return np.NewSource(sourcePod).DenyPod(a.Sources()...).AllowPod(a.Agnostic.KubeAPIServer()).Build()
}
func (a *azureNetworkPolicy) newSource(sourcePod *np.SourcePod) *np.RuleBuilder {
return np.NewSource(sourcePod).DenyPod(a.Sources()...).DenyHost(a.metadata, a.Agnostic.External(), a.Agnostic.GardenPrometheus())
}
// Sources returns a list of SourcePods of Azure.
func (a *azureNetworkPolicy) Sources() []*np.SourcePod {
ag := a.Agnostic
return []*np.SourcePod{
ag.AddonManager(),
ag.CloudControllerManagerNotSecured(),
ag.CloudControllerManagerSecured(),
ag.ElasticSearch(),
ag.EtcdEvents(),
ag.EtcdMain(),
ag.Grafana(),
ag.Kibana(),
ag.KubeAPIServer(),
ag.KubeControllerManagerNotSecured(),
ag.KubeControllerManagerSecured(),
ag.KubeSchedulerNotSecured(),
ag.KubeSchedulerSecured(),
ag.KubeStateMetricsSeed(),
ag.KubeStateMetricsShoot(),
ag.MachineControllerManager(),
ag.Prometheus(),
}
}
// Provider returns Azure cloud provider.
func (a *azureNetworkPolicy) Provider() string {
return "azure"
}