@@ -8,6 +8,8 @@ Hive Gateway allows you to sign subgraph requests with
8
8
[ AWS Signature Version 4 (SigV4)] ( https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html )
9
9
for secure communication between the Gateway and the subgraphs.
10
10
11
+ ## Signing outgoing requests
12
+
11
13
``` mermaid
12
14
flowchart TD
13
15
A[Consumer] -->|GraphQL Request| B(Hive Gateway)
@@ -22,20 +24,22 @@ flowchart TD
22
24
J --> |HTTP Request| K[Users Subgraph]
23
25
```
24
26
25
- ## How to use?
27
+ ### How to use?
26
28
27
- You can enable AWS SigV4 signing by setting the ` awsSigV4 ` option to ` true ` in the Gateway
29
+ You can enable AWS SigV4 signing by setting the ` awsSigV4.outgoing ` option to ` true ` in the Gateway
28
30
configuration.
29
31
30
32
``` ts filename="gateway.config.ts"
31
33
import { defineConfig } from ' @graphql-hive/gateway'
32
34
33
35
export const gatewayConfig = defineConfig ({
34
- awsSigV4: true
36
+ awsSigV4: {
37
+ outgoing: true
38
+ }
35
39
})
36
40
```
37
41
38
- ## Credentials
42
+ ### Credentials
39
43
40
44
By default, Hive Gateway will use the standard environment variables to get the AWS credentials. But
41
45
you can also provide the credentials directly in the configuration.
@@ -45,14 +49,16 @@ import { defineConfig } from '@graphql-hive/gateway'
45
49
46
50
export const gatewayConfig = defineConfig ({
47
51
awsSigV4: {
48
- accessKeyId: process .env .AWS_ACCESS_KEY_ID ,
49
- secretAccessKey: process .env .AWS_SECRET_ACCESS_KEY ,
50
- region: process .env .AWS_REGION
52
+ outgoing: {
53
+ accessKeyId: process .env .AWS_ACCESS_KEY_ID ,
54
+ secretAccessKey: process .env .AWS_SECRET_ACCESS_KEY ,
55
+ region: process .env .AWS_REGION
56
+ }
51
57
}
52
58
})
53
59
```
54
60
55
- ### Assume Role (IAM)
61
+ #### Assume Role (IAM)
56
62
57
63
You can provide the ` roleArn ` and ` roleSessionName ` to assume a role using the provided credentials.
58
64
@@ -61,15 +67,17 @@ import { defineConfig } from '@graphql-hive/gateway'
61
67
62
68
export const gatewayConfig = defineConfig ({
63
69
awsSigV4: {
64
- region: process .env .AWS_REGION ,
65
- // By default it takes the credentials from the environment variables
66
- roleArn: ' arn:aws:iam::123456789012:role/role-name' , // process.env.AWS_ROLE_ARN
67
- roleSessionName: ' session-name' // process.env.AWS_ROLE_SESSION_NAME
70
+ outgoing: {
71
+ region: process .env .AWS_REGION ,
72
+ // By default it takes the credentials from the environment variables
73
+ roleArn: ' arn:aws:iam::123456789012:role/role-name' , // process.env.AWS_ROLE_ARN
74
+ roleSessionName: ' session-name' // process.env.AWS_ROLE_SESSION_NAME
75
+ }
68
76
}
69
77
})
70
78
```
71
79
72
- ## Service and region configuration
80
+ ### Service and region configuration
73
81
74
82
By default, the plugin extracts the service and region from the URL of the subgraph. But you can
75
83
also provide the service and region directly in the configuration.
@@ -79,16 +87,18 @@ import { defineConfig } from '@graphql-hive/gateway'
79
87
80
88
export const gatewayConfig = defineConfig ({
81
89
awsSigV4: {
82
- accessKeyId: process .env .AWS_ACCESS_KEY_ID ,
83
- secretAccessKey: process .env .AWS_SECRET_ACCESS_KEY ,
84
- region: process .env .AWS_REGION ,
85
- serviceName: ' lambda' ,
86
- region: ' us-east-1'
90
+ outgoing: {
91
+ accessKeyId: process .env .AWS_ACCESS_KEY_ID ,
92
+ secretAccessKey: process .env .AWS_SECRET_ACCESS_KEY ,
93
+ region: process .env .AWS_REGION ,
94
+ serviceName: ' lambda' ,
95
+ region: ' us-east-1'
96
+ }
87
97
}
88
98
})
89
99
```
90
100
91
- ## Subgraph-specific configuration
101
+ ### Subgraph-specific configuration
92
102
93
103
You can also configure the SigV4 signing for specific subgraphs by setting the ` awsSigV4 ` option in
94
104
the subgraph configuration.
@@ -97,8 +107,10 @@ the subgraph configuration.
97
107
import { defineConfig } from ' @graphql-hive/gateway'
98
108
99
109
export const gatewayConfig = defineConfig ({
100
- // Allowing SigV4 signing for only the 'products' subgraph
101
- awsSigV4 : subgraph => subgraph === ' products'
110
+ awsSigV4: {
111
+ // Allowing SigV4 signing for only the 'products' subgraph
112
+ outgoing : subgraph => subgraph === ' products'
113
+ }
102
114
})
103
115
```
104
116
@@ -108,28 +120,81 @@ or you can provide the credentials directly per subgraph.
108
120
import { defineConfig } from ' @graphql-hive/gateway'
109
121
110
122
export const gatewayConfig = defineConfig ({
111
- // Providing AWS SigV4 credentials for the 'products' and 'users' subgraphs separately
112
- // And do not allow SigV4 signing for any other subgraph
113
- awsSigV4(subgraph ) {
114
- // You can use hardcoded credentials for the 'products' subgraph
115
- if (subgraph === ' products' ) {
116
- return {
117
- accessKeyId: process .env .PRODUCTS_AWS_ACCESS_KEY_ID ,
118
- secretAccessKey: process .env .PRODUCTS_AWS_SECRET_ACCESS_KEY ,
119
- serviceName: ' lambda' ,
120
- region: ' eu-west-1'
123
+ awsSigV4: {
124
+ // Providing AWS SigV4 credentials for the 'products' and 'users' subgraphs separately
125
+ // And do not allow SigV4 signing for any other subgraph
126
+ outgoing(subgraph ) {
127
+ // You can use hardcoded credentials for the 'products' subgraph
128
+ if (subgraph === ' products' ) {
129
+ return {
130
+ accessKeyId: process .env .PRODUCTS_AWS_ACCESS_KEY_ID ,
131
+ secretAccessKey: process .env .PRODUCTS_AWS_SECRET_ACCESS_KEY ,
132
+ serviceName: ' lambda' ,
133
+ region: ' eu-west-1'
134
+ }
121
135
}
122
- }
123
- // You can use Assume Role for the 'users' subgraph
124
- if ( subgraph === ' users ' ) {
125
- return {
126
- roleArn : ' arn:aws:iam::123456789012:role/role -name' ,
127
- roleSessionName : ' session-name ' ,
128
- serviceName : ' s3 ' ,
129
- region: ' us-east-1 '
136
+ // You can use Assume Role for the 'users' subgraph
137
+ if ( subgraph === ' users' ) {
138
+ return {
139
+ roleArn: ' arn:aws:iam::123456789012:role/role-name ' ,
140
+ roleSessionName : ' session -name' ,
141
+ serviceName : ' s3 ' ,
142
+ region : ' us-east-1 '
143
+ }
130
144
}
145
+ return false
146
+ }
147
+ }
148
+ })
149
+ ```
150
+
151
+ ## Validating incoming requests
152
+
153
+ Hive Gateway can also mimic AWS services by validating the incoming requests with AWS SigV4.
154
+
155
+ But you have to provide some credentials using environment variables or directly in the
156
+ configuration.
157
+
158
+ ``` ts filename="gateway.config.ts"
159
+ import { defineConfig } from ' @graphql-hive/gateway'
160
+
161
+ export const gatewayConfig = defineConfig ({
162
+ awsSigV4: {
163
+ incoming: {
164
+ // Hard-coded secret
165
+ secretAccessKey : () => process .env .AWS_SECRET_ACCESS_KEY ,
166
+
167
+ // Or Assume Role
168
+ assumeRole : () => ({
169
+ roleArn: process .env [' AWS_ROLE_ARN' ],
170
+ roleSessionName: process .env [' AWS_ROLE_SESSION_NAME' ],
171
+ region: process .env [' AWS_REGION' ]
172
+ })
173
+ }
174
+ }
175
+ })
176
+ ```
177
+
178
+ ### Combining with JWT
179
+
180
+ If you use JWT for authentication for some services, you can combine both depending on the prefix in
181
+ the ` Authorization ` header.
182
+
183
+ In this case if the ` Authorization ` header starts with ` Bearer ` , the JWT will be used for
184
+ authentication, otherwise, the request will be validated with AWS SigV4.
185
+
186
+ ``` ts filename="gateway.config.ts"
187
+ import { defineConfig } from ' @graphql-hive/gateway'
188
+
189
+ export const gatewayConfig = defineConfig ({
190
+ awsSigV4: {
191
+ incoming: true
192
+ },
193
+ jwt: {
194
+ reject: {
195
+ missingToken: false ,
196
+ invalidToken: false
131
197
}
132
- return false
133
198
}
134
199
})
135
200
```
0 commit comments