Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ipfs/kubo/core/commands/cmdenv"
"github.com/ipfs/kubo/repo"
"github.com/ipfs/kubo/repo/fsrepo"
"github.com/libp2p/go-libp2p/core/peer"
)

// ConfigUpdateOutput is config profile apply command's output
Expand Down Expand Up @@ -607,6 +608,15 @@ func replaceConfig(r repo.Repo, file io.Reader) error {
}

newCfg.Identity.PrivKey = pkstr
pk, err := newCfg.Identity.DecodePrivateKey("")
if err != nil {
return errors.New("failed to decode PrivKey")
}
id, err := peer.IDFromPrivateKey(pk)
if err != nil {
return errors.New("failed to derive PeerID from PrivKey")
}
newCfg.Identity.PeerID = id.String()

// Handle Pinning.RemoteServices (API.Key of each service is a secret)

Expand Down
2 changes: 2 additions & 0 deletions docs/changelogs/v0.43.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ This release was brought to you by the [Shipyard](https://ipshipyard.com/) team.

### 📝 Changelog

- Fixed `ipfs config replace` to keep `Identity.PeerID` consistent with the preserved private key.

### 👨‍👩‍👧‍👦 Contributors
21 changes: 21 additions & 0 deletions test/cli/config_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ipfs/kubo/test/cli/harness"
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)

Expand Down Expand Up @@ -106,6 +107,26 @@ func TestConfigSecrets(t *testing.T) {
}
assert.Equal(t, origPrivKey, newPrivKey, "PrivKey should be preserved")
})

t.Run("Identity.PeerID is derived from preserved PrivKey during config replace", func(t *testing.T) {
t.Parallel()
node := harness.NewT(t).NewNode().Init()

originalPeerID := node.PeerID().String()
foreignPeerID := "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
assert.NotEqual(t, originalPeerID, foreignPeerID)

configShow := node.RunIPFS("config", "show").Stdout.String()
configJSON := MustVal(sjson.Set(configShow, "Identity.PeerID", foreignPeerID))
node.WriteBytes("foreign-peerid-config", []byte(configJSON))

node.IPFS("config", "replace", "foreign-peerid-config")

newConfig := node.ReadFile(node.ConfigFile())
newPeerID := gjson.Get(newConfig, "Identity.PeerID").String()
assert.Equal(t, originalPeerID, newPeerID)
assert.NotEqual(t, foreignPeerID, newPeerID)
})
})

t.Run("TLS security validation", func(t *testing.T) {
Expand Down