ipfs/kubo

ipfs config replace can result in a broken configuration.

Geschlossen

#8.993 geöffnet am 24.05.2022

 (8 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Go (2.725 Forks)batch import
dif/easygood first issuehelp wantedkind/bugneed/triage

Repository-Metriken

Stars
 (13.906 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 4T 2h) (28 gemergte PRs in 30 T)

Beschreibung

Checklist

Installation method

built from source

Version

go-ipfs version: 0.14.0-dev
Repo version: 12
System version: amd64/linux
Golang version: go1.18.1

Config

{
  "API": {
    "HTTPHeaders": {}
  },
  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "AppendAnnounce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001",
      "/ip4/0.0.0.0/udp/4001/quic",
      "/ip6/::/udp/4001/quic"
    ]
  },
  "AutoNAT": {},
  "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
  ],
  "DNS": {
    "Resolvers": {}
  },
  "Datastore": {
    "BloomFilterSize": 0,
    "GCPeriod": "1h",
    "HashOnRead": false,
    "Spec": {
      "mounts": [
        {
          "child": {
            "path": "blocks",
            "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
            "sync": true,
            "type": "flatfs"
          },
          "mountpoint": "/blocks",
          "prefix": "flatfs.datastore",
          "type": "measure"
        },
        {
          "child": {
            "compression": "none",
            "path": "datastore",
            "type": "levelds"
          },
          "mountpoint": "/",
          "prefix": "leveldb.datastore",
          "type": "measure"
        }
      ],
      "type": "mount"
    },
    "StorageGCWatermark": 90,
    "StorageMax": "10GB"
  },
  "Discovery": {
    "MDNS": {
      "Enabled": true,
      "Interval": 10
    }
  },
  "Experimental": {
    "AcceleratedDHTClient": false,
    "FilestoreEnabled": false,
    "GraphsyncEnabled": false,
    "Libp2pStreamMounting": false,
    "P2pHttpProxy": false,
    "StrategicProviding": false,
    "UrlstoreEnabled": false
  },
  "Gateway": {
    "APICommands": [],
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    },
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": null,
    "RootRedirect": "",
    "Writable": false
  },
  "Identity": {
    "PeerID": "12D3KooWEap9eCWiatZSAxz1f3HgCN5SiJqm6kyp6SwYEnE1CC8G"
  },
  "Internal": {},
  "Ipns": {
    "RecordLifetime": "",
    "RepublishPeriod": "",
    "ResolveCacheSize": 128
  },
  "Migration": {
    "DownloadSources": [],
    "Keep": ""
  },
  "Mounts": {
    "FuseAllowOther": false,
    "IPFS": "/ipfs",
    "IPNS": "/ipns"
  },
  "Peering": {
    "Peers": null
  },
  "Pinning": {
    "RemoteServices": {}
  },
  "Plugins": {
    "Plugins": null
  },
  "Provider": {
    "Strategy": ""
  },
  "Pubsub": {
    "DisableSigning": false,
    "Router": ""
  },
  "Reprovider": {
    "Interval": "12h",
    "Strategy": "all"
  },
  "Routing": {
    "Type": "dht"
  },
  "Swarm": {
    "AddrFilters": null,
    "ConnMgr": {
      "GracePeriod": "20s",
      "HighWater": 900,
      "LowWater": 600,
      "Type": "basic"
    },
    "DisableBandwidthMetrics": false,
    "DisableNatPortMap": false,
    "RelayClient": {},
    "RelayService": {},
    "ResourceMgr": {},
    "Transports": {
      "Multiplexers": {},
      "Network": {},
      "Security": {}
    }
  }
}

Description

It is possible to pass a configuration file that will result in the IPFS node not being startable again.

Steps to reproduce:

  1. Produce a broken config file with no Identity portion
jq 'del(.Identity)' <.ipfs/config >config.borked
  1. replace the config using the built-in utility
ipfs config replace config.borked

now you have an IPFS daemon that can never start again.

Why this is bad:

Well, if you try to replace the config file with a fully-functional config file, i.e. one that has a complete Identiy secion including public and private keys, you are presented an error.

Error: setting private key with API is not supported

if you aren't careful, you might read this as you cannot set your identity through the API. But this is not the case. It only wants the private key to be removed.

That got me thinking.... what if I save the config the right way, and then move the config to another ipfs instance, will this result in a corrupted config file as well? it turns out that it does.

ipfs init
ipfs daemon (in another terminal)
ipfs config show > config.good

and on a second fresh instance

ipfs init
ipfs daemon (in another terminal)
ipfs config replace config.good

this time, you will have a config with mismatched public and private keys. Next time IPFS is started, the following is shown.

Initializing daemon...
go-ipfs version: 0.14.0-dev
Repo version: 12
System version: amd64/linux
Golang version: go1.18.1
2022-05-24T16:55:16.639-0700	ERROR	core	core/builder.go:117	constructing the node: could not build arguments for function "github.com/ipfs/go-ipfs/core/node/libp2p".PstoreAddSelfKeys (/home/cory/go/src/github.com/ipfs/go-ipfs/core/node/libp2p/libp2p.go:42): failed to build crypto.PrivKey: received non-nil error from function "github.com/ipfs/go-ipfs/core/node".PrivateKey.func1 (/home/cory/go/src/github.com/ipfs/go-ipfs/core/node/identity.go:18): private key in config does not match id: 12D3KooWGShTrRSCeRoQCwBmKz4vJVNYuUda11dbvZvERGynd3C6 != 12D3KooWMY1eWZGCA9Ut28KbBbmXcWQ3Ggoatjqh5akakYN4mnpP

Error: constructing the node (see log for full detail): private key in config does not match id: 12D3KooWGShTrRSCeRoQCwBmKz4vJVNYuUda11dbvZvERGynd3C6 != 12D3KooWMY1eWZGCA9Ut28KbBbmXcWQ3Ggoatjqh5akakYN4mnpP

Contributor Guide