Skip to content
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

Gateway.APICommands configuration is ignored #8059

Closed
lidel opened this issue Apr 7, 2021 · 13 comments · Fixed by #10309
Closed

Gateway.APICommands configuration is ignored #8059

lidel opened this issue Apr 7, 2021 · 13 comments · Fixed by #10309
Assignees
Labels
kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization topic/config Topic config topic/gateway Topic gateway topic/rpc-api Issues related to Kubo RPC API at /api/v0

Comments

@lidel
Copy link
Member

lidel commented Apr 7, 2021

This one slipped between our fingers:

Problem

Gateway.APICommands is ignored, go-ipfs 0.8.0 uses hardcoded list of commands:
(cmd/ipfs/daemon.go#L669core/commands/root.go#L166-L198

Why this matters

This is blocking our users from running their own delegated routing service without additional nginx magic as noted in libp2p/js-libp2p#371:

We were trying to use Gateway.APICommands in context of ipfs/js-ipfs#2155 (comment) but it did not work, and @mburns had to redirect to API port at Nginx level.

How to fix it?

Unsure, needs more analysis.
I see two ways to resolve this:

(A) keep implicit safelist, extend it with values added to APICommands

A backward-compatible way to fix this is to keep current implicit defaults from core/commands/root.go#L166-L198 when Gateway.APICommands is empty, but if we do this, how can gateway operator disable /api/v0 entierely if they wish to do so?

(B) no /api/v0 by default, only explicit opt-in safelist via APICommands

Perhaps we should make a breaking change and disable /api/v0 by default on Gateways, unless user explicitly safelisted commands via Gateway.APICommands ? This feels like a way safer default. We have some features that depend on /api/v0 and /ipfs/ endpoint does not provide replacement for them yet, so better to avoid this (eg. we don't want user to safelist dht/put but break refs as a side effect)


It always felt to me like something that should be opt-in, but would appreciate feedback if someone thinks otherwise.

@lidel lidel added kind/bug A bug in existing code (including security flaws) topic/gateway Topic gateway need/triage Needs initial labeling and prioritization topic/config Topic config topic/rpc-api Issues related to Kubo RPC API at /api/v0 labels Apr 7, 2021
@aschmahmann
Copy link
Contributor

We're going to go with option A here.

@BigLep BigLep added this to the Best Effort Track milestone Mar 10, 2022
@BigLep
Copy link
Contributor

BigLep commented Mar 10, 2022

@lidel : is this a good candidate for @schomatis ?

@schomatis
Copy link
Contributor

Yes, assigning.

@schomatis schomatis self-assigned this Mar 10, 2022
@schomatis schomatis moved this to 🥞 Todo in IPFS Shipyard Team Mar 10, 2022
@schomatis schomatis moved this from 🥞 Todo to 🏃‍♀️ In Progress in IPFS Shipyard Team Mar 26, 2022
@schomatis
Copy link
Contributor

@lidel Working on this, do we want an extra config for

how can gateway operator disable /api/v0 entierely if they wish to do so?

?

@schomatis
Copy link
Contributor

@lidel Looking at APICommands, this option is an array of strings. How should they work? Do we expect the user to provide the name of ipfs subcommands (which we would search by reflection I imagine), would they provide more specialized subcommands, like block.get or block.stat, for example, to only select the read variants of a subcommand?

I'm temporarily blocking this issue on getting some simple and concrete examples since I don't see any documentation around the option that we need to implement.

@schomatis schomatis moved this from 🏃‍♀️ In Progress to 🛑 Blocked in IPFS Shipyard Team Mar 28, 2022
@lidel
Copy link
Member Author

lidel commented Apr 14, 2022

@schomatis

  • yes, we want to allow safelisting of a specific subcomand so people don't expose too much.
    • Cosmetic note: using / as a separator may be a better idea, as cmd/subcmd maps to /api/v0/cmd/subcmd URL paths better than .
  • re "how can gateway operator disable /api/v0 entierely if they wish to do so?" – what we want is to remove all implicitly exposed /api/v0 endpoints from the gateway port, and expose only things that user explicitly added to the APICommands array.
    • Rationale: most of the gateway operators don't need anything from /api/v0 and exposing it only opens them to expensive preload calls like /api/v0/refs?r=true (which are inexpensive for person sending the request)

@schomatis schomatis moved this from 🛑 Blocked to 🥞 Todo in IPFS Shipyard Team Apr 15, 2022
@schomatis schomatis moved this from 🥞 Todo to 🏃‍♀️ In Progress in IPFS Shipyard Team May 3, 2022
@schomatis
Copy link
Contributor

We're definitely not prepared to select only a subset of subcommands. This will likely require some reworking of the commands library.

@schomatis
Copy link
Contributor

The simplest approach seems to add a function to prune the commands root given a list of whitelisted commands. The code would use similar logic to the subcommand resolution.

We should use a single hardcoded "master" root:

https://github.com/ipfs/go-ipfs/blob/25cc85fa9359f907f348e0c2139f2b535313c56c/core/commands/root.go#L122-L126

from which all the other subsets like the hardcoded read-only variant

https://github.com/ipfs/go-ipfs/blob/25cc85fa9359f907f348e0c2139f2b535313c56c/core/commands/root.go#L174-L182

would instead be generated on-the-fly through a list of strings (just as the APICommands one the user would provide in its config file) using this new logic.


re "how can gateway operator disable /api/v0 entierely if they wish to do so?" – what we want is to remove all implicitly exposed /api/v0 endpoints from the gateway port, and expose only things that user explicitly added to the APICommands array.

I still can't detect a clear answer to this. When APICommands is empty do we want to use the read-only list (shown above) or nothing (allow no command)?


@lidel Blocking until getting confirmation on the proposed approach.

@schomatis schomatis moved this from 🏃‍♀️ In Progress to 🛑 Blocked in IPFS Shipyard Team May 3, 2022
@lidel
Copy link
Member Author

lidel commented May 10, 2022

@schomatis Generating gateway subset on the fly based on APICommands sgtm.

When APICommands is empty do we want to use the read-only list (shown above) or nothing (allow no command)?

We want nothing – exposing /api/v0 on Gateway should be a conscious opt-in.

@schomatis schomatis moved this from 🛑 Blocked to 🥞 Todo in IPFS Shipyard Team May 10, 2022
@schomatis schomatis moved this from 🥞 Todo to 🏃‍♀️ In Progress in IPFS Shipyard Team May 11, 2022
@schomatis
Copy link
Contributor

Blocked on landing ipfs/go-ipfs-cmds#231.

@schomatis schomatis moved this from 🏃‍♀️ In Progress to 🛑 Blocked in IPFS Shipyard Team May 20, 2022
@hacdias
Copy link
Member

hacdias commented Jan 18, 2024

@lidel considering the current goal of removing /api/v0 from the gateway port completely, I would suggest just removing the configuration.

@lidel
Copy link
Member Author

lidel commented Jan 18, 2024

@hacdias yep, it is not even documented at docs/config.md, let's remove it.

@hacdias
Copy link
Member

hacdias commented Jan 18, 2024

@lidel there you have it #10309

@github-project-automation github-project-automation bot moved this from 🛑 Blocked to 🎉 Done in IPFS Shipyard Team Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization topic/config Topic config topic/gateway Topic gateway topic/rpc-api Issues related to Kubo RPC API at /api/v0
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants