Skip to content

Commit 30339b6

Browse files
authored
Docs/Gateway: AWS Sigv4 (#6568)
1 parent a127321 commit 30339b6

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

packages/web/docs/src/content/gateway/authorization-authentication.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ gateway, and no other entity can execute requests to the subgraph on behalf of t
2424

2525
</Callout>
2626

27+
<Callout type="warning">
28+
If you are looking for an authentication for subgraph requests via [AWS Signature Version 4
29+
(Sigv4)](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html), you
30+
can enable `awsSigv4` flag documented [here](/docs/gateway/other-features/security/aws-sigv4).
31+
</Callout>
32+
2733
<Callout>
2834
You can refer to [Generic Auth plugin docs](https://www.npmjs.com/package/@envelop/generic-auth),
2935
if you need a more customized auth setup without JWT.

packages/web/docs/src/content/gateway/other-features/security/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
'disable-introspection': 'Introspection',
77
https: 'HTTPS',
88
'hmac-signature': 'HMAC Signature',
9+
'aws-sigv4': 'AWS Signature V4',
910
'audit-documents': 'Audit Documents',
1011
'block-field-suggestions': 'Block Field Suggestions',
1112
'character-limit': 'Character Limit',
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
searchable: false
3+
---
4+
5+
# AWS Signature Version 4 (SigV4)
6+
7+
Hive Gateway allows you to sign subgraph requests with
8+
[AWS Signature Version 4 (SigV4)](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html)
9+
for secure communication between the Gateway and the subgraphs.
10+
11+
```mermaid
12+
flowchart TD
13+
A[Consumer] -->|GraphQL Request| B(Hive Gateway)
14+
B --> C[Execution Engine]
15+
C -->|Subgraph request| D[AWS Sigv4 Plugin]
16+
D --> |Get the credentials| E[Assume Role I AM]
17+
E --> F[Sign the request]
18+
F --> |HTTP Request| G[Products Subgraph]
19+
C -->|Subgraph request| H[AWS Sigv4 Plugin]
20+
H --> |Get the credentials| I[Hard-coded configuration]
21+
I --> J[Sign the request]
22+
J --> |HTTP Request| K[Users Subgraph]
23+
```
24+
25+
## How to use?
26+
27+
You can enable AWS SigV4 signing by setting the `awsSigV4` option to `true` in the Gateway
28+
configuration.
29+
30+
```ts filename="gateway.config.ts"
31+
import { defineConfig } from '@graphql-hive/gateway'
32+
33+
export const gatewayConfig = defineConfig({
34+
awsSigV4: true
35+
})
36+
```
37+
38+
## Credentials
39+
40+
By default, Hive Gateway will use the standard environment variables to get the AWS credentials. But
41+
you can also provide the credentials directly in the configuration.
42+
43+
```ts filename="gateway.config.ts"
44+
import { defineConfig } from '@graphql-hive/gateway'
45+
46+
export const gatewayConfig = defineConfig({
47+
awsSigV4: {
48+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
49+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
50+
region: process.env.AWS_REGION
51+
}
52+
})
53+
```
54+
55+
### Assume Role (IAM)
56+
57+
You can provide the `roleArn` and `roleSessionName` to assume a role using the provided credentials.
58+
59+
```ts filename="gateway.config.ts"
60+
import { defineConfig } from '@graphql-hive/gateway'
61+
62+
export const gatewayConfig = defineConfig({
63+
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
68+
}
69+
})
70+
```
71+
72+
## Service and region configuration
73+
74+
By default, the plugin extracts the service and region from the URL of the subgraph. But you can
75+
also provide the service and region directly in the configuration.
76+
77+
```ts filename="gateway.config.ts"
78+
import { defineConfig } from '@graphql-hive/gateway'
79+
80+
export const gatewayConfig = defineConfig({
81+
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'
87+
}
88+
})
89+
```
90+
91+
## Subgraph-specific configuration
92+
93+
You can also configure the SigV4 signing for specific subgraphs by setting the `awsSigV4` option in
94+
the subgraph configuration.
95+
96+
```ts filename="gateway.config.ts"
97+
import { defineConfig } from '@graphql-hive/gateway'
98+
99+
export const gatewayConfig = defineConfig({
100+
// Allowing SigV4 signing for only the 'products' subgraph
101+
awsSigV4: subgraph => subgraph === 'products'
102+
})
103+
```
104+
105+
or you can provide the credentials directly per subgraph.
106+
107+
```ts filename="gateway.config.ts"
108+
import { defineConfig } from '@graphql-hive/gateway'
109+
110+
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'
121+
}
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'
130+
}
131+
}
132+
return false
133+
}
134+
})
135+
```

0 commit comments

Comments
 (0)