Skip to content

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

Open
juan-malbeclabs wants to merge 1 commit intojo/permission-crud-sdk-clifrom
jo/permission-enforcement
Open

[New Permission 3/5] smartcontract: enforce Permission-based authorization in existing instructions#3206
juan-malbeclabs wants to merge 1 commit intojo/permission-crud-sdk-clifrom
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
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.

1 participant