-
Notifications
You must be signed in to change notification settings - Fork 473
/
peer_authentication_checker.go
67 lines (53 loc) · 2.71 KB
/
peer_authentication_checker.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
package checkers
import (
security_v1beta "istio.io/client-go/pkg/apis/security/v1beta1"
"github.com/kiali/kiali/business/checkers/common"
"github.com/kiali/kiali/business/checkers/peerauthentications"
"github.com/kiali/kiali/config"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/models"
)
const PeerAuthenticationCheckerType = "peerauthentication"
type PeerAuthenticationChecker struct {
PeerAuthentications []*security_v1beta.PeerAuthentication
MTLSDetails kubernetes.MTLSDetails
WorkloadsPerNamespace map[string]models.WorkloadList
}
func (m PeerAuthenticationChecker) Check() models.IstioValidations {
validations := models.IstioValidations{}
validations.MergeValidations(common.PeerAuthenticationMultiMatchChecker(PeerAuthenticationCheckerType, m.PeerAuthentications, m.WorkloadsPerNamespace).Check())
for _, peerAuthn := range m.PeerAuthentications {
validations.MergeValidations(m.runChecks(peerAuthn))
}
return validations
}
// runChecks runs all the individual checks for a single mesh policy and appends the result into validations.
func (m PeerAuthenticationChecker) runChecks(peerAuthn *security_v1beta.PeerAuthentication) models.IstioValidations {
peerAuthnName := peerAuthn.Name
key, rrValidation := EmptyValidValidation(peerAuthnName, peerAuthn.Namespace, PeerAuthenticationCheckerType)
var enabledCheckers []Checker
matchLabels := make(map[string]string)
if peerAuthn.Spec.Selector != nil {
matchLabels = peerAuthn.Spec.Selector.MatchLabels
}
enabledCheckers = append(enabledCheckers, common.SelectorNoWorkloadFoundChecker(PeerAuthenticationCheckerType, matchLabels, m.WorkloadsPerNamespace))
if config.IsRootNamespace(peerAuthn.Namespace) {
enabledCheckers = append(enabledCheckers, peerauthentications.DisabledMeshWideChecker{PeerAuthn: peerAuthn, DestinationRules: m.MTLSDetails.DestinationRules})
} else {
enabledCheckers = append(enabledCheckers, peerauthentications.DisabledNamespaceWideChecker{PeerAuthn: peerAuthn, DestinationRules: m.MTLSDetails.DestinationRules})
}
// PeerAuthentications into the root namespace namespace are considered Mesh-wide objects
if config.IsRootNamespace(peerAuthn.Namespace) {
enabledCheckers = append(enabledCheckers,
peerauthentications.MeshMtlsChecker{MeshPolicy: peerAuthn, MTLSDetails: m.MTLSDetails, IsServiceMesh: false})
} else {
enabledCheckers = append(enabledCheckers,
peerauthentications.NamespaceMtlsChecker{PeerAuthn: peerAuthn, MTLSDetails: m.MTLSDetails})
}
for _, checker := range enabledCheckers {
checks, validChecker := checker.Check()
rrValidation.Checks = append(rrValidation.Checks, checks...)
rrValidation.Valid = rrValidation.Valid && validChecker
}
return models.IstioValidations{key: rrValidation}
}