Skip to content

Conversation

@ffranr
Copy link
Contributor

@ffranr ffranr commented Oct 8, 2025

This PR refactors the MacaroonWhitelist function to improve code clarity and enhance permission control:

  • Simplifies the structure by introducing an internal helper function.
  • Separates universe proof courier permissions from general read/write permissions for better logic isolation.
  • Inlines the defaultMacaroonWhitelist, ensuring all endpoint access is explicitly controlled by the user's configuration (read, write, courier, etc.).
  • Updates a stale comment in the proof courier implementation to reflect current behavior.

These changes make the permissioning model more secure by preventing certain endpoints from being always accessible by default.

ffranr added 4 commits October 8, 2025 11:13
Refactor the function by introducing an internal helper to improve
readability.
Refactor MacaroonWhitelist to handle public universe proof courier
permissions independently. This clarifies the logic and avoids coupling
courier access with other universe server permissions.
Remove the defaultMacaroonWhitelist map and inline its entries directly
into the conditional logic within MacaroonWhitelist. This ensures that
access to previously always-available endpoints is now governed by
explicit user configuration (read/write/courier), improving permission
control and aligning with expected access restrictions.
@ffranr ffranr added this to the v0.8 milestone Oct 8, 2025
@ffranr ffranr requested review from darioAnongba and jtobin October 8, 2025 11:11
@ffranr ffranr self-assigned this Oct 8, 2025
@ffranr ffranr added the gRPC label Oct 8, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @ffranr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on improving the security and clarity of the Macaroon permissioning model, enhancing the robustness of database migrations, and extending the functionality of Universe RPC endpoints to provide more detailed blockchain information. It refactors the MacaroonWhitelist for better control, adds a critical check for dirty database states during startup, and enriches FetchSupplyCommit and FetchSupplyLeaves RPC responses with block header data. New integration tests have been added to cover the enhanced RPC functionality, and relevant documentation has been updated.

Highlights

  • Macaroon Whitelist Refactoring: The MacaroonWhitelist function has been refactored to improve clarity and permission granularity. The defaultMacaroonWhitelist is now inlined, and universe proof courier permissions are explicitly separated from general read/write permissions. This ensures that all endpoint access is strictly controlled by user configuration, enhancing the security model by preventing certain endpoints from being always accessible by default.
  • Database Migration Robustness: A new check has been added to the tapd startup process to prevent it from proceeding if a SQLite database is in a 'dirty' state due to a failed migration. This change ensures that manual intervention is required to resolve database inconsistencies, preventing potential data corruption or unexpected behavior.
  • Enhanced Supply Commit/Leaves RPCs: The FetchSupplyCommit and FetchSupplyLeaves RPC endpoints now include a block_headers field in their responses. This new field provides a map of block header timestamps and hashes for all block heights referenced by supply leaves, allowing clients to obtain this crucial timing and hash information directly from the RPC response without performing separate blockchain queries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ffranr ffranr changed the base branch from 0-8-0-staging to main October 8, 2025 11:11
@ffranr ffranr moved this from 🆕 New to 👀 In review in Taproot-Assets Project Board Oct 8, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement to the macaroon permissioning system. The refactoring makes the code much clearer and enhances security by removing the default whitelist, ensuring all endpoint access is explicitly configured. The separation of concerns for different permission flags is well-executed. I have one suggestion to further improve maintainability.

