Skip to content

Commit 7d84a3f

Browse files
committed
feat: rework gateway page and add recursive gateway
1 parent 3ad3e76 commit 7d84a3f

File tree

1 file changed

+81
-64
lines changed

1 file changed

+81
-64
lines changed

docs/concepts/ipfs-gateway.md

Lines changed: 81 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,103 +3,120 @@ title: IPFS Gateway
33
description: Learn why gateways are an important part of using IPFS in conjunction with the legacy web.
44
related:
55
'IPFS Docs: Address IPFS on the Web': /how-to/address-ipfs-on-web/
6-
'IPFS public gateway checker': https://ipfs.github.io/public-gateway-checker/
6+
'IPFS public gateway checker': https://ipfs.fyi/gateways
77
'Gateway specifications': https://specs.ipfs.tech/http-gateways/
88
---
99

1010
# IPFS Gateway
1111

12-
An _IPFS gateway_ is a web-based service that gets content from an IPFS network (private, or the public swarm backed by Amino DHT), and makes it available via HTTP, allowing IPFS-incompatible browsers, tools and software to benefit from [content-addressing](https://docs.ipfs.tech/concepts/content-addressing/). For example, some browsers or tools like [Curl](https://curl.haxx.se/) or [Wget](https://www.gnu.org/software/wget/) don't support IPFS natively and cannot access to IPFS content using canonical addressing like `ipfs://{CID}/{optional path to resource}`. While tools like [IPFS Companion](https://github.com/ipfs-shipyard/ipfs-companion) add browser support for native IPFS URLs, this is not always an option. As such, there are multiple gateway types and <VueCustomTooltip label="A way to address data by its hash rather than its location (IPs)." underlined multiline>gateway providers</VueCustomTooltip> available so that applications of all kinds can interface with IPFS using HTTP.
12+
An _IPFS gateway_ is a standardized HTTP API for getting content-addressed data from IPFS nodes and CID providers (private, or the public IPFS Mainnet). It allows using HTTP semantics for interaction with IPFS. For example, some browsers or tools like [Curl](https://curl.haxx.se/) or [Wget](https://www.gnu.org/software/wget/) don't support IPFS natively and cannot access to IPFS content using canonical addressing like `ipfs://{CID}/{optional path to resource}`. While tools like [IPFS Companion](https://github.com/ipfs-shipyard/ipfs-companion) add browser support for native IPFS URLs, this is not always an option. As such, IPFS gateways enable a broad range of applications to interface with IPFS using HTTP.
1313

1414
This page discusses:
1515

16-
- [Gateway request lifecycle](#gateway-request-lifecycle)
1716
- [Gateway providers](#gateway-providers)
1817
- [Gateway types](#gateway-types)
18+
- [Recursive vs. non-recursive gateways](#recursive-vs-non-recursive-gateways)
19+
- [Trusted vs. trustless gateways](#trusted-vs-trustless-gateways)
20+
- [Read-only gateways](#read-only-gateways)
21+
- [Authenticated gateways](#authenticated-gateways)
22+
- [Gateway request lifecycle](#gateway-request-lifecycle)
23+
- [Resolution styles](#resolution-styles)
24+
- [Path](#path)
25+
- [Subdomain](#subdomain)
26+
- [DNSLink](#dnslink)
27+
- [Gateway URL formats](#gateway-url-formats)
1928
- [Working with gateways](#working-with-gateways)
2029
- [Implementing gateways](#implementing-gateways)
21-
- [FAQs](#frequently-asked-questions-faqs)
22-
23-
## Gateway request lifecycle
24-
25-
:::callout
26-
This section uses the _default_ gateway request lifecycle of [IPFS Kubo](https://github.com/ipfs/kubo) to introduce the basic concepts in the lifecycle. However, some gateways only serve content that they have and/or want to provide. For example, a Kubo gateway with `NoFetch` enabled will not attempt to retrieve content from the network.
27-
:::
28-
29-
When a client request for a CID reaches an IPFS gateway, the gateway first checks whether the CID is cached locally. At this point, one of the following occurs:
30+
- [Learning more](#learning-more)
3031

31-
- **If the CID is cached locally**, the gateway responds with the content referred to by the CID, and the lifecycle is complete.
32-
33-
- **If the CID is not in the local cache**, the gateway will attempt to retrieve it from the network.
34-
35-
The CID retrieval process is composed of two parts, content discovery / routing and content retrieval:
32+
## Gateway providers
3633

37-
1. In the **content discovery / routing** step, the gateway will determine <VueCustomTooltip label="An IPFS network peer that can provide data specified by a particular CID upon request." underlined multiline>provider</VueCustomTooltip> location; that is, _where_ the data specified by the CID can be found:
34+
Regardless of who deploys a gateway and where, any IPFS gateway resolves access to any requested IPFS [content identifier](content-addressing.md).
3835

39-
- Asking peers that it is directly connected to if they have the data specified by the CID.
40-
- Query the DHT for the IDs and network addresses of peers that have the data specified by the CID.
36+
### Your local gateway
4137

42-
2. Next, the gateway performs **content retrieval**, which can be broken into the following steps:
38+
Your machine may host a gateway as a local service; e.g., at `localhost:8080`. You have a local gateway service if you installed [IPFS Desktop](https://github.com/ipfs-shipyard/ipfs-desktop#ipfs-desktop) or another form of IPFS node.
4339

44-
1. The gateway connects to the provider.
45-
1. The gateway fetches the CIDs content.
46-
1. The gateway streams the content to the client.
40+
### Public gateways
4741

48-
:::callout
49-
- Learn more about content discovery, routing, retrieval and the subsystems involved in each part of the process in [How IPFS works](./how-ipfs-works.md).
50-
- Dive into the technical specifications for gateways in the [IPFS HTTP Gateways specification](https://specs.ipfs.tech/http-gateways/) page.
51-
:::
42+
Public ([recursive](#recursive-vs-non-recursive-gateways)) gateways are provided by the IPFS various other organizations, including the [IPFS Foundation](./public-utilities.md#public-ipfs-gateways) as a public utility.
5243

53-
## Gateway providers
54-
55-
Regardless of who deploys a gateway and where, any IPFS gateway resolves access to any requested IPFS [content identifier](content-addressing.md). Therefore, for best performance, when you need the service of a gateway, you should use the one closest to you.
44+
For a list of public gateways, see the [IPFS Gateways Checker](https://ipfs.fyi/gateways).
5645

57-
### Your local gateway
46+
## Gateway types
5847

59-
Your machine may host a gateway as a local service; e.g., at `localhost:8080`. You have a local gateway service if you installed [IPFS Desktop](https://github.com/ipfs-shipyard/ipfs-desktop#ipfs-desktop) or another form of IPFS node.
48+
There are multiple gateway types, each with specific use case, security, performance, and functional implications.
6049

61-
### Private gateways
50+
- [Recursive vs. non-recursive gateways](#recursive-vs-non-recursive-gateways)
51+
- [Trusted vs. trustless gateways](#trusted-vs-trustless-gateways)
52+
- [Authentication support](#authenticated-gateways)
53+
- [Read support](#read-only-gateways)
6254

63-
_Private gateways_ are configured to limit access to requests from specific domains or parts of the public internet.
55+
### Recursive vs. non-recursive gateways
6456

65-
They are frequently, but not exclusively, used behind firewalls. Running [IPFS Desktop](https://github.com/ipfs-shipyard/ipfs-desktop#ipfs-desktop) or another form of IPFS node triggers connection attempts to other IPFS peers. Private network administrators may treat such connection attempts as potential security vulnerabilities. Private IPFS gateway servers located inside the private network and running a trusted code base provide an alternative architecture for read/write access to externally-hosted IPFS content.
57+
Recursive gateways are gateways that will attempt to retrieve content from other peers on the network if they do not have it locally.
6658

67-
### Public gateways
59+
Non-recursive gateways are gateways that only serve content that they have themselves. For example, [Kubo](https://github.com/ipfs/kubo) can be configured to act as a non-recursive gateway by setting the [`NoFetch`](https://github.com/ipfs/kubo/blob/master/docs/config.md#gatewaynofetch) option.
6860

69-
For more information about public gateways, see the [Public IPFS Gateways](./public-utilities.md#public-ipfs-gateways)
61+
In general, recursive gateways are more powerful for end-users because they abstract away all details of the peer-to-peer network. However, they are much more resource-intensive for operators and prone to abuse.
7062

71-
## Gateway types
63+
Non-recursive gateways are becoming a popular way to provide IPFS content to the network (as an alternative or in addition to Bitswap). Non-recursive provider records can only be announced to the [IPNI](../concepts/ipni/), but not the [DHT](../concepts/dht.md).
7264

73-
There are multiple gateway types, each with specific use case, security, performance, and functional implications.
65+
## Trusted vs. trustless gateways
7466

75-
- [Read support](#read-only-gateways)
76-
- [Authentication support](#authenticated-gateways)
77-
- [Resolution style](#resolution-style)
78-
- [Service](#gateway-services)
67+
See [Trusted vs. Trustless Gateways](../reference/http/gateway/#trusted-vs-trustless) for more information.
7968

8069
### Read-only gateways
8170

8271
_Read-only gateways_ are the simplest kind of gateway. This gateway type provides a way to fetch IPFS content using the HTTP GET method.
8372

84-
### Authenticated gateways
73+
## Authenticated gateways
8574

8675
If a gateway provider wants to limit access to requests with authentication, they may need to configure a reverse proxy, develop an IPFS plugin, or set a cache-layer above IPFS.
8776

8877
Configuring a reverse proxy is the most popular way for providers handling authentication. Reverse proxy can also keep the original IPFS API calls which makes gateway adaptable to all IPFS SDK and toolkits.
8978

9079
![Auth with Reverse proxy](./images/ipfs-gateways/public-authed-gateway.png)
9180

92-
Providers can design their own centralized authentication service like [Infura IPFS Auth](https://docs.infura.io/networks/ipfs/how-to/authenticate-requests), or a decentralized authentication service like [IPFS W3Auth](https://wiki.crust.network/docs/en/buildIPFSWeb3AuthGW)).
81+
## Gateway request lifecycle
82+
83+
:::callout
84+
This section uses the _default_ recursive gateway request lifecycle of [IPFS Kubo](https://github.com/ipfs/kubo) to introduce the basic concepts in the lifecycle. However, non-recursive gateways only serve content that they have and/or want to provide. For example, a Kubo gateway with `NoFetch` enabled will **not** attempt to retrieve content from the network.
85+
:::
86+
87+
When a client request for a CID reaches an IPFS gateway, the gateway first checks whether the CID is cached locally. At this point, one of the following occurs:
88+
89+
- **If the CID is cached locally**, the gateway responds with the content referred to by the CID, and the lifecycle is complete.
90+
91+
- **If the CID is not in the local cache**, the gateway will attempt to retrieve it from the network.
92+
93+
The CID retrieval process is composed of two parts, content discovery / routing and content retrieval:
94+
95+
1. In the **content discovery / routing** step, the gateway will determine <VueCustomTooltip label="An IPFS network peer that can provide data specified by a particular CID upon request." underlined multiline>provider</VueCustomTooltip> location; that is, _where_ the data specified by the CID can be found:
96+
97+
- Asking peers that it is directly connected to if they have the data specified by the CID.
98+
- Query the DHT for the IDs and network addresses of peers that have the data specified by the CID.
99+
100+
2. Next, the gateway performs **content retrieval**, which can be broken into the following steps:
101+
102+
1. The gateway connects to the provider.
103+
1. The gateway fetches the CIDs content.
104+
1. The gateway streams the content to the client.
105+
106+
:::callout
107+
- Learn more about content discovery, routing, retrieval and the subsystems involved in each part of the process in [How IPFS works](./how-ipfs-works.md).
108+
- Dive into the technical specifications for gateways in the [IPFS HTTP Gateways specification](https://specs.ipfs.tech/http-gateways/) page.
109+
:::
93110

94-
### Resolution style
111+
## Resolution styles
95112

96-
Three resolution styles exist:
113+
Gateways typically support three resolution styles:
97114

98115
- [Path](#path)
99116
- [Subdomain](#subdomain)
100117
- [DNSLink](#dnslink)
101118

102-
#### Path
119+
### Path
103120

104121
The examples discussed above employed path resolution:
105122

@@ -115,17 +132,17 @@ This type of gateway does not provide origin isolation and should not be used fo
115132
Learn more at [Address IPFS on the web: Path Gateway](../how-to/address-ipfs-on-web.md#path-gateway) and [Path Gateway Specification](https://specs.ipfs.tech/http-gateways/path-gateway/).
116133
:::
117134

118-
#### Subdomain
135+
### Subdomain
119136

120-
Subdomain resolution style maintains compliance with the [single-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy). The canonical form of access, `https://{CID}.ipfs.{gatewayURL}/{optional path to resource}`, causes the browser to interpret each returned file as being from a different origin.
137+
Subdomain resolution style ensures compliance with the [single-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy). The canonical form of access, `https://{CID}.ipfs.{gatewayURL}/{optional path to resource}`, ensures origin isolation per CID.
121138

122139
::: callout
123-
This type of gateway does provide origin isolation and should be used for hosting web apps.
140+
Subdomain gateways provide origin isolation and should be used for hosting web apps.
124141

125142
Learn more at [Address IPFS on the web: Subdomain Gateway](../how-to/address-ipfs-on-web.md#subdomain-gateway) and [Subdomain Gateway Specification](https://specs.ipfs.tech/http-gateways/subdomain-gateway/).
126143
:::
127144

128-
#### DNSlink
145+
### DNSLink
129146

130147
Whenever the content of data within IPFS changes, IPFS creates a new CID based on the content of that data. Many applications require access to the latest version of a file or website but will not know the exact CID for that latest version. The [InterPlanetary Name Service (IPNS)](ipns.md) allows a version-independent IPNS identifier to resolve into the current version's IPFS CID.
131148

@@ -141,7 +158,7 @@ DNSLink resolution occurs when the gateway recognizes an IPNS identifier contain
141158
https://{gateway URL}/ipns/{example.com}/{optional path}
142159
```
143160

144-
2. The gateway searches the DNS TXT records of the requested domain `{example.com}` for a string of the form `dnslink=/ipfs/{CID}` or `_dnslink=/ipfs/{CID}`. If found, the gateway uses the specified CID to serve up `ipfs://{CID}/{optional path}`. As with path resolution, this form of DNSLink resolution violates the single-origin policy. The domain operator may ensure single-origin policy compliance — and the delivery of the current version of content — by adding an `Alias` record in the DNS that refers to a suitable IPFS gateway; e.g., `gateway.ipfs.io`.
161+
2. The gateway searches the DNS TXT records of the requested domain `{_dnslink.example.com}` for a string of the form `dnslink=/ipfs/{CID}`. If found, the gateway uses the specified CID to serve up `ipfs://{CID}/{optional path}`. As with path resolution, this form of DNSLink resolution violates the single-origin policy. The domain operator may ensure single-origin policy compliance — and the delivery of the current version of content — by adding an `Alias` record in the DNS that refers to a suitable IPFS gateway; e.g., `gateway.ipfs.io`.
145162
3. The `Alias` record redirects any access to that `example.com` to the specified gateway. Hence the browser's request to `https://{example.com}/{optional path to resource}` redirects to the gateway specified in the `Alias`.
146163
4. The gateway employs DNSLink resolution to return the current content version from IPFS.
147164
5. The browser does not perceive the gateway as the origin of the content and therefore enforces the single-origin policy to protect `example.com`.
@@ -150,18 +167,18 @@ DNSLink resolution occurs when the gateway recognizes an IPNS identifier contain
150167
Learn more at [Address IPFS on the web: DNSLink Gateway](../how-to/address-ipfs-on-web.md#dnslink-gateway) and [DNSLink Gateway Specification](https://specs.ipfs.tech/http-gateways/dnslink-gateway/).
151168
:::
152169

153-
### Gateway services
170+
## Gateway URL formats
154171

155-
Currently HTTP gateways may access both IPFS and IPNS services:
172+
Currently HTTP gateways typically expose both immutable IPFS and mutable IPNS (either IPNS names or DNSLink) resources using the following URL formats:
156173

157-
| Service | Style | Canonical form of access |
158-
| ------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
159-
| IPFS | path | `https://{gateway URL}/ipfs/{CID}/{optional path to resource}` |
160-
| IPFS | subdomain | `https://{CID}.ipfs.{gatewayURL}/{optional path to resource}` |
161-
| IPFS | DNSLink | `https://{example.com}/{optional path to resource}` **preferred**, or <br>`https://{gateway URL}/ipns/{example.com}/{optional path to resource}` |
162-
| IPNS | path | `https://{gateway URL}/ipns/{IPNS identifier}/{optional path to resource}` |
163-
| IPNS | subdomain | `https://{IPNS identifier}.ipns.{gatewayURL}/{optional path to resource}` |
164-
| IPNS | DNSLink | Useful when IPNS identifier is a domain: <br>`https://{example.com}/{optional path to resource}` **preferred**, or <br>`https://{gateway URL}/ipns/{example.com}/{optional path to resource}` |
174+
| Service | Resolution style | Canonical form of access |
175+
| ------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
176+
| IPFS | path | `https://{gateway URL}/ipfs/{CID}/{optional path to resource}` |
177+
| IPFS | subdomain | `https://{CID}.ipfs.{gatewayURL}/{optional path to resource}` |
178+
| IPFS | DNSLink | `https://{example.com}/{optional path to resource}` **preferred**, or <br>`https://{gateway URL}/ipns/{example.com}/{optional path to resource}` |
179+
| IPNS | path | `https://{gateway URL}/ipns/{IPNS identifier}/{optional path to resource}` |
180+
| IPNS | subdomain | `https://{IPNS identifier}.ipns.{gatewayURL}/{optional path to resource}` |
181+
| IPNS | DNSLink | Useful when IPNS identifier is a domain: <br>`https://{example.com}/{optional path to resource}` **preferred**, or <br>`https://{gateway URL}/ipns/{example.com}/{optional path to resource}` |
165182

166183
## Working with gateways
167184

0 commit comments

Comments
 (0)