Commit graph

27 commits

Author SHA1 Message Date
bitromortac
b1593b9bee
rules: improve channel-restriction resilience
The channel-restriction rule was previously fragile because it failed to
initialize when a restricted channel was closed while the session was
inactive. This often caused unnecessary session invalidation and blocked
users from managing their nodes.

This change makes the rule resilient by allowing it to start even if
some channels in the deny-list are missing from the node's current
active set. To maintain high performance, this implements a negative
cache that tracks unknown channel IDs, shielding LND from redundant RPC
calls during request evaluation.

Only having a negative cache without invalidation can be a security
problem. Someone could apply a rule with a future guessed channel id
such that the channel restriction populates the checkedIDs map with it.
After the channel was opened, we'd then allow making actions on the
channel because we don't know about the channel's id in the getChannelID
check.

To ensure security isn't compromised by the cache, this adds a
self-healing retry mechanism. If the firewall encounters an unknown
channel outpoint while it still has unmapped restricted IDs, it clears
the negative cache and forces a single retry in the next RPC call. This
ensures that any newly opened restricted channels are correctly
identified and blocked without adding latency to the common path.

Note: This approach deliberately accepts potential cache thrashing in the
edge case where a user repeatedly requests an unknown channel point
while a permanently missing ID exists in the deny list. This trade-off
is accepted to prioritize security (fail close) over performance in this
specific invalid state.
2026-02-04 13:31:09 +01:00
bitromortac
7e0c04fea5
rules: add test to demo failure for closed channels
This also introduces the use of testify mock to check which calls were
made.
2026-02-03 15:40:13 +01:00
ffranr
a0e63124c0
multi: reformat long lines for readability
- Replace occurrences of `// nolint:lll` with `// nolint:ll` across
  files for consistency.
- Reformat multiline strings, comments, and function parameters to
  improve clarity and adhere to style guidelines.
- Add `// nolint:ll` comments where necessary to prevent linter
  warnings.
2025-12-09 16:12:03 +00:00
Elle Mouton
b4aadaa4bd
multi: rename ActionsDB to ActionsListDB
To better represent the interface and to free up the use of the
ActionsDB name as this will be used to represent the full Actions DB in
an upcoming commit.
2025-05-07 13:30:34 +02:00
Oliver Gugger
e995fcbeb7
mod: bump to latest version of tapd, lnd, loop 2025-04-29 21:18:48 +02:00
Elle
4cc7bf2b37
Merge pull request #1002 from ellemouton/sql24
[sql-24] firewalldb: thread contexts through for privacy mapper interfaces
2025-03-27 18:42:56 +02:00
Elle Mouton
dbec9da31b
multi: update LND and friends
This commit updates:
- LND
- pool
- loop
- taproot-assets
- faraday
- lighting-node-connect
- aperture
- lndclient
- btclog

We start using the new btclog v2 library and the associated breaking
changes in the lnd/build package.

With this commit, we deprecate the `--remote.lit-maxlogfiles` and
`--remote.lit-maxlogfilesize` options and introduce new logging options
under the `--remote.lit-logging` namespace.

Finally, the LND update introduced a new `MaxBlocksMinedPerTest`
variable in the `lntest` package that we now need to override in order
for our itests to pass.
2025-03-26 09:20:52 -05:00
Elle Mouton
7e8e4a9920
firewalldb: thread context to PseudoToReal
Update the PseudoToReal method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
7ce36d7e7d
multi: thread contexts through privacy map interfaces
Update the PrivacyMapDB interface methods to take contexts (both the
methods themselves and the call-back params) and then ensure all
implementations are updated and all call-sites pass contexts through
correctly.
2025-03-25 18:10:52 +02:00
Elle Mouton
9316a591a4
firewalldb+rules: thread contexts through KVStores methods 2025-03-11 15:44:15 -05:00
jiangmencity
fb9d3f51f7 chore: fix some typos in comment
Signed-off-by: jiangmencity <jiangmen@52it.net>
2025-01-20 19:57:29 +08:00
Elle Mouton
21983bab75
rules: thread context through 2025-01-13 09:23:20 +02:00
bitromortac
a36d6c0296
rules: restrict initial channel fee parameters
Channel policy boundaries are enforced for channel openings.
2024-07-02 18:21:41 +02:00
bitromortac
9911052fd7
rules: restrict channel open peers
We add a peer restriction for channel opening for OpenChannelSync and
BatchOpenChannel.
2024-07-02 18:21:41 +02:00
bitromortac
f5d57f8cf1
rules: add channel open constraints
We add a new channel constraint rule that enforces limits on channel
opening for the OpenChannelSync and BatchOpenChannel end points.

The channel constraint rule takes care about:
* min channel size
* max channel size
* max push amount
* no closing address was used
2024-07-02 18:21:41 +02:00
Elle Mouton
f8a36010e2
rules: add on-chain budget
This adds an on-chain budget that handles requests and responses for the
following endpoints:

* OpenChannelSync
* BatchOpenChannel

The budget rule checks that the onchain fee rate is not violated and
that pending and confirmed amounts are handled correctly.

An edge case can occur when lit crashes or shuts down after the budget
rule has forwarded a request but didn't receive a response yet. The
pending budget is not removed in case the request didn't go through and
is not accounted towards the spent budget in case the request did go
through. To be able to handle these cases in the future we add a unique
identifier to the request, that can be checked by calling LND's channel
bookkeeping APIs. Not all of them expose the identifier yet, which is
why pending actions cannot be deleted yet. This leads to underspending
of the budget and can be fixed by user intervention by creating a new
session. The memo prefix is removed when reading forwarding the
bookkeeping requests for privacy reasons.
2024-07-02 18:21:41 +02:00
bitromortac
7489f0a0b2
rules: pass in lnd connection identifier
We pass a random lnd connection identifier to the rule enforcer that is
unique per lnd connection lifetime. It is used to generate unique
request identifiers that amend the non-unique request identifiers that
are passed from lnd.
2024-07-02 15:04:26 +02:00
bitromortac
5129b95fd5
rules+rpcserver: handle unknown rules
This is to tolerate unknown rules sent from the autopilot for the
`autopilot features` command.

Otherwise, when trying to register a feature that requires an upgrade, a
more user friendly error is returned.
2024-04-25 18:19:48 +02:00
bitromortac
1636bb2bd6
firewall+rules: map with privacy flags
We change the rule mapping to accept the newly added privacy flags. Peer
and channel restrictions can be controlled with privacy flags.
2024-04-25 14:49:46 +02:00
Elle Mouton
8b5289953a
rules: let RealToPseudo take in a PrivacyMapReader
This commit expands the RealToPseudo methods to take in a privacy map db
reader. This allows the methods to check if the privacy map db already
contains an entry for a "real" string before generating a new one.

For now, only an empty PrivacyMapReader is ever provided to the
RealToPseudo call. This will be changed in the following commit.
2023-08-31 16:56:59 +02:00
Elle Mouton
0092435104
rules: add PeerRestrict rule 2023-01-27 06:47:12 +02:00
Elle Mouton
8425f4572d
rules: add ChannelRestrict rule 2023-01-27 06:47:12 +02:00
Elle Mouton
0629601d86
rules: add History Limit rule 2023-01-27 06:47:12 +02:00
Elle Mouton
ad9dd3e8ef
rules: add ChanPolicyBounds rule 2023-01-27 06:47:12 +02:00
Elle Mouton
042a5ee855
rules: add RateLimit rule 2023-01-27 06:47:12 +02:00
Elle Mouton
c4e7284de1
rules: add manager set 2023-01-27 06:47:12 +02:00
Elle Mouton
b5d5682a67
rules: add Rule interface 2023-01-27 06:47:12 +02:00