lncli: ip range caveat for macaroons

This commit is contained in:
Slyghtning 2025-03-07 09:57:57 +01:00
parent 26a4562263
commit 1681be6d65
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF

@ -30,6 +30,10 @@ var (
Name: "ip_address", Name: "ip_address",
Usage: "the IP address the macaroon will be bound to", Usage: "the IP address the macaroon will be bound to",
} }
macIPRangeFlag = cli.StringFlag{
Name: "ip_range",
Usage: "the IP range the macaroon will be bound to",
}
macCustomCaveatNameFlag = cli.StringFlag{ macCustomCaveatNameFlag = cli.StringFlag{
Name: "custom_caveat_name", Name: "custom_caveat_name",
Usage: "the name of the custom caveat to add", Usage: "the name of the custom caveat to add",
@ -557,6 +561,19 @@ func applyMacaroonConstraints(ctx *cli.Context,
) )
} }
if ctx.IsSet(macIPRangeFlag.Name) {
_, net, err := net.ParseCIDR(ctx.String(macIPRangeFlag.Name))
if err != nil {
return nil, fmt.Errorf("unable to parse ip_range "+
"%s: %w", ctx.String("ip_range"), err)
}
macConstraints = append(
macConstraints,
macaroons.IPLockConstraint(net.String()),
)
}
if ctx.IsSet(macCustomCaveatNameFlag.Name) { if ctx.IsSet(macCustomCaveatNameFlag.Name) {
customCaveatName := ctx.String(macCustomCaveatNameFlag.Name) customCaveatName := ctx.String(macCustomCaveatNameFlag.Name)
if containsWhiteSpace(customCaveatName) { if containsWhiteSpace(customCaveatName) {