Lightning Nodes
This guide provides a comprehensive look at what macaroons are, how they work, and how to use them effectively with your Comet nodes.
Estimated reading time: 15 minutes
Macaroons are the authentication mechanism that secures access to your Comet Platform nodes. If you're building applications that interact with LND or Tapd nodes, understanding macaroons is essential.
What Are Macaroons?
Macaroons are a type of cryptographic credential designed for distributed authorization. Think of them as "cookies with superpowers", they're bearer tokens that can be attenuated (restricted) to grant specific permissions without requiring direct communication with the authentication server.
Why Macaroons Instead of Traditional Auth?
Traditional authentication methods like API keys or OAuth tokens have limitations in distributed systems:
API Keys are all-or-nothing: either you have full access or no access
OAuth requires callbacks and server-to-server communication for token validation
JWT tokens can't be easily restricted after issuance
Macaroons solve these problems by:
Granular Permissions: Each macaroon can specify exactly what operations are allowed
Attenuation: You can create a restricted version of a macaroon without contacting the server
Distributed Authorization: Third parties can add restrictions without invalidating the macaroon
Cryptographic Security: Tampering with permissions invalidates the macaroon signature
Real-World Analogy
Imagine a hotel key card (the macaroon) that:
Grants access to your room, the gym, and the pool
You can create a restricted copy that only opens your room (attenuation)
The hotel never needs to know you made this restricted copy
If someone tries to modify the restricted copy to add pool access, it stops working (tamper-proof)
That's how macaroons work with your Lightning and Taproot Assets nodes.
Macaroon Structure and Components
Understanding macaroon structure helps you use them effectively and troubleshoot issues.
Core Components
Every macaroon consists of three parts:
1. Identifier
A unique string that identifies which macaroon this is. The identifier is used by the server to look up the root key needed to verify the signature.
2. Caveats
A list of restrictions or conditions that must be satisfied for the macaroon to be valid. There are two types:
First-Party Caveats (enforced by the node itself):
Time-based expiration: "valid until 2026-12-31"
IP restrictions: "only from 203.0.113.45"
Method restrictions: "only for /v1/balance and /v1/channels endpoints"
Third-Party Caveats (require validation from another service):
"must authenticate with service X"
Rarely used in Lightning/Tapd contexts
Example caveats:
3. Signature
A cryptographic signature that proves the macaroon hasn't been tampered with. This is calculated using HMAC with a secret root key known only to the node.
Macaroon Encoding
Macaroons are typically base64-encoded when transmitted or stored:
When you see strings like this in configuration files or API requests, they're encoded macaroons.
Macaroon-Based Authentication in Comet Platform
Comet Platform uses macaroons to secure access to both LND and Tapd node interfaces.
Authentication Flow
Default Macaroons
When you create a node on Comet Platform, several macaroons are automatically generated:
For LND Nodes:
Macaroon | Permissions | Use Case |
|---|---|---|
admin.macaroon | Full access to all RPC methods | Administrative tasks, full node control |
readonly.macaroon | Read-only access (no state changes) | Monitoring, dashboards, analytics |
invoice.macaroon | Create and manage invoices | Payment processing applications |
router.macaroon | Route queries and updates | Payment routing optimization |
signer.macaroon | Sign messages and transactions | Authentication, proof of node ownership |
For Tapd Nodes:
Macaroon | Permissions | Use Case |
|---|---|---|
admin.macaroon | Full access to all Taproot Assets operations | Asset minting, transfers, full control |
readonly.macaroon | View asset balances and history | Monitoring and reporting |
mint.macaroon | Mint new assets only | Asset issuance applications |
send.macaroon | Send existing assets | Payment applications |
Security Note: Admin macaroons grant complete control over your node. Treat them like private keys—never share them, commit them to version control, or expose them in client-side code.
Permission Levels and Scopes
Macaroons support fine-grained permission control through URI patterns and method restrictions.
LND Permission Examples
Tapd Permission Examples
Creating and Managing Macaroons
Generating New Macaroons
You can create custom macaroons with specific permissions to follow the principle of least privilege.
Using LND CLI (via Comet)
Using Python SDK
Using JavaScript SDK
Setting Permissions and Restrictions
Time-Based Expiration
Create macaroons that automatically expire:
IP Restrictions
Restrict macaroon usage to specific IP addresses:
Note: IP restrictions are enforced by the LND node. Make sure your application's outbound IP is stable or use CIDR ranges.
Using Macaroons with API Calls
REST API
Macaroons are passed in the HTTP header Grpc-Metadata-macaroon as hex-encoded strings:
Python Example
JavaScript/Node.js Example
gRPC API
For gRPC connections, macaroons are passed as metadata:
Python Example
Go Example
Using Macaroons with CLI
The Comet CLI automatically handles macaroon authentication when you configure it:
Macaroon Security Best Practices
Storage Recommendations
DO:
✅ Store macaroons in secure, encrypted storage
✅ Use environment variables for server-side applications
✅ Use secure credential managers (AWS Secrets Manager, HashiCorp Vault)
✅ Encrypt macaroons at rest with strong encryption
✅ Use file system permissions (chmod 600) to restrict access
✅ Store different macaroons for different environments (dev, staging, prod)
DON'T:
❌ Commit macaroons to version control (Git, SVN, etc.)
❌ Include macaroons in client-side code or mobile apps
❌ Share macaroons via email, chat, or unencrypted channels
❌ Store macaroons in application logs
❌ Use the same macaroon across multiple services
❌ Store admin macaroons in production applications
Rotation Policies
Regularly rotate macaroons, especially after:
Team member departures
Security incidents or breaches
Suspected credential compromise
Major application updates
Every 90 days (recommended)
Rotation Process:
Revocation Procedures
If a macaroon is compromised:
Immediate Actions:
For Admin Macaroon Compromise:
If your admin macaroon is compromised, you may need to:
Immediately close all channels (if LND node)
Transfer all assets to a new address (if Tapd node)
Create a new node with fresh credentials
Restore funds/assets to the new node
Critical: Admin macaroon compromise is a serious security incident. Contact Comet support immediately at support@comet.platform.
Troubleshooting Macaroon Issues
Common Error Messages
"permission denied"
Cause: The macaroon doesn't have permission for the requested operation.
Solution:
"invalid macaroon signature"
Cause: The macaroon has been tampered with or is corrupted.
Solution:
Download a fresh copy from Comet dashboard
Verify the macaroon file isn't corrupted
Ensure you're using the correct macaroon for the node
"macaroon expired"
Cause: Time-based caveat has expired.
Solution:
"IP address not authorized"
Cause: Request is coming from an IP not listed in macaroon caveats.
Solution:
Verify your application's outbound IP address
Update IP restrictions or remove them:
Debugging Tips
1. Print Macaroon Contents
2. Test with Different Macaroons
3. Verify Encoding
4. Test REST vs gRPC
Sometimes REST works but gRPC doesn't (or vice versa). Test both:
Code Examples for Common Operations
Check Macaroon Permissions
Validate Macaroon Locally
Create Attenuated Macaroon
Related Resources
Connect to Your Node Guide - Using macaroons with various connection methods
API Reference - Complete API documentation with authentication examples
Security & Backup Management - Securing your macaroons and credentials
CLI Reference - CLI-based macaroon management
External Documentation
Need Help?
If you're experiencing issues with macaroons:
Check the Troubleshooting & FAQs guide
Review error messages carefully—they usually indicate the exact problem
Test with admin macaroon to isolate permission issues
Contact Comet support at support@comet.platform