Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Override role based unicast stream authorization on public network#8526

Merged
peterargue merged 5 commits into
leo/228-networking-unicast-authorizationonflow/flow-go:leo/228-networking-unicast-authorizationfrom
leo/fix-unicast-stream-authorization-public-networkonflow/flow-go:leo/fix-unicast-stream-authorization-public-networkCopy head branch name to clipboard
Apr 8, 2026
Merged

Override role based unicast stream authorization on public network#8526
peterargue merged 5 commits into
leo/228-networking-unicast-authorizationonflow/flow-go:leo/228-networking-unicast-authorizationfrom
leo/fix-unicast-stream-authorization-public-networkonflow/flow-go:leo/fix-unicast-stream-authorization-public-networkCopy head branch name to clipboard

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Apr 7, 2026

Copy link
Copy Markdown
Member

Skip role-based checks on the public network.

https://github.com/onflow/flow-go-internal/pull/7185

Summary by CodeRabbit

  • New Features

    • Added explicit unicast stream authorization configuration to network nodes. The system now supports both role-based authorization (validating sender and receiver roles) and unrestricted authorization modes, allowing flexible control over unicast message permissions across network participants.
  • Tests

    • Added comprehensive test coverage for unicast sender role authorization behavior and validation against message authentication configurations.

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bbc77bca-e51f-4845-b70c-1289401dcf3d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request introduces unicast stream authorization to Flow network nodes. It adds role-based authorization functions in the message package, extends the network configuration to support pluggable authorizers, and applies this configuration across access, observer, and follower node builders.

Changes

Cohort / File(s) Summary
Authorization Mechanism
network/message/authorization.go, network/message/authorization_test.go
Introduced IsAuthorizedUnicastSenderRole for role-based sender authorization and AlwaysAuthorizedUnicastSenderRole for unrestricted authorization. Implemented a unicastRoleAuthorization map defining allowed sender roles per receiver role. Added comprehensive tests including cross-validation against message configuration.
Configuration Infrastructure
network/underlay/network.go
Extended NetworkConfig with UnicastStreamAuthorizer field. Added WithUnicastStreamAuthorizer option function and default initialization in Validate() using message.IsAuthorizedUnicastSenderRole.
Node Builder Integration
cmd/access/node_builder/access_node_builder.go, cmd/observer/node_builder/observer_builder.go, follower/follower_builder.go
Applied UnicastStreamAuthorizer configuration with message.AlwaysAuthorizedUnicastSenderRole in underlay network initialization across all three node builders.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • janezpodhostnik

Poem

🐰 Role-based gates now guard the stream,
Unicast flows secure and clean,
Three builders unified in aim,
With authorization, all the same!
Hops of joy for networks keen! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: overriding role-based unicast stream authorization specifically on the public network, which aligns with the core modifications across all affected files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/fix-unicast-stream-authorization-public-network

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 3950604.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@zhangchiqing
zhangchiqing marked this pull request as ready for review April 7, 2026 23:54
@zhangchiqing
zhangchiqing requested a review from a team as a code owner April 7, 2026 23:54
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
network/underlay/network.go 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
network/message/authorization_test.go (1)

46-119: Add one underlay-level test for the callback wiring.

These tests only exercise the helper functions, and the “cross validation” path effectively treats every role as a possible receiver, so it can still pass even when NetworkConfig.UnicastStreamAuthorizer is never invoked at runtime. A small integration test around underlay.NewNetwork and incoming unicast handling would catch the regression this PR currently misses.

Based on learnings: Ensure network messages are authenticated and validated; treat message handling with the same high-assurance principles as other protocol code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@network/message/authorization_test.go` around lines 46 - 119, Add an
integration test that constructs an underlay network via underlay.NewNetwork
using a test NetworkConfig with a stubbed UnicastStreamAuthorizer and a test
incoming stream (e.g., a fake net.Conn or in-memory stream) to confirm the
authorizer callback and message validation path are invoked; specifically, wire
a UnicastStreamAuthorizer spy into NetworkConfig.UnicastStreamAuthorizer, start
the network, inject a crafted unicast message on the incoming stream, and assert
that the spy was called with the expected sender/receiver roles and that the
message handler path validated/authenticated the message (fail the test if the
authorizer is never called), so the test verifies callback wiring beyond the
helper functions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@network/underlay/network.go`:
- Around line 165-175: NetworkConfig.UnicastStreamAuthorizer is never used: add
a field UnicastStreamAuthorizer to the Network struct, initialize it in
NewNetwork from cfg.UnicastStreamAuthorizer (falling back to
message.IsAuthorizedUnicastSenderRole if nil), and in handleIncomingStream
consult that authorizer before reading/processing the unicast stream
(reject/close the stream if the callback returns false). Update references to
use Network.UnicastStreamAuthorizer so public-network overrides are honored.

---

Nitpick comments:
In `@network/message/authorization_test.go`:
- Around line 46-119: Add an integration test that constructs an underlay
network via underlay.NewNetwork using a test NetworkConfig with a stubbed
UnicastStreamAuthorizer and a test incoming stream (e.g., a fake net.Conn or
in-memory stream) to confirm the authorizer callback and message validation path
are invoked; specifically, wire a UnicastStreamAuthorizer spy into
NetworkConfig.UnicastStreamAuthorizer, start the network, inject a crafted
unicast message on the incoming stream, and assert that the spy was called with
the expected sender/receiver roles and that the message handler path
validated/authenticated the message (fail the test if the authorizer is never
called), so the test verifies callback wiring beyond the helper functions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c95c64d2-4d1a-4f62-ab89-6892537cf956

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce557d and 3950604.

📒 Files selected for processing (6)
  • cmd/access/node_builder/access_node_builder.go
  • cmd/observer/node_builder/observer_builder.go
  • follower/follower_builder.go
  • network/message/authorization.go
  • network/message/authorization_test.go
  • network/underlay/network.go

Comment thread network/underlay/network.go Outdated
Comment on lines +165 to +175
UnicastStreamAuthorizer func(flow.Role, flow.Role) bool
}

// Validate validates the configuration, and sets default values for any missing fields.
func (cfg *NetworkConfig) Validate() {
if cfg.UnicastMessageTimeout <= 0 {
cfg.UnicastMessageTimeout = DefaultUnicastTimeout
}
if cfg.UnicastStreamAuthorizer == nil {
cfg.UnicastStreamAuthorizer = message.IsAuthorizedUnicastSenderRole
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

The new unicast authorizer is never enforced.

Line 165 adds the callback to NetworkConfig, but Network never stores it and neither NewNetwork nor handleIncomingStream calls it. That makes the new public-network overrides a no-op and leaves the default role gate unused as well. Please thread the callback into Network and consult it before reading from an incoming unicast stream.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@network/underlay/network.go` around lines 165 - 175,
NetworkConfig.UnicastStreamAuthorizer is never used: add a field
UnicastStreamAuthorizer to the Network struct, initialize it in NewNetwork from
cfg.UnicastStreamAuthorizer (falling back to
message.IsAuthorizedUnicastSenderRole if nil), and in handleIncomingStream
consult that authorizer before reading/processing the unicast stream
(reject/close the stream if the callback returns false). Update references to
use Network.UnicastStreamAuthorizer so public-network overrides are honored.

@peterargue
peterargue changed the base branch from master to leo/228-networking-unicast-authorization April 8, 2026 17:09
@peterargue
peterargue merged commit 54fcaa7 into leo/228-networking-unicast-authorization Apr 8, 2026
@peterargue
peterargue deleted the leo/fix-unicast-stream-authorization-public-network branch April 8, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.