@@ -423,16 +423,16 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
423
423
}
424
424
policiesCfg := vsc .generatePolicies (ownerDetails , vsEx .VirtualServer .Spec .Policies , vsEx .Policies , specContext , policyOpts )
425
425
426
- if policiesCfg .JWKSAuthEnabled {
427
- jwtAuthKey := policiesCfg .JWTAuth .Key
428
- policiesCfg .JWTAuthList = make (map [string ]* version2.JWTAuth )
429
- policiesCfg .JWTAuthList [jwtAuthKey ] = policiesCfg .JWTAuth
426
+ if policiesCfg .JWTAuth . JWKSEnabled {
427
+ jwtAuthKey := policiesCfg .JWTAuth .Auth . Key
428
+ policiesCfg .JWTAuth . List = make (map [string ]* version2.JWTAuth )
429
+ policiesCfg .JWTAuth . List [jwtAuthKey ] = policiesCfg .JWTAuth . Auth
430
430
}
431
431
432
- if policiesCfg .APIKeyEnabled {
433
- apiMapName := policiesCfg .APIKey .MapName
434
- policiesCfg .APIKeyClientMap = make (map [string ][]apiKeyClient )
435
- policiesCfg .APIKeyClientMap [apiMapName ] = policiesCfg .APIKeyClients
432
+ if policiesCfg .APIKey . Enabled {
433
+ apiMapName := policiesCfg .APIKey .Key . MapName
434
+ policiesCfg .APIKey . ClientMap = make (map [string ][]apiKeyClient )
435
+ policiesCfg .APIKey . ClientMap [apiMapName ] = policiesCfg .APIKey . Clients
436
436
}
437
437
438
438
dosCfg := generateDosCfg (dosResources ["" ])
@@ -454,7 +454,7 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
454
454
var healthChecks []version2.HealthCheck
455
455
var limitReqZones []version2.LimitReqZone
456
456
457
- limitReqZones = append (limitReqZones , policiesCfg .LimitReqZones ... )
457
+ limitReqZones = append (limitReqZones , policiesCfg .RateLimit . Zones ... )
458
458
459
459
// generate upstreams for VirtualServer
460
460
for _ , u := range vsEx .VirtualServer .Spec .Upstreams {
@@ -582,29 +582,29 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
582
582
if policiesCfg .OIDC {
583
583
routePoliciesCfg .OIDC = policiesCfg .OIDC
584
584
}
585
- if routePoliciesCfg .JWKSAuthEnabled {
586
- policiesCfg .JWKSAuthEnabled = routePoliciesCfg .JWKSAuthEnabled
585
+ if routePoliciesCfg .JWTAuth . JWKSEnabled {
586
+ policiesCfg .JWTAuth . JWKSEnabled = routePoliciesCfg .JWTAuth . JWKSEnabled
587
587
588
- if policiesCfg .JWTAuthList == nil {
589
- policiesCfg .JWTAuthList = make (map [string ]* version2.JWTAuth )
588
+ if policiesCfg .JWTAuth . List == nil {
589
+ policiesCfg .JWTAuth . List = make (map [string ]* version2.JWTAuth )
590
590
}
591
591
592
- jwtAuthKey := routePoliciesCfg .JWTAuth .Key
593
- if _ , exists := policiesCfg .JWTAuthList [jwtAuthKey ]; ! exists {
594
- policiesCfg .JWTAuthList [jwtAuthKey ] = routePoliciesCfg .JWTAuth
592
+ jwtAuthKey := routePoliciesCfg .JWTAuth .Auth . Key
593
+ if _ , exists := policiesCfg .JWTAuth . List [jwtAuthKey ]; ! exists {
594
+ policiesCfg .JWTAuth . List [jwtAuthKey ] = routePoliciesCfg .JWTAuth . Auth
595
595
}
596
596
}
597
- if routePoliciesCfg .APIKeyEnabled {
598
- policiesCfg .APIKeyEnabled = routePoliciesCfg .APIKeyEnabled
599
- apiMapName := routePoliciesCfg .APIKey .MapName
600
- if policiesCfg .APIKeyClientMap == nil {
601
- policiesCfg .APIKeyClientMap = make (map [string ][]apiKeyClient )
597
+ if routePoliciesCfg .APIKey . Enabled {
598
+ policiesCfg .APIKey . Enabled = routePoliciesCfg .APIKey . Enabled
599
+ apiMapName := routePoliciesCfg .APIKey .Key . MapName
600
+ if policiesCfg .APIKey . ClientMap == nil {
601
+ policiesCfg .APIKey . ClientMap = make (map [string ][]apiKeyClient )
602
602
}
603
- if _ , exists := policiesCfg .APIKeyClientMap [apiMapName ]; ! exists {
604
- policiesCfg .APIKeyClientMap [apiMapName ] = routePoliciesCfg .APIKeyClients
603
+ if _ , exists := policiesCfg .APIKey . ClientMap [apiMapName ]; ! exists {
604
+ policiesCfg .APIKey . ClientMap [apiMapName ] = routePoliciesCfg .APIKey . Clients
605
605
}
606
606
}
607
- limitReqZones = append (limitReqZones , routePoliciesCfg .LimitReqZones ... )
607
+ limitReqZones = append (limitReqZones , routePoliciesCfg .RateLimit . Zones ... )
608
608
609
609
dosRouteCfg := generateDosCfg (dosResources [r .Path ])
610
610
@@ -722,30 +722,30 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
722
722
if policiesCfg .OIDC {
723
723
routePoliciesCfg .OIDC = policiesCfg .OIDC
724
724
}
725
- if routePoliciesCfg .JWKSAuthEnabled {
726
- policiesCfg .JWKSAuthEnabled = routePoliciesCfg .JWKSAuthEnabled
725
+ if routePoliciesCfg .JWTAuth . JWKSEnabled {
726
+ policiesCfg .JWTAuth . JWKSEnabled = routePoliciesCfg .JWTAuth . JWKSEnabled
727
727
728
- if policiesCfg .JWTAuthList == nil {
729
- policiesCfg .JWTAuthList = make (map [string ]* version2.JWTAuth )
728
+ if policiesCfg .JWTAuth . List == nil {
729
+ policiesCfg .JWTAuth . List = make (map [string ]* version2.JWTAuth )
730
730
}
731
731
732
- jwtAuthKey := routePoliciesCfg .JWTAuth .Key
733
- if _ , exists := policiesCfg .JWTAuthList [jwtAuthKey ]; ! exists {
734
- policiesCfg .JWTAuthList [jwtAuthKey ] = routePoliciesCfg .JWTAuth
732
+ jwtAuthKey := routePoliciesCfg .JWTAuth .Auth . Key
733
+ if _ , exists := policiesCfg .JWTAuth . List [jwtAuthKey ]; ! exists {
734
+ policiesCfg .JWTAuth . List [jwtAuthKey ] = routePoliciesCfg .JWTAuth . Auth
735
735
}
736
736
}
737
- if routePoliciesCfg .APIKeyEnabled {
738
- policiesCfg .APIKeyEnabled = routePoliciesCfg .APIKeyEnabled
739
- apiMapName := routePoliciesCfg .APIKey .MapName
740
- if policiesCfg .APIKeyClientMap == nil {
741
- policiesCfg .APIKeyClientMap = make (map [string ][]apiKeyClient )
737
+ if routePoliciesCfg .APIKey . Enabled {
738
+ policiesCfg .APIKey . Enabled = routePoliciesCfg .APIKey . Enabled
739
+ apiMapName := routePoliciesCfg .APIKey .Key . MapName
740
+ if policiesCfg .APIKey . ClientMap == nil {
741
+ policiesCfg .APIKey . ClientMap = make (map [string ][]apiKeyClient )
742
742
}
743
- if _ , exists := policiesCfg .APIKeyClientMap [apiMapName ]; ! exists {
744
- policiesCfg .APIKeyClientMap [apiMapName ] = routePoliciesCfg .APIKeyClients
743
+ if _ , exists := policiesCfg .APIKey . ClientMap [apiMapName ]; ! exists {
744
+ policiesCfg .APIKey . ClientMap [apiMapName ] = routePoliciesCfg .APIKey . Clients
745
745
}
746
746
}
747
747
748
- limitReqZones = append (limitReqZones , routePoliciesCfg .LimitReqZones ... )
748
+ limitReqZones = append (limitReqZones , routePoliciesCfg .RateLimit . Zones ... )
749
749
750
750
dosRouteCfg := generateDosCfg (dosResources [r .Path ])
751
751
@@ -812,7 +812,7 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
812
812
}
813
813
}
814
814
815
- for mapName , apiKeyClients := range policiesCfg .APIKeyClientMap {
815
+ for mapName , apiKeyClients := range policiesCfg .APIKey . ClientMap {
816
816
maps = append (maps , * generateAPIKeyClientMap (mapName , apiKeyClients ))
817
817
}
818
818
@@ -861,16 +861,16 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
861
861
TLSPassthrough : vsc .isTLSPassthrough ,
862
862
Allow : policiesCfg .Allow ,
863
863
Deny : policiesCfg .Deny ,
864
- LimitReqOptions : policiesCfg .LimitReqOptions ,
865
- LimitReqs : policiesCfg .LimitReqs ,
866
- JWTAuth : policiesCfg .JWTAuth ,
864
+ LimitReqOptions : policiesCfg .RateLimit . Options ,
865
+ LimitReqs : policiesCfg .RateLimit . Reqs ,
866
+ JWTAuth : policiesCfg .JWTAuth . Auth ,
867
867
BasicAuth : policiesCfg .BasicAuth ,
868
- JWTAuthList : policiesCfg .JWTAuthList ,
869
- JWKSAuthEnabled : policiesCfg .JWKSAuthEnabled ,
868
+ JWTAuthList : policiesCfg .JWTAuth . List ,
869
+ JWKSAuthEnabled : policiesCfg .JWTAuth . JWKSEnabled ,
870
870
IngressMTLS : policiesCfg .IngressMTLS ,
871
871
EgressMTLS : policiesCfg .EgressMTLS ,
872
- APIKey : policiesCfg .APIKey ,
873
- APIKeyEnabled : policiesCfg .APIKeyEnabled ,
872
+ APIKey : policiesCfg .APIKey . Key ,
873
+ APIKeyEnabled : policiesCfg .APIKey . Enabled ,
874
874
OIDC : vsc .oidcPolCfg .oidc ,
875
875
WAF : policiesCfg .WAF ,
876
876
Dos : dosCfg ,
@@ -891,23 +891,38 @@ func (vsc *virtualServerConfigurator) GenerateVirtualServerConfig(
891
891
return vsCfg , vsc .warnings
892
892
}
893
893
894
+ // rateLimit hold the configuration for the ratelimiting Policy
895
+ type rateLimit struct {
896
+ Reqs []version2.LimitReq
897
+ Zones []version2.LimitReqZone
898
+ Options version2.LimitReqOptions
899
+ }
900
+
901
+ // jwtAuth hold the configuration for the JWTAuth & JWKSAuth Policies
902
+ type jwtAuth struct {
903
+ Auth * version2.JWTAuth
904
+ List map [string ]* version2.JWTAuth
905
+ JWKSEnabled bool
906
+ }
907
+
908
+ // apiKeyAuth hold the configuration for the APIKey Policy
909
+ type apiKeyAuth struct {
910
+ Enabled bool
911
+ Key * version2.APIKey
912
+ Clients []apiKeyClient
913
+ ClientMap map [string ][]apiKeyClient
914
+ }
915
+
894
916
type policiesCfg struct {
895
917
Allow []string
896
918
Deny []string
897
- LimitReqOptions version2.LimitReqOptions
898
- LimitReqZones []version2.LimitReqZone
899
- LimitReqs []version2.LimitReq
900
- JWTAuth * version2.JWTAuth
901
- JWTAuthList map [string ]* version2.JWTAuth
902
- JWKSAuthEnabled bool
919
+ RateLimit rateLimit
920
+ JWTAuth jwtAuth
903
921
BasicAuth * version2.BasicAuth
904
922
IngressMTLS * version2.IngressMTLS
905
923
EgressMTLS * version2.EgressMTLS
906
924
OIDC bool
907
- APIKeyEnabled bool
908
- APIKey * version2.APIKey
909
- APIKeyClients []apiKeyClient
910
- APIKeyClientMap map [string ][]apiKeyClient
925
+ APIKey apiKeyAuth
911
926
WAF * version2.WAF
912
927
ErrorReturn * version2.Return
913
928
BundleValidator bundleValidator
@@ -994,20 +1009,20 @@ func (p *policiesCfg) addRateLimitConfig(
994
1009
) * validationResults {
995
1010
res := newValidationResults ()
996
1011
rlZoneName := fmt .Sprintf ("pol_rl_%v_%v_%v_%v" , polNamespace , polName , vsNamespace , vsName )
997
- p .LimitReqs = append (p .LimitReqs , generateLimitReq (rlZoneName , rateLimit ))
998
- p .LimitReqZones = append (p .LimitReqZones , generateLimitReqZone (rlZoneName , rateLimit , podReplicas ))
999
- if len (p .LimitReqs ) == 1 {
1000
- p .LimitReqOptions = generateLimitReqOptions (rateLimit )
1012
+ p .RateLimit . Reqs = append (p .RateLimit . Reqs , generateLimitReq (rlZoneName , rateLimit ))
1013
+ p .RateLimit . Zones = append (p .RateLimit . Zones , generateLimitReqZone (rlZoneName , rateLimit , podReplicas ))
1014
+ if len (p .RateLimit . Reqs ) == 1 {
1015
+ p .RateLimit . Options = generateLimitReqOptions (rateLimit )
1001
1016
} else {
1002
1017
curOptions := generateLimitReqOptions (rateLimit )
1003
- if curOptions .DryRun != p .LimitReqOptions .DryRun {
1004
- res .addWarningf ("RateLimit policy %s with limit request option dryRun='%v' is overridden to dryRun='%v' by the first policy reference in this context" , polKey , curOptions .DryRun , p .LimitReqOptions .DryRun )
1018
+ if curOptions .DryRun != p .RateLimit . Options .DryRun {
1019
+ res .addWarningf ("RateLimit policy %s with limit request option dryRun='%v' is overridden to dryRun='%v' by the first policy reference in this context" , polKey , curOptions .DryRun , p .RateLimit . Options .DryRun )
1005
1020
}
1006
- if curOptions .LogLevel != p .LimitReqOptions .LogLevel {
1007
- res .addWarningf ("RateLimit policy %s with limit request option logLevel='%v' is overridden to logLevel='%v' by the first policy reference in this context" , polKey , curOptions .LogLevel , p .LimitReqOptions .LogLevel )
1021
+ if curOptions .LogLevel != p .RateLimit . Options .LogLevel {
1022
+ res .addWarningf ("RateLimit policy %s with limit request option logLevel='%v' is overridden to logLevel='%v' by the first policy reference in this context" , polKey , curOptions .LogLevel , p .RateLimit . Options .LogLevel )
1008
1023
}
1009
- if curOptions .RejectCode != p .LimitReqOptions .RejectCode {
1010
- res .addWarningf ("RateLimit policy %s with limit request option rejectCode='%v' is overridden to rejectCode='%v' by the first policy reference in this context" , polKey , curOptions .RejectCode , p .LimitReqOptions .RejectCode )
1024
+ if curOptions .RejectCode != p .RateLimit . Options .RejectCode {
1025
+ res .addWarningf ("RateLimit policy %s with limit request option rejectCode='%v' is overridden to rejectCode='%v' by the first policy reference in this context" , polKey , curOptions .RejectCode , p .RateLimit . Options .RejectCode )
1011
1026
}
1012
1027
}
1013
1028
return res
@@ -1055,7 +1070,7 @@ func (p *policiesCfg) addJWTAuthConfig(
1055
1070
secretRefs map [string ]* secrets.SecretReference ,
1056
1071
) * validationResults {
1057
1072
res := newValidationResults ()
1058
- if p .JWTAuth != nil {
1073
+ if p .JWTAuth . Auth != nil {
1059
1074
res .addWarningf ("Multiple jwt policies in the same context is not valid. JWT policy %s will be ignored" , polKey )
1060
1075
return res
1061
1076
}
@@ -1076,7 +1091,7 @@ func (p *policiesCfg) addJWTAuthConfig(
1076
1091
return res
1077
1092
}
1078
1093
1079
- p .JWTAuth = & version2.JWTAuth {
1094
+ p .JWTAuth . Auth = & version2.JWTAuth {
1080
1095
Secret : secretRef .Path ,
1081
1096
Realm : jwtAuth .Realm ,
1082
1097
Token : jwtAuth .Token ,
@@ -1092,14 +1107,14 @@ func (p *policiesCfg) addJWTAuthConfig(
1092
1107
JwksPath : uri .Path ,
1093
1108
}
1094
1109
1095
- p .JWTAuth = & version2.JWTAuth {
1110
+ p .JWTAuth . Auth = & version2.JWTAuth {
1096
1111
Key : polKey ,
1097
1112
JwksURI : * JwksURI ,
1098
1113
Realm : jwtAuth .Realm ,
1099
1114
Token : jwtAuth .Token ,
1100
1115
KeyCache : jwtAuth .KeyCache ,
1101
1116
}
1102
- p .JWKSAuthEnabled = true
1117
+ p .JWTAuth . JWKSEnabled = true
1103
1118
return res
1104
1119
}
1105
1120
return res
@@ -1359,7 +1374,7 @@ func (p *policiesCfg) addAPIKeyConfig(
1359
1374
secretRefs map [string ]* secrets.SecretReference ,
1360
1375
) * validationResults {
1361
1376
res := newValidationResults ()
1362
- if p .APIKey != nil {
1377
+ if p .APIKey . Key != nil {
1363
1378
res .addWarningf (
1364
1379
"Multiple API Key policies in the same context is not valid. API Key policy %s will be ignored" ,
1365
1380
polKey ,
@@ -1384,20 +1399,20 @@ func (p *policiesCfg) addAPIKeyConfig(
1384
1399
return res
1385
1400
}
1386
1401
1387
- p .APIKeyClients = generateAPIKeyClients (secretRef .Secret .Data )
1402
+ p .APIKey . Clients = generateAPIKeyClients (secretRef .Secret .Data )
1388
1403
1389
1404
mapName := fmt .Sprintf (
1390
1405
"apikey_auth_client_name_%s_%s_%s" ,
1391
1406
rfc1123ToSnake (vsNamespace ),
1392
1407
rfc1123ToSnake (vsName ),
1393
1408
strings .Split (rfc1123ToSnake (polKey ), "/" )[1 ],
1394
1409
)
1395
- p .APIKey = & version2.APIKey {
1410
+ p .APIKey . Key = & version2.APIKey {
1396
1411
Header : apiKey .SuppliedIn .Header ,
1397
1412
Query : apiKey .SuppliedIn .Query ,
1398
1413
MapName : mapName ,
1399
1414
}
1400
- p .APIKeyEnabled = true
1415
+ p .APIKey . Enabled = true
1401
1416
return res
1402
1417
}
1403
1418
@@ -1655,14 +1670,14 @@ func removeDuplicateLimitReqZones(rlz []version2.LimitReqZone) []version2.LimitR
1655
1670
func addPoliciesCfgToLocation (cfg policiesCfg , location * version2.Location ) {
1656
1671
location .Allow = cfg .Allow
1657
1672
location .Deny = cfg .Deny
1658
- location .LimitReqOptions = cfg .LimitReqOptions
1659
- location .LimitReqs = cfg .LimitReqs
1660
- location .JWTAuth = cfg .JWTAuth
1673
+ location .LimitReqOptions = cfg .RateLimit . Options
1674
+ location .LimitReqs = cfg .RateLimit . Reqs
1675
+ location .JWTAuth = cfg .JWTAuth . Auth
1661
1676
location .BasicAuth = cfg .BasicAuth
1662
1677
location .EgressMTLS = cfg .EgressMTLS
1663
1678
location .OIDC = cfg .OIDC
1664
1679
location .WAF = cfg .WAF
1665
- location .APIKey = cfg .APIKey
1680
+ location .APIKey = cfg .APIKey . Key
1666
1681
location .PoliciesErrorReturn = cfg .ErrorReturn
1667
1682
}
1668
1683
0 commit comments