Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 2f9f629

Browse files
authored
docs: auth (#227)
* docs: auth On-behalf-of: @SAP a.shcherbatiuk@sap.com Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com> --------- Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
1 parent 21ffb52 commit 2f9f629

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ This repository contains two main components:
1313
- [Listener](./docs/listener.md): watches a cluster and stores its openAPI spec in a directory.
1414
- [Gateway](./docs/gateway.md): exposes the openAPI spec as a GraphQL endpoints.
1515

16+
## Authorization
17+
18+
All information about authorization can be found in the [authorization](./docs/authorization.md) section.
19+
1620
## Quickstart
1721

1822
If you want to get started quickly, you can follow the [quickstart guide](./docs/quickstart.md).

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func initConfig() {
5151
v.SetDefault("openapi-definitions-path", "./bin/definitions")
5252
v.SetDefault("enable-kcp", true)
5353
v.SetDefault("local-development", false)
54-
v.SetDefault("authenticate-schema-requests", false)
54+
v.SetDefault("introspection-authentication", false)
5555

5656
// Listener
5757
v.SetDefault("listener-apiexport-workspace", ":root")

common/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package config
22

33
type Config struct {
4-
OpenApiDefinitionsPath string `mapstructure:"openapi-definitions-path"`
5-
EnableKcp bool `mapstructure:"enable-kcp"`
6-
LocalDevelopment bool `mapstructure:"local-development"`
7-
AuthenticateSchemaRequests bool `mapstructure:"authenticate-schema-requests"`
4+
OpenApiDefinitionsPath string `mapstructure:"openapi-definitions-path"`
5+
EnableKcp bool `mapstructure:"enable-kcp"`
6+
LocalDevelopment bool `mapstructure:"local-development"`
7+
IntrospectionAuthentication bool `mapstructure:"introspection-authentication"`
88

99
Listener struct {
1010
// Listener fields will be added here

docs/authorization.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Authorization
2+
3+
All requests must contain an `Authorization` header with a valid Bearer token by default:
4+
```shell
5+
{
6+
"Authorization": $YOUR_TOKEN
7+
}
8+
```
9+
You can disable authorization by setting the following environment variable:
10+
```shell
11+
export LOCAL_DEVELOPMENT=true
12+
```
13+
This is useful for local development and testing purposes.
14+
15+
## Introspection authentication
16+
17+
By default, introspection requests (i.e. the requests that are made to fetch the GraphQL schema) are **not** protected by authorization.
18+
19+
You can protect those requests by setting the following environment variable:
20+
```shell
21+
export INTROSPECTION_AUTHENTICATION=true
22+
```
23+
24+
### Error fetching schema
25+
26+
When GraphiQL page is loaded, it makes a request to fetch the GraphQL schema and there is no way to add the `Authorization` header to that request.
27+
28+
We have this [issue](https://github.com/openmfp/kubernetes-graphql-gateway/issues/217) open to fix this.
29+
30+
But for now, you can use the following workaround:
31+
1. Open the GraphiQL page in your browser.
32+
2. Add the `Authorization` header in the `Headers` section of the GraphiQL user interface like so:
33+
3. Press `Re-fetch GraphQL schema` button in the left sidebar(third button from the top).
34+
4. Now the GraphQL schema should be fetched, and you can use the GraphiQL interface as usual.

docs/quickstart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export ENABLE_KCP=false
2424
# you must point to the config of the cluster you want to run against
2525
export KUBECONFIG=YOUR_KUBECONFIG_PATH
2626
```
27+
28+
2729
## Running the Listener
2830

2931
Make sure you have done steps from the [setup section](#setup-the-environment).

gateway/manager/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (s *Service) handleAuth(w http.ResponseWriter, r *http.Request, token strin
136136
return false
137137
}
138138

139-
if s.AppCfg.AuthenticateSchemaRequests {
139+
if s.AppCfg.IntrospectionAuthentication {
140140
if s.isIntrospectionQuery(r) {
141141
ok, err := s.validateToken(r.Context(), token)
142142
if err != nil {

tests/gateway_test/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (suite *CommonTestSuite) SetupTest() {
9393

9494
suite.appCfg.LocalDevelopment = suite.LocalDevelopment
9595
suite.appCfg.Gateway.Cors.Enabled = true
96-
suite.appCfg.AuthenticateSchemaRequests = suite.AuthenticateSchemaRequests
96+
suite.appCfg.IntrospectionAuthentication = suite.AuthenticateSchemaRequests
9797

9898
suite.log, err = logger.New(logger.DefaultConfig())
9999
require.NoError(suite.T(), err)

0 commit comments

Comments
 (0)