Skip to content

Commit

Permalink
chore: adjust comment and use pointer for non-manandatory field
Browse files Browse the repository at this point in the history
Signed-off-by: Ardika Bagus <me@ardikabs.com>
  • Loading branch information
ardikabs committed Apr 17, 2024
1 parent 566aa30 commit 33b3bc0
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 67 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/jwt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package v1alpha1
// JWT defines the configuration for JSON Web Token (JWT) authentication.
type JWT struct {

// AllowMissing specifies whether a missing JWT is acceptable, but it will fail if an invalid JWT is presented.
//
AllowMissing bool `json:"allowMissing,omitempty"`
// AllowMissing determines whether a missing JWT is acceptable, defaulting to false if not specified.
// Note: Even if allowMissing is set to true, JWT authentication will still fail if an invalid JWT is presented.
AllowMissing *bool `json:"allowMissing,omitempty"`

// Providers defines the JSON Web Token (JWT) authentication provider type.
// When multiple JWT providers are specified, the JWT is considered valid if
Expand Down
5 changes: 5 additions & 0 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 @@ -423,8 +423,9 @@ spec:
authentication.
properties:
allowMissing:
description: AllowMissing specifies whether a missing JWT is acceptable,
but it will fail if an invalid JWT is presented.
description: |-
AllowMissing determines whether a missing JWT is acceptable, defaulting to false if not specified.
Note: Even if allowMissing is set to true, JWT authentication will still fail if an invalid JWT is presented.
type: boolean
providers:
description: |-
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func wildcard2regex(wildcard string) string {

func (t *Translator) buildJWT(jwt *egv1a1.JWT) *ir.JWT {
return &ir.JWT{
AllowMissing: jwt.AllowMissing,
AllowMissing: ptr.Deref(jwt.AllowMissing, false),
Providers: jwt.Providers,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,28 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: true
jwt:
providers:
- audiences:
- one.foo.com
claimToHeaders:
- claim: claim1
header: one-route-example-key
issuer: https://one.example.com
name: example1
remoteJWKS:
uri: https://one.example.com/jwt/public-key/jwks.json
- audiences:
- two.foo.com
claimToHeaders:
- claim: claim2
header: two-route-example-key
issuer: https://two.example.com
name: example2
remoteJWKS:
uri: https://two.example.com/jwt/public-key/jwks.json
name: grpcroute/default/grpcroute-1/rule/0/match/-1/*
security:
jwt:
providers:
- audiences:
- one.foo.com
claimToHeaders:
- claim: claim1
header: one-route-example-key
issuer: https://one.example.com
name: example1
remoteJWKS:
uri: https://one.example.com/jwt/public-key/jwks.json
- audiences:
- two.foo.com
claimToHeaders:
- claim: claim2
header: two-route-example-key
issuer: https://two.example.com
name: example2
remoteJWKS:
uri: https://two.example.com/jwt/public-key/jwks.json
envoy-gateway/gateway-2:
accessLog:
text:
Expand Down Expand Up @@ -357,28 +358,29 @@ xdsIR:
weight: 1
hostname: gateway.envoyproxy.io
isHTTP2: false
jwt:
allowMissing: true
providers:
- audiences:
- three.foo.com
claimToHeaders:
- claim: claim3
header: three-route-example-key
extractFrom:
cookies:
- session_access_token
headers:
- name: Authorization
valuePrefix: 'Bearer '
params:
- token
issuer: https://three.example.com
name: example3
remoteJWKS:
uri: https://three.example.com/jwt/public-key/jwks.json
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
name: ""
prefix: /
security:
jwt:
allowMissing: true
providers:
- audiences:
- three.foo.com
claimToHeaders:
- claim: claim3
header: three-route-example-key
extractFrom:
cookies:
- session_access_token
headers:
- name: Authorization
valuePrefix: 'Bearer '
params:
- token
issuer: https://three.example.com
name: example3
remoteJWKS:
uri: https://three.example.com/jwt/public-key/jwks.json
2 changes: 1 addition & 1 deletion internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ type CORS struct {
//
// +k8s:deepcopy-gen=true
type JWT struct {
// AllowMissing specifies whether JWT authentication could be optionally required.
// AllowMissing determines whether a missing JWT is acceptable.
//
AllowMissing bool `json:"allowMissing,omitempty" yaml:"allowMissing,omitempty"`

Expand Down
2 changes: 1 addition & 1 deletion internal/xds/translator/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func buildJWTAuthn(irListener *ir.HTTPListener) (*jwtauthnv3.JwtAuthentication,
})
}

if route.JWT.AllowMissing {
if route.Security.JWT.AllowMissing {
reqs = append(reqs, &jwtauthnv3.JwtRequirement{
RequiresType: &jwtauthnv3.JwtRequirement_AllowMissing{
AllowMissing: &emptypb.Empty{},
Expand Down
35 changes: 18 additions & 17 deletions internal/xds/translator/testdata/in/xds-ir/jwt-optional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ http:
hostname: "*"
pathMatch:
exact: "foo/bar"
jwt:
providers:
- name: example
issuer: https://www.example.com
audiences:
- foo.com
remoteJWKS:
uri: https://localhost/jwt/public-key/jwks.json
extractFrom:
cookies:
- session_access_token
headers:
- name: Authorization
valuePrefix: 'Bearer '
params:
- token
allowMissing: true
security:
jwt:
providers:
- name: example
issuer: https://www.example.com
audiences:
- foo.com
remoteJWKS:
uri: https://localhost/jwt/public-key/jwks.json
extractFrom:
cookies:
- session_access_token
headers:
- name: Authorization
valuePrefix: 'Bearer '
params:
- token
allowMissing: true
destination:
name: "first-route-dest"
settings:
Expand Down
3 changes: 1 addition & 2 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,8 @@ _Appears in:_

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allowMissing` | _boolean_ | true | AllowMissing specifies whether a missing JWT is acceptable, but it will fail if an invalid JWT is presented. |
| `providers` | _[JWTProvider](#jwtprovider) array_ | true | Providers defines the JSON Web Token (JWT) authentication provider type.<br />When multiple JWT providers are specified, the JWT is considered valid if<br />any of the providers successfully validate the JWT. For additional details,<br />see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/jwt_authn_filter.html. |

| `allowMissing` | _boolean_ | true | AllowMissing determines whether a missing JWT is acceptable, defaulting to false if not specified.<br />Note: Even if allowMissing is set to true, JWT authentication will still fail if an invalid JWT is presented. |
| `providers` | _[JWTProvider](#jwtprovider) array_ | true | Providers defines the JSON Web Token (JWT) authentication provider type.<br />When multiple JWT providers are specified, the JWT is considered valid if<br />any of the providers successfully validate the JWT. For additional details,<br />see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/jwt_authn_filter.html. |


Expand Down

0 comments on commit 33b3bc0

Please sign in to comment.