Skip to content

[New Permission 3/5] smartcontract: enforce Permission-based authorization in existing instructions#3206

Open
juan-malbeclabs wants to merge 9 commits intomainfrom
jo/permission-enforcement
Open

[New Permission 3/5] smartcontract: enforce Permission-based authorization in existing instructions#3206
juan-malbeclabs wants to merge 9 commits intomainfrom
jo/permission-enforcement

Conversation

@juan-malbeclabs
Copy link
Contributor

@juan-malbeclabs juan-malbeclabs commented Mar 9, 2026

PR 5 of 5. Review order: PR 1: scaffoldPR 2: authorize()PR 3: CRUD processorsPR 4: SDK+CLI → PR 5 (this).
This diff is against jo/permission-crud-sdk-cli.

Summary of Changes

  • Wires authorize() into all existing instruction processors that require privileged access: accesspass/{close,set}, multicastgroup/subscribe, and user/{ban,closeaccount,create,create_subscribe,delete,requestban} — each processor now appends the caller's Permission PDA as an optional trailing account
  • Deletes processors/user/create_core.rs (328 lines) by absorbing its logic directly into create.rs, eliminating a layer of indirection that was only needed before the authorization refactor
  • Adds DZClient::build_and_send() helper in the Rust SDK that automatically checks for and appends the caller's Permission PDA as a trailing account when it exists on-chain, making permission account usage transparent to callers
  • Updates all affected Rust SDK commands (user, tenant, accesspass, permission) to use build_and_send() so they automatically include the Permission account
  • Updates the activator to pass the Permission account when issuing user-related instructions

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 12 +680 / -625 +55
SDK 14 +145 / -355 -210
Activator 1 +4 / -4 0
Tests 1 +9 / -281 -272
Config 1 +6 / -1 +5

Net code reduction overall — the authorization refactor removed more duplication than it added.

Key files (click to expand)
  • smartcontract/programs/doublezero-serviceability/src/processors/user/create.rs — absorbs create_core.rs, adds authorize() call; now the single source of truth for user creation
  • smartcontract/programs/doublezero-serviceability/src/processors/user/create_subscribe.rs — refactored to call authorize(), with account layout updated to accept optional trailing Permission PDA
  • smartcontract/sdk/rs/src/client.rs — new build_and_send() method: looks up caller's Permission PDA, appends it as a read-only trailing account if it exists, then signs and sends the transaction
  • smartcontract/programs/doublezero-serviceability/src/processors/multicastgroup/subscribe.rs — adds authorize() for ACCESS_PASS_ADMIN check; old inline allowlist check replaced
  • smartcontract/programs/doublezero-serviceability/src/processors/user/create_core.rs — deleted (328 lines); logic consolidated into create.rs
  • smartcontract/sdk/rs/src/commands/user/create_subscribe.rs — gutted (299 lines removed) as the user-creation logic it duplicated is now fully in the program processor
  • smartcontract/programs/doublezero-serviceability/src/processors/accesspass/close.rs — adds authorize() for ACCESS_PASS_ADMIN
  • smartcontract/sdk/rs/src/doublezeroclient.rs — adds get_permission_pda_for_payer() convenience method used by build_and_send()

Testing Verification

  • tests/create_subscribe_user_test.rs updated to reflect the simplified processor — existing passing tests confirm the create_core consolidation is behavior-preserving
  • tests/permission_test.rs (from PR 3) covers the authorize() enforcement paths invoked by these processors
  • make rust-test passes with all affected processors and SDK commands

@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-enforcement branch from fcc211f to cb87d98 Compare March 9, 2026 17:43
@juan-malbeclabs juan-malbeclabs changed the base branch from jo/permission-crud to jo/permission-crud-sdk-cli March 9, 2026 17:46
@juan-malbeclabs juan-malbeclabs changed the title smartcontract: enforce Permission-based authorization in existing instructions [New Permission 3/5] smartcontract: enforce Permission-based authorization in existing instructions Mar 9, 2026
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-crud-sdk-cli branch from 53175e4 to 7c2c64c Compare March 10, 2026 16:01
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-enforcement branch from cb87d98 to a6b59b4 Compare March 10, 2026 16:03
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-crud-sdk-cli branch from 7c2c64c to 5bdc49e Compare March 11, 2026 15:11
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-enforcement branch from a6b59b4 to cdf8668 Compare March 11, 2026 15:14
/// and post-activation subscription changes (add/remove toggle). The caller is
/// responsible for setting `user.status = Updating` when
/// `publisher_list_transitioned` is true and the user is already activated.
pub fn subscribe_user_to_multicastgroup(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this shared code? It's used by both mutlicast subscribe and create subscribe, so the subscribe logic is deduplicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please take another look. I rebased it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was fixed in the rebase. The subscribe_user_to_multicastgroup() helper is preserved, the branch no longer touches subscribe.rs at all, so the shared logic used by both MulticastGroupSubscribe and CreateSubscribeUser is intact.

@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-crud-sdk-cli branch from de2986e to 426ea94 Compare March 12, 2026 19:34
Base automatically changed from jo/permission-crud-sdk-cli to main March 12, 2026 19:47
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-enforcement branch from cdf8668 to e63b15f Compare March 12, 2026 20:21
@juan-malbeclabs juan-malbeclabs force-pushed the jo/permission-enforcement branch from e63b15f to 8bc4aee Compare March 13, 2026 13:18
- remove unused ResourceExtensionBorrowed import in closeaccount
- add missing dz_prefix_count field to UserCreateSubscribeArgs initializers in sdk, instructions test, and integration tests
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole file should have probably not been touched. All that is changed here is that it got rid of the onchain allocation tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this break Steven's fix for failed transactions due to races causing activator noise?

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this break Steven's fix for failed transactions due to races causing activator noise?

Copy link
Contributor

Choose a reason for hiding this comment

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

Onchain allocation support was removed from this file.

- Add execute_authorized_transaction_quiet to DoubleZeroClient trait and
  DZClient impl, restoring quiet mode for ban and closeaccount commands
  that was lost when switching to execute_authorized_transaction
- Restore onchain allocation support in CreateSubscribeUserCommand SDK
  command (feature-flag-gated ResourceExtension PDA logic removed in
  permission enforcement refactor)
- Restore atomic path tests and fixture resource extension PDA fields in
  create_subscribe_user_test.rs
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.

serviceability: Permission account model for scalable, granular access control

2 participants