-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPIP: Gateway _redirects File #290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for filling this!
Will circle back to this when we land gateway specs and IPIP process, but made a quick pass from IPIP perspective (figuring out what works, what not, and what we can simplify), so thank you for your patience.
Left some comments inline (but feel free to ignore/park until final IPIP template lands)
@lidel out of curiosity, did you mean to close this? |
@justincjohnson no, I never closed this, thanks for the ping 🙏 It looks like a bug in Github – your PR should be switched to ps. I'll be going over IPIP reviews next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your angelic patience @justincjohnson ❤️
I did the first pass review of this along with your working code in ipfs/kubo#8890 – some questions / asks apply to both – details inline.
http-gateways/REDIRECTS_FILE.md
Outdated
- `301` - Permanent Redirect (default) | ||
- `302` - Temporary Redirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justincjohnson thoughts on also supporting these niche redirect codes?
The rationale is that the spec should state which codes are supported,
and implementation should error on unsupported ones.
By allowing all 301-308 variants here, we make it easier for people to move static website hosting to IPFS,
while keeping dynamic backends that process POST still around.
- `301` - Permanent Redirect (default) | |
- `302` - Temporary Redirect | |
- `301` - Permanent Redirect (default) | |
- `302` - Found (commonly used for Temporary Redirect) | |
- `303` - See Other (replacing PUT and POST with GET) | |
- `307` - Temporary Redirect (explicitly preserving body and HTTP method of original request) | |
- `308` - Permanent Redirect (explicitly preserving body and HTTP method of original request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lidel I'm not sure this makes sense. If I understand correctly, these additional methods assume we will be receiving requests with PUT and POST and then redirect rules can redirect those requests to a separate dynamic backend for processing, using the same PUT or POST method. The problem I see with this is the gateway currently isn't handling PUT and POST requests. Any requests with PUT or POST result in an error that the gateway is read-only. So any redirect rules that are processed will only be for GET or HEAD requests.
Are you wanting these changes in anticipation of future rearchitecting of the gateway to support writes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justincjohnson no, this is purely to maximize interop with HTTP semantics.
Supporting these codes makes it easier for people who have a regular web2 website to move hosting of that website to IPFS. They can redirect legacy POST endpoints to a different hostname (307, 308), or turn them to GET (303) and show user-friendly error page.
By making the migration less painful, we allow for migrating bigger websites in stages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume I'm missing something here. 😅
307 and 308 redirect using the same method as the request, so to redirect to a web2 backend using those codes we are assuming the request came to us as a POST.
303 can redirect a POST to a GET, which again assumes the request came to us as a POST.
My point is that currently the gateway won't even serve these requests, thus they will never reach the redirect code.
$ curl -X POST http://localhost:8080/ipfs/$CID
Method POST not allowed: read only access
But please do enlighten me. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, but the behavior you described is a bug/limitation in Kubo implementation, not a technical limitation blocking us from having them in this spec.
fwiw prior art for _redirects
implementations is that only 301 302 work everywhere:
- Cloudflare Pages docs state they support 301, 302, 303, 307, 308
- Netlify only supports 301 and 302, explicitly does not support 307, does not mention others
My suggestion is to include all HTTP redirect codes in the _redirects
spec for completeness, and fix Kubo at some point, but I don't feel strongly about this: at the end of the day, docs, examples, most users will use 301 and 302 and don't even know other codes exist. They have a very niche utility.
Should we keep 303, 307, 308 in this spec?
@thibmeu thoughts from Cloudflare side?
@dignifiedquire thoughts from Iroh's gateway side?
(I'll bring this up during today's IPFS Implementers call)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. That makes sense to me. 👌
@lidel I believe I've addressed all of your feedback on the spec and IPIP. In case it got lost in the resolved comments above, the car file fixture is attached again here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of comprehensive text fixtures, that implementers can use in their tests, thank you!
I think it is ready for final reviews.
We were missing some folks at IPFS Implementers Sync call today, so pinging here:
- @lidel will drop 👍 after I review feat(gateway): _redirects file support kubo#8890 :)
- @dignifiedquire will you have time to eyeball this from Iroh's point of view?
- @thattommyhall / @gmasgras / @alanshaw / @vasco-santos / @thibmeu any concerns from gateway operator side?
I have a couple of questions:
|
@fabricedesre the way I think about this is it mirrors a Netlify or Cloudflare Pages deploy. So, in part, we are following cow paths that are already paved, so using _redirects and the literal same syntax that the two mentioned systems already use. We'll see where other use cases end up, but the one to look at is PWAs / SPAs that need redirects support like this to be able to be deployed correctly and then viewed / function correctly across many IPFS contexts. So yes, this is "gateways only" to support publish your app to IPFS but load in an HTTP browser context. |
I would argue that netlify / cloudflare made the wrong choice of location here, but that ship has sailed :) Where I'm a bit more worried is focusing on a "HTTP browser context". Accessing IPFS through http is a temporary workaround until ipfs:// protocol handlers are available. Once this is the case (we have one in https://capyloon.org), this proposal adds a constraint to the code that resolves ipfs:// urls, turning it in some kind of application server to keep feature parity with "ipfs over http" urls. This is somewhat worrisome, depending on the implementation details. |
@fabricedesre I want to add my POV as an DAPP developer that has been waiting for this functionality for long time, and following this PR closely. Bringing these comments at this stage, when the PR was open for months is slightly unfair to the effort of contributors. I am not saying that your points are not valid, but they could have been introduced earlier in the process. For the part of IPFS fundamentals and HTTP workaround. I fully understand the IPFS design principles and see your point. However HTTP is not going anywhere anytime soon and coexistence and migration paths will be required for decades. To make a simile from the telco world SMS is alive and kicking in an industry that is already in its 6th generation. From an DAPP developer point of view, the rewrite feature is a must. My use case is having multiple URIs been served from the same "text" (template), a core feature of internet's content architecture for which a migration path to IPFS will be required. An ipfs:// protocol handlers alone would not fix the problem. And populating millions of CIDs for slightly different content (templating) would be as wasteful as creating an HTTP resource for each slightly different content, it is not going to happen. Will there be an efficient, IPFS native, way to implement a substitute for content templating? how would an ipfs:// entrypoint to templated content look like? That is a very fair question to make, but would probably require research both at IPFS level then followed by DAPP application stack adoption. Not happening anytime soon. All points to the fact that IPFS stack needs to offer a migration path, otherwise, why an HTTP gateway at all? I think the contributor has made an exceptional effort in providing this feature, carefully integrating with the current state of art and minimizing the impact on the HTTP gateway functionality, respecting its "transitional" nature.
This is a wise statement, for many of those use cases will need an IPFS native alternative. |
Late feedback is ok, I've pinged folks on discussion forums for this very reason :) Let's explore ramifications. How
|
Thinking aloud here, but I'm open to any needed changes, so this isn't push back per se. Are many developers familiar with well-known URIs and the Are there other projects outside the IPFS ecosystem that desire to use a well known, shared format for redirect specifications? Is there value in simply consolidating config into a single directory? Are many developers likely to assume they can configure redirects at any level of a project? |
Also to be clear, I appreciate @fabricedesre commenting on the implications for serving web content over |
I don't know if this will very useful to you, but I am going to relate how I would expect this to work when developing a DAPP front-end meant to be served via IPFS: It is normally regarded as good practice, i.e. the community is trying to convert development stacks so that the deliverable always works as relative content (there is no URL prefix kown) So, a DAPP front-end should work when "mounted" on a domain with a _dnslink, but should also work when accessed via CID directly, like:
So that the application is not dependent no how is accessed in the IPFS-verse, which makes it feel more "decentralized". I am not too familiar with .well-known but I associate it with metadata relative to the serving domain. A quick look at wikipedia states that the prefix "/well-known" is used. that would imply that there can be only one /well-known per domain. In my opinion _redirect medatadata should be maintained by the same person that maintains the content itself, as they are the ones that know which redirects or rewrites are required. There should not be any assumption of where it is going to be placed: i.e. should work in a "relative" fashion, working regardless of the level at which the content is finally placed. For example, I can think, imagine I want my application to serve maps/region/region_name content, but all of them are going to be served by a script called map_reagion.js in that folder. Then I could rewrite anything under maps/region/* into map_region.js living under the maps/region folder. map_region.js will use the information on the URL ifself to workout what exactly to render (i.e. zoom in a SVG, for example). Thanks to this setup, I can distribute links pointing to particular regions across the application of third parties. then: https://my_dapp.com/maps/reagion/US would work thanks to _dnslink Of course It would be possible to call it ./well-known instead of _redirects, but I believe /well-known is meant to be at the root, and that would be strange for the generic content gateway access as the resource would be https://ipfs.io/ipfs/CID/.well-known/ i guess. The case of _redirects is specified as living in the "publishing folder", whatever that means, seems more like ROOT_CID. or? |
Thanks for sharing that background info @rvalle. As mentioned in the spec, for security reasons...
So the It seems to me that making web apps securely accessible from any (possibly nested) IPFS path or from |
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
- Add max file size - Update test fixture CID, due to new tests for max file size
cross referencing from DNSLink and Subdomain specs, making is clear it is about _redirects file.
Thank you @justincjohnson for driving this IPIP, and everyone for feedback ❤️ Quick summary:
Thanks again, and see you on future IPIPs! 🚢 |
ipfs/kubo#8890 ipfs/specs#290 This commit was moved from ipfs/kubo@bcaacdd
👀 Preview
For reference, working code in Kubo PR: ipfs/kubo#8890