/
request_authentication_checker.go
49 lines (38 loc) · 1.79 KB
/
request_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
package checkers
import (
security_v1beta "istio.io/client-go/pkg/apis/security/v1beta1"
"github.com/kiali/kiali/business/checkers/common"
"github.com/kiali/kiali/models"
)
const RequestAuthenticationCheckerType = "requestauthentication"
type RequestAuthenticationChecker struct {
RequestAuthentications []*security_v1beta.RequestAuthentication
WorkloadsPerNamespace map[string]models.WorkloadList
Cluster string
}
func (m RequestAuthenticationChecker) Check() models.IstioValidations {
validations := models.IstioValidations{}
validations.MergeValidations(common.RequestAuthenticationMultiMatchChecker(m.Cluster, RequestAuthenticationCheckerType, m.RequestAuthentications, m.WorkloadsPerNamespace).Check())
for _, peerAuthn := range m.RequestAuthentications {
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 RequestAuthenticationChecker) runChecks(requestAuthn *security_v1beta.RequestAuthentication) models.IstioValidations {
requestAuthnName := requestAuthn.Name
key, rrValidation := EmptyValidValidation(requestAuthnName, requestAuthn.Namespace, RequestAuthenticationCheckerType, m.Cluster)
matchLabels := make(map[string]string)
if requestAuthn.Spec.Selector != nil {
matchLabels = requestAuthn.Spec.Selector.MatchLabels
}
enabledCheckers := []Checker{
common.SelectorNoWorkloadFoundChecker(RequestAuthenticationCheckerType, matchLabels, m.WorkloadsPerNamespace),
}
for _, checker := range enabledCheckers {
checks, validChecker := checker.Check()
rrValidation.Checks = append(rrValidation.Checks, checks...)
rrValidation.Valid = rrValidation.Valid && validChecker
}
return models.IstioValidations{key: rrValidation}
}