Skip to content

Commit 682a03f

Browse files
shaneuttk8s-ci-robot
authored andcommitted
docs: update GEP 1767 to remove TrueField type
Signed-off-by: Shane Utt <[email protected]>
1 parent 2322922 commit 682a03f

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

geps/gep-1767/index.md

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,6 @@ If `HTTPCORSFilter` is set, then the gateway will generate the response of the "
129129
For the actual cross-origin request, the gateway will add CORS headers to the response before it is sent to the client.
130130

131131
```golang
132-
// AllowCredentialsType describes valid value of config `AllowCredentials`.
133-
//
134-
// +kubebuilder:validation:Enum=true
135-
type AllowCredentialsType string
136-
137-
const (
138-
// The actual cross-origin request allows to include credentials.
139-
AllowCredentials AllowCredentialsType = "true"
140-
)
141-
142132
const (
143133
// HTTPRouteFilterCORS can be used to add CORS headers to an
144134
// HTTP response before it is sent to the client.
@@ -222,7 +212,7 @@ type HTTPCORSFilter struct {
222212
// Output:
223213
//
224214
// The `Access-Control-Allow-Origin` response header can only use `*`
225-
// wildcard as value when the `AllowCredentials` field is unspecified.
215+
// wildcard as value when the `AllowCredentials` field is false.
226216
//
227217
// Input:
228218
// Origin: https://foo.example
@@ -233,7 +223,7 @@ type HTTPCORSFilter struct {
233223
// Output:
234224
// Access-Control-Allow-Origin: *
235225
//
236-
// When the `AllowCredentials` field is specified and `AllowOrigins`
226+
// When the `AllowCredentials` field is true and `AllowOrigins`
237227
// field specified with the `*` wildcard, the gateway must return a
238228
// single origin in the value of the `Access-Control-Allow-Origin`
239229
// response header, instead of specifying the `*` wildcard. The value
@@ -259,8 +249,8 @@ type HTTPCORSFilter struct {
259249
// AllowCredentials indicates whether the actual cross-origin request
260250
// allows to include credentials.
261251
//
262-
// The only valid value for the `Access-Control-Allow-Credentials`
263-
// response header is true (case-sensitive).
252+
// When set to true, the gateway will include the `Access-Control-Allow-Credentials`
253+
// response header with value true (case-sensitive).
264254
//
265255
// Input:
266256
// Origin: https://foo.example
@@ -272,14 +262,12 @@ type HTTPCORSFilter struct {
272262
// Access-Control-Allow-Origin: https://foo.example
273263
// Access-Control-Allow-Credentials: true
274264
//
275-
// If the credentials are not allowed in cross-origin requests,
276-
// the gateway will omit the header `Access-Control-Allow-Credentials`
277-
// entirely rather than setting its value to false.
265+
// When set to false, the gateway will omit the header
266+
// `Access-Control-Allow-Credentials` entirely (this is the standard CORS
267+
// behavior).
278268
//
279269
// Support: Extended
280-
//
281-
// +optional
282-
AllowCredentials AllowCredentialsType `json:"allowCredentials,omitempty"`
270+
AllowCredentials *bool `json:"allowCredentials,omitempty"`
283271

284272
// AllowMethods indicates which HTTP methods are supported
285273
// for accessing the requested resource.
@@ -317,7 +305,7 @@ type HTTPCORSFilter struct {
317305
// Access-Control-Allow-Methods: GET, POST, DELETE, PATCH, OPTIONS
318306
//
319307
// The `Access-Control-Allow-Methods` response header can only use `*`
320-
// wildcard as value when the `AllowCredentials` field is unspecified.
308+
// wildcard as value when the `AllowCredentials` field is false.
321309
//
322310
// Input:
323311
// Access-Control-Request-Method: PUT
@@ -328,7 +316,7 @@ type HTTPCORSFilter struct {
328316
// Output:
329317
// Access-Control-Allow-Methods: *
330318
//
331-
// When the `AllowCredentials` field is specified and `AllowMethods`
319+
// When the `AllowCredentials` field is true and the `AllowMethods`
332320
// field specified with the `*` wildcard, the gateway must specify one
333321
// HTTP method in the value of the Access-Control-Allow-Methods response
334322
// header. The value of the header `Access-Control-Allow-Methods` is same
@@ -386,7 +374,7 @@ type HTTPCORSFilter struct {
386374
//
387375
// A wildcard indicates that the requests with all HTTP headers are allowed.
388376
// The `Access-Control-Allow-Headers` response header can only use `*` wildcard
389-
// as value when the `AllowCredentials` field is unspecified.
377+
// as value when the `AllowCredentials` field is false.
390378
//
391379
// Input:
392380
// Access-Control-Request-Headers: Content-Type, Cache-Control
@@ -397,8 +385,8 @@ type HTTPCORSFilter struct {
397385
// Output:
398386
// Access-Control-Allow-Headers: *
399387
//
400-
// When the `AllowCredentials` field is specified and `AllowHeaders` field
401-
// specified with the `*` wildcard, the gateway must specify one or more
388+
// When the `AllowCredentials` field is true and the `AllowHeaders` field
389+
// is specified with the `*` wildcard, the gateway must specify one or more
402390
// HTTP headers in the value of the `Access-Control-Allow-Headers` response
403391
// header. The value of the header `Access-Control-Allow-Headers` is same as
404392
// the `Access-Control-Request-Headers` header provided by the client. If
@@ -456,7 +444,7 @@ type HTTPCORSFilter struct {
456444
//
457445
// A wildcard indicates that the responses with all HTTP headers are exposed
458446
// to clients. The `Access-Control-Expose-Headers` response header can only use
459-
// `*` wildcard as value when the `AllowCredentials` field is unspecified.
447+
// `*` wildcard as value when the `AllowCredentials` field is false.
460448
//
461449
// Config:
462450
// exposeHeaders: ["*"]
@@ -590,7 +578,7 @@ spec:
590578
- allowOrigins:
591579
- https://foo.example
592580
- http://foo.example
593-
allowCredentials: "true"
581+
allowCredentials: true
594582
allowMethods:
595583
- GET
596584
- PUT
@@ -656,6 +644,48 @@ Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Request
656644
Access-Control-Expose-Headers: Content-Security-Policy
657645
```
658646

647+
### Disabling credentials
648+
649+
To disable credentials for cross-origin requests, simply don't set the
650+
`allowCredentials` field at all. If you prefer to be explicit, you can
651+
set it to `false`, although this will generally not be necessary:
652+
653+
```yaml
654+
apiVersion: gateway.networking.k8s.io/v1
655+
kind: HTTPRoute
656+
metadata:
657+
name: http-route-cors-no-credentials
658+
spec:
659+
hostnames:
660+
- http.route.cors.com
661+
parentRefs:
662+
- group: gateway.networking.k8s.io
663+
kind: Gateway
664+
name: http-gateway
665+
rules:
666+
- backendRefs:
667+
- kind: Service
668+
name: http-route-cors
669+
port: 80
670+
matches:
671+
- path:
672+
type: PathPrefix
673+
value: /resource/bar
674+
filters:
675+
- cors:
676+
allowOrigins:
677+
- https://foo.example
678+
allowCredentials: false
679+
allowMethods:
680+
- GET
681+
- POST
682+
type: CORS
683+
```
684+
685+
Omitting the field, and setting it to `false` both mean `false`. In this
686+
configuration the gateway will _not_ include the
687+
`Access-Control-Allow-Credentials` header in responses.
688+
659689
## Prior Art
660690
Some implementations already support CORS.
661691

geps/gep-1767/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors:
77
- lianglli
88
- robscott
99
- EyalPazz
10+
- shaneutt
1011
references:
1112
- https://github.com/kubernetes-sigs/gateway-api/pull/3435
1213
- https://github.com/kubernetes-sigs/gateway-api/pull/3637

0 commit comments

Comments
 (0)