提交 0c8a0975 作者: Juan Batiz-Benet

Merge pull request #1221 from ipfs/unrestricted-api-access

Add option to allow unrestricted API access
...@@ -28,6 +28,7 @@ const ( ...@@ -28,6 +28,7 @@ const (
writableKwd = "writable" writableKwd = "writable"
ipfsMountKwd = "mount-ipfs" ipfsMountKwd = "mount-ipfs"
ipnsMountKwd = "mount-ipns" ipnsMountKwd = "mount-ipns"
unrestrictedApiAccess = "unrestricted-api"
// apiAddrKwd = "address-api" // apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm" // swarmAddrKwd = "address-swarm"
) )
...@@ -71,6 +72,7 @@ the port as you would other services or database (firewall, authenticated proxy, ...@@ -71,6 +72,7 @@ the port as you would other services or database (firewall, authenticated proxy,
cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"), cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"), cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"),
cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"), cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"),
cmds.BoolOption(unrestrictedApiAccess, "Allow API access to unlisted hashes"),
// TODO: add way to override addresses. tricky part: updating the config if also --init. // TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"), // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
...@@ -281,6 +283,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) { ...@@ -281,6 +283,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
Writable: true, Writable: true,
BlockList: &corehttp.BlockList{ BlockList: &corehttp.BlockList{
Decider: func(s string) bool { Decider: func(s string) bool {
unrestricted, _, _ := req.Option(unrestrictedApiAccess).Bool()
if unrestricted {
return true
}
// for now, only allow paths in the WebUI path // for now, only allow paths in the WebUI path
for _, webuipath := range corehttp.WebUIPaths { for _, webuipath := range corehttp.WebUIPaths {
if strings.HasPrefix(s, webuipath) { if strings.HasPrefix(s, webuipath) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论