what is the macaroon max length In an LND node, what is the max size, in bytes, of a macaroon. If there is no explicit max length, what can you reasonably expect to be the size of your macaroon?
A macaroon consists of three parts:

The header: Identifies the macaroon and contains three fields.

The version: 1 byte, always set to 0x02 in lnd
The location: variable length string, always set to &quot;lnd&quot; in lnd
The identifier: variable length binary data, contains protobuf serialized data in lnd containing the permissions of the macaroon. More on that later.


The caveats: Restricts the capabilities of the macaroon. This is a variable length list of strings. lnd currently only implements two possible restrictions, the time-before and the ipaddr restriction.

Example with maximum characters:
[&quot;time-before 2006-01-02T15:04:05.999999999Z07:00&quot;, &quot;ipaddr 255.255.255.255&quot;]

Which is roughly 70 bytes plus some encoding overhead.


The signature: An HMAC-SHA256 hash, so 32 bytes plus encoding overhead.

The permissions
As mentioned above, the macaroon identifier contains a list of permissions. Currently this just contains a protobuf serialized list of {Entity string, Action string} pairs that correspond to permission sets in lnd. For example, the pair {Entity: &quot;info&quot;, Action: &quot;read&quot;} would give a user read-only access to informational calls.
These permissions make it a bit tricky to estimate the maximum size of a macaroon in lnd. At the moment, the maximum number of distinct entity/action pairs that exists is 17, which is given to the automatically created admin.macaroon. That admin macaroon currently is around 280 bytes in size.
But soon, you will be able to customize the permissions of a macaroon even further by specifying individual URIs that are allowed to be accessed. A user could could then, for example, add a permission pair of {Entity: &quot;uri&quot;, Action: &quot;/lnrpc.Lightning/ExportAllChannelBackups&quot;} to a custom macaroon.
Just for fun, I went ahead and created a maximum-sized macaroon with all currently available URIs which turned out to be 4041 bytes in size.
From that, I would summarize that limiting user input when uploading a macaroon to 4096 or 5120 bytes should cover almost all cases of custom macaroons.