Mitigation Strategy: Strong Peer Identity Verification (using libp2p-pnet
and libp2p-tls
)
-
Mitigation Strategy: Implement a combination of Private Network Protector (
libp2p-pnet
) and TLS-based PeerID verification (libp2p-tls
). -
Description:
libp2p-pnet
(Private Network):- Generate a pre-shared key (PSK).
- Configure the
go-libp2p
host usinglibp2p.PrivateNetwork(psk)
during host creation, providing the PSK. - Ensure all nodes in your private network use the same PSK.
libp2p-tls
(TLS with PeerID Verification):- Configure
go-libp2p
to uselibp2p-tls
for transport security:libp2p.Security(libp2ptls.ID, libp2ptls.New)
. - Within your connection upgrade logic (e.g., a custom security upgrader), use
libp2ptls.ExtractPeerID
to get thePeerID
from the presented TLS certificate. - Verify that the extracted
PeerID
matches the expectedPeerID
. - Reject connections if the certificate is invalid or the
PeerID
doesn't match.
- Configure
-
Threats Mitigated:
- Impersonation: (Severity: High)
- Sybil Attacks: (Severity: High)
- Man-in-the-Middle (MITM) Attacks: (Severity: Medium)
-
Impact:
- Impersonation: Risk significantly reduced.
- Sybil Attacks: Risk significantly reduced (within the private network).
- MITM Attacks: Risk reduced (further mitigation with certificate pinning is recommended, but that's less directly
go-libp2p
).
-
Currently Implemented (Hypothetical Example):
libp2p-pnet
is implemented inhost.go
.libp2p-tls
is enabled by default. Basic certificate validation is performed.
-
Missing Implementation (Hypothetical Example):
- Strict
PeerID
verification is not consistently implemented. - Strong cipher suite enforcement is not explicitly configured.
- Strict
Mitigation Strategy: Connection Gating and Resource Management
-
Mitigation Strategy: Use a
ConnectionGater
and thego-libp2p-resource-manager
to control connections and limit resource consumption. -
Description:
ConnectionGater
:- Implement the
network.ConnectionGater
interface. - Implement logic within the interface methods (
InterceptPeerDial
,InterceptAccept
,InterceptSecured
,InterceptUpgraded
) to control connection establishment. - Use this logic to limit connections, block malicious peers, and prioritize connections.
- Register the
ConnectionGater
with the host usinglibp2p.ConnectionGater(yourGater)
.
- Implement the
go-libp2p-resource-manager
:- Create a
resource.Manager
instance:rm, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.InfiniteLimits))
or use arcmgr.NewDefaultResourceManager
. - Configure limits using the
resource.Manager
API (e.g.,rm.SetLimit(...)
). - Register the
resource.Manager
with the host usinglibp2p.ResourceManager(rm)
.
- Create a
-
Threats Mitigated:
- Eclipse Attacks: (Severity: Medium)
- Denial-of-Service (DoS) Attacks: (Severity: High)
- Sybil Attacks: (Severity: Medium)
-
Impact:
- Eclipse Attacks: Risk reduced.
- DoS Attacks: Risk significantly reduced.
- Sybil Attacks: Risk partially reduced.
-
Currently Implemented (Hypothetical Example):
- A basic
resource.Manager
is configured. - No
ConnectionGater
is implemented.
- A basic
-
Missing Implementation (Hypothetical Example):
ConnectionGater
is entirely missing.resource.Manager
limits are not fine-tuned.
Mitigation Strategy: GossipSub Hardening
-
Mitigation Strategy: Configure GossipSub parameters to improve resilience.
-
Description:
- Review GossipSub Parameters: Understand options like
WithPeerOutboundQueueSize
,WithValidateQueueSize
,WithMaxPendingConnections
,WithPeerExchange
,WithFloodPublish
,WithHeartbeatInterval
. - Adjust Parameters: Use the
pubsub.Options
when creating the GossipSub instance (e.g.,pubsub.NewGossipSub(ctx, host, pubsub.WithPeerExchange(true))
). Adjust parameters based on your needs.
- Review GossipSub Parameters: Understand options like
-
Threats Mitigated:
- Eclipse Attacks: (Severity: Medium)
- Denial-of-Service (DoS) Attacks: (Severity: Medium)
- Message Suppression/Modification: (Severity: Medium)
-
Impact:
- Eclipse Attacks: Risk reduced.
- DoS Attacks: Risk reduced.
- Message Suppression/Modification: Risk reduced.
-
Currently Implemented (Hypothetical Example):
- GossipSub is used with default parameters.
-
Missing Implementation (Hypothetical Example):
- No specific GossipSub hardening.
Mitigation Strategy: DHT Routing Table Protection (for libp2p-kad-dht
)
-
Mitigation Strategy: Use
libp2p-kad-dht
securely and implement custom validators. -
Description:
- Mode Selection:
- Use
dht.ModeServer
only on trusted nodes. - Use
dht.ModeClient
on all other nodes. Set this usingdhtopts.Mode(dht.ModeClient)
.
- Use
- Custom Validators (
WithValidators
):- Implement custom validation logic conforming to the
record.Validator
interface. - Use
dhtopts.Validator(yourValidator)
when creating the DHT instance.
- Implement custom validation logic conforming to the
- Redundancy: Query multiple peers for the same record.
- Refresh Routing Table: This happens automatically, but ensure reasonable refresh intervals.
- Mode Selection:
-
Threats Mitigated:
- Routing Table Poisoning: (Severity: High)
-
Impact:
- Routing Table Poisoning: Risk significantly reduced.
-
Currently Implemented (Hypothetical Example):
- Mixed
ModeServer
/ModeClient
configuration. - No custom validators.
- Mixed
-
Missing Implementation (Hypothetical Example):
ModeServer
on untrusted nodes.- No custom validators.