Skip to content

Commit

Permalink
rename JWTAuthentication to JWT
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Oct 26, 2023
1 parent 9ebdb43 commit 462e1e8
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 90 deletions.
9 changes: 4 additions & 5 deletions api/v1alpha1/securitypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ type SecurityPolicySpec struct {
// +optional
CORS *CORS `json:"cors,omitempty"`

// JWTAuthentication defines the configuration for JSON Web Token (JWT)
// authentication.
// JWT defines the configuration for JSON Web Token (JWT) authentication.
//
// +optional
JWTAuthentication *JWTAuthentication `json:"jwtAuthentication,omitempty"`
JWT *JWT `json:"jwt,omitempty"`
}

// CORS defines the configuration for Cross-Origin Resource Sharing (CORS).
Expand All @@ -70,8 +69,8 @@ type CORS struct {
MaxAge *metav1.Duration `json:"maxAge,omitempty" yaml:"maxAge,omitempty"`
}

// JWTAuthentication defines the configuration for JSON Web Token (JWT) authentication.
type JWTAuthentication struct {
// JWT defines the configuration for JSON Web Token (JWT) authentication.
type JWT struct {

// Providers defines the JSON Web Token (JWT) authentication provider type.
//
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/validation/securitypolicy_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func validateSecurityPolicySpec(spec *egv1a1.SecurityPolicySpec) error {
errs = append(errs, errors.New("spec is nil"))
case spec.CORS != nil:
sum++
case spec.JWTAuthentication != nil:
case spec.JWT != nil:
sum++
}
if sum == 0 {
Expand All @@ -52,15 +52,15 @@ func validateSecurityPolicySpec(spec *egv1a1.SecurityPolicySpec) error {
return utilerrors.NewAggregate(errs)
}

if err := ValidateJWTAuthentication(spec.JWTAuthentication.Providers); err != nil {
if err := ValidateJWTProvider(spec.JWT.Providers); err != nil {
errs = append(errs, err)
}

return utilerrors.NewAggregate(errs)
}

// ValidateJWTAuthentication validates the provided JWT authentication configuration.
func ValidateJWTAuthentication(providers []egv1a1.JWTProvider) error {
// ValidateJWTProvider validates the provided JWT authentication configuration.
func ValidateJWTProvider(providers []egv1a1.JWTProvider) error {
var errs []error

if len(providers) == 0 {
Expand Down
30 changes: 15 additions & 15 deletions api/v1alpha1/validation/securitypolicy_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{},
},
},
Expand All @@ -71,7 +71,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "unqualified_...",
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "",
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "unique",
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand All @@ -372,7 +372,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand All @@ -467,7 +467,7 @@ func TestValidateSecurityPolicy(t *testing.T) {
Name: "test",
},
Spec: egv1a1.SecurityPolicySpec{
JWTAuthentication: &egv1a1.JWTAuthentication{
JWT: &egv1a1.JWT{
Providers: []egv1a1.JWTProvider{
{
Name: "test",
Expand Down
14 changes: 7 additions & 7 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ spec:
request can be cached.
type: string
type: object
jwtAuthentication:
description: JWTAuthentication defines the configuration for JSON
Web Token (JWT) authentication.
jwt:
description: JWT defines the configuration for JSON Web Token (JWT)
authentication.
properties:
providers:
description: "Providers defines the JSON Web Token (JWT) authentication
Expand Down
28 changes: 14 additions & 14 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,16 @@ func resolveSecurityPolicyRouteTargetRef(policy *egv1a1.SecurityPolicy, routes m
func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPolicy, route RouteContext, xdsIR XdsIRMap) {
// Build IR
var (
cors *ir.CORS
jwtAuthentication *ir.JWTAuthentication
cors *ir.CORS
jwt *ir.JWT
)

if policy.Spec.CORS != nil {
cors = t.buildCORS(policy)
}

if policy.Spec.JWTAuthentication != nil {
jwtAuthentication = t.buildJWTAuthentication(policy)
if policy.Spec.JWT != nil {
jwt = t.buildJWT(policy)
}

// Apply IR to all relevant routes
Expand All @@ -245,7 +245,7 @@ func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPoli
// route is associated with a Gateway API xRoute
if strings.HasPrefix(r.Name, prefix) {
r.CORS = cors
r.JWTAuthentication = jwtAuthentication
r.JWT = jwt
}
}
}
Expand All @@ -256,16 +256,16 @@ func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPoli
func (t *Translator) translateSecurityPolicyForGateway(policy *egv1a1.SecurityPolicy, gateway *GatewayContext, xdsIR XdsIRMap) {
// Build IR
var (
cors *ir.CORS
jwtAuthentication *ir.JWTAuthentication
cors *ir.CORS
jwt *ir.JWT
)

if policy.Spec.CORS != nil {
cors = t.buildCORS(policy)
}

if policy.Spec.JWTAuthentication != nil {
jwtAuthentication = t.buildJWTAuthentication(policy)
if policy.Spec.JWT != nil {
jwt = t.buildJWT(policy)
}

// Apply IR to all the routes within the specific Gateway
Expand All @@ -281,8 +281,8 @@ func (t *Translator) translateSecurityPolicyForGateway(policy *egv1a1.SecurityPo
if r.CORS == nil {
r.CORS = cors
}
if r.JWTAuthentication == nil {
r.JWTAuthentication = jwtAuthentication
if r.JWT == nil {
r.JWT = jwt
}
}
}
Expand Down Expand Up @@ -331,8 +331,8 @@ func (t *Translator) buildCORS(policy *egv1a1.SecurityPolicy) *ir.CORS {
}
}

func (t *Translator) buildJWTAuthentication(policy *egv1a1.SecurityPolicy) *ir.JWTAuthentication {
return &ir.JWTAuthentication{
Providers: policy.Spec.JWTAuthentication.Providers,
func (t *Translator) buildJWT(policy *egv1a1.SecurityPolicy) *ir.JWT {
return &ir.JWT{
Providers: policy.Spec.JWT.Providers,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ securityPolicies:
kind: Gateway
name: gateway-1
namespace: envoy-gateway
jwtAuthentication:
jwt:
providers:
- name: example1
issuer: https://one.example.com
Expand Down Expand Up @@ -105,7 +105,7 @@ securityPolicies:
kind: HTTPRoute
name: httproute-1
namespace: default
jwtAuthentication:
jwt:
providers:
- name: example3
issuer: https://three.example.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ securityPolicies:
name: policy-for-route
namespace: default
spec:
jwtAuthentication:
jwt:
providers:
- audiences:
- three.foo.com
Expand Down Expand Up @@ -219,7 +219,7 @@ securityPolicies:
name: policy-for-gateway
namespace: envoy-gateway
spec:
jwtAuthentication:
jwt:
providers:
- audiences:
- one.foo.com
Expand Down Expand Up @@ -275,7 +275,7 @@ xdsIR:
port: 8080
weight: 1
hostname: '*'
jwtAuthentication:
jwt:
providers:
- audiences:
- one.foo.com
Expand Down Expand Up @@ -319,7 +319,7 @@ xdsIR:
port: 8080
weight: 1
hostname: gateway.envoyproxy.io
jwtAuthentication:
jwt:
providers:
- audiences:
- three.foo.com
Expand Down
Loading

0 comments on commit 462e1e8

Please sign in to comment.