Comment on lines +363 to +377
addEndpoints(
"/universerpc.Universe/Info",

"/universerpc.Universe/AssetRoots",
"/universerpc.Universe/QueryAssetRoots",
"/universerpc.Universe/AssetLeafKeys",
"/universerpc.Universe/AssetLeaves",
"/universerpc.Universe/QueryProof",

"/universerpc.Universe/FetchSupplyCommit",
"/universerpc.Universe/FetchSupplyLeaves",

"/authmailboxrpc.Mailbox/MailboxInfo",
"/authmailboxrpc.Mailbox/ReceiveMessages",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and prevent typos, it's a good practice to define these RPC endpoint paths as constants instead of using string literals directly. This is especially useful as these paths are used in multiple places in this function and potentially elsewhere in the codebase.

You could define them in a const block at the package level, for example:

const (
	// Universe RPC methods.
	UniverseInfoPath            = "/universerpc.Universe/Info"
	UniverseAssetRootsPath      = "/universerpc.Universe/AssetRoots"
	UniverseQueryAssetRootsPath = "/universerpc.Universe/QueryAssetRoots"
	UniverseAssetLeafKeysPath   = "/universerpc.Universe/AssetLeafKeys"
	UniverseAssetLeavesPath     = "/universerpc.Universe/AssetLeaves"
	UniverseQueryProofPath      = "/universerpc.Universe/QueryProof"
	UniverseFetchSupplyCommitPath = "/universerpc.Universe/FetchSupplyCommit"
	UniverseFetchSupplyLeavesPath = "/universerpc.Universe/FetchSupplyLeaves"

	// Mailbox RPC methods.
	MailboxInfoPath           = "/authmailboxrpc.Mailbox/MailboxInfo"
	MailboxReceiveMessagesPath = "/authmailboxrpc.Mailbox/ReceiveMessages"
	// ... and so on for other paths.
)

Then you can use these constants throughout the function, which makes the code more robust and easier to read.

Suggested change
addEndpoints(
"/universerpc.Universe/Info",
"/universerpc.Universe/AssetRoots",
"/universerpc.Universe/QueryAssetRoots",
"/universerpc.Universe/AssetLeafKeys",
"/universerpc.Universe/AssetLeaves",
"/universerpc.Universe/QueryProof",
"/universerpc.Universe/FetchSupplyCommit",
"/universerpc.Universe/FetchSupplyLeaves",
"/authmailboxrpc.Mailbox/MailboxInfo",
"/authmailboxrpc.Mailbox/ReceiveMessages",
)
addEndpoints(
UniverseInfoPath,
UniverseAssetRootsPath,
UniverseQueryAssetRootsPath,
UniverseAssetLeafKeysPath,
UniverseAssetLeavesPath,
UniverseQueryProofPath,
UniverseFetchSupplyCommitPath,
UniverseFetchSupplyLeavesPath,
MailboxInfoPath,
MailboxReceiveMessagesPath,
)

@ffranr ffranr marked this pull request as draft October 8, 2025 11:14
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18343162813

Details

  • 41 of 47 (87.23%) changed or added relevant lines in 2 files are covered.
  • 41 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.04%) to 56.553%

Changes Missing Coverage Covered Lines Changed/Added Lines %
taprpc/perms.go 38 44 86.36%
Files with Coverage Reduction New Missed Lines %
asset/group_key.go 2 72.15%
commitment/tap.go 2 85.42%
rfqmsg/records.go 2 71.29%
tapgarden/custodian.go 2 77.39%
universe/supplyverifier/manager.go 2 64.53%
universe/archive.go 3 81.46%
authmailbox/receive_subscription.go 4 77.89%
tapgarden/caretaker.go 4 76.63%
tapchannel/aux_leaf_signer.go 5 43.18%
tapdb/assets_store.go 7 79.61%
Totals Coverage Status
Change from base Build 18323057272: 0.04%
Covered Lines: 63949
Relevant Lines: 113078

💛 - Coveralls

@ffranr ffranr changed the base branch from main to 0-8-0-staging October 10, 2025 14:31
@ffranr ffranr marked this pull request as ready for review October 10, 2025 14:31
Copy link
Contributor

@darioAnongba darioAnongba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@jtobin jtobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, LGTM. 👍 👍

@jtobin jtobin merged commit 5a85843 into 0-8-0-staging Oct 13, 2025
54 of 57 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Oct 13, 2025
GeorgeTsagk pushed a commit that referenced this pull request Oct 20, 2025
…whitelist

Improve `MacaroonWhitelist` Structure and Permission Granularity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

5 participants