Skip to content

feat: add BTCPay API key lockdown plugin - #5

Open
okjodom wants to merge 1 commit into
mainfrom
okjodom/btcpay-api-key-lockdown-plugin
Open

feat: add BTCPay API key lockdown plugin#5
okjodom wants to merge 1 commit into
mainfrom
okjodom/btcpay-api-key-lockdown-plugin

Conversation

@okjodom

@okjodom okjodom commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a second BTCPay Server plugin that restricts account API key and store access token management by server-configured roles
  • add a server settings page for selecting allowed roles and whether server admins bypass the restriction
  • update BTCPay plugin build, pack, and dev scripts to target named plugins and load both Minmo plugins in dev

We can avoid a plugin based lockdown should this issue be addressed in btcpayserver core btcpayserver/btcpayserver#7502

Before

image

After

image

Verification

  • git diff --cached --check
  • scripts/build-plugin.sh Minmo.BTCPayServer.ApiKeyLockdown.Plugin
  • scripts/pack-plugin.sh Minmo.BTCPayServer.ApiKeyLockdown.Plugin

@okjodom
okjodom requested review from a team, isaacknjama and nombumurage and a lite review from Copilot August 13, 2026 10:42
@okjodom
okjodom force-pushed the okjodom/btcpay-api-key-lockdown-plugin branch from 6ad5a23 to b5628a1 Compare August 13, 2026 10:43
@okjodom
okjodom requested review from TChukwuleta and removed request for isaacknjama and nombumurage August 13, 2026 10:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new BTCPay Server plugin (“API Key Lockdown”) to restrict API key/access-token management based on server-configured roles, and updates local build/pack/dev scripts to support targeting named plugins and loading both Minmo plugins during development.

Changes:

  • Added Minmo.BTCPayServer.ApiKeyLockdown.Plugin with settings UI, policy, and an MVC action filter to block restricted endpoints/flows.
  • Added locked/blocked UI views for disallowed users and a server settings page to configure allowed roles.
  • Updated plugin scripts (build-plugin.sh, pack-plugin.sh, dev-btcpay.sh) to accept/handle named plugins and load multiple plugins in dev.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
btcpayserver/scripts/pack-plugin.sh Parameterize packing to target a specified plugin name/directory.
btcpayserver/scripts/dev-btcpay.sh Build and load both Minmo plugins in BTCPay debug runs.
btcpayserver/scripts/build-plugin.sh Parameterize build to target a specified plugin project.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/README.md Documents plugin purpose, restricted endpoints, and dev commands.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Plugins/MinmoApiKeyLockdown/Views/NavExtension.cshtml Adds server-nav entry to reach the plugin settings page.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Plugins/MinmoApiKeyLockdown/Views/Configure.cshtml Server settings UI for enabling lockdown and selecting allowed roles.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Plugins/MinmoApiKeyLockdown/Views/ApiKeysLocked.cshtml Locked UI for account API keys when disallowed.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Plugins/MinmoApiKeyLockdown/Views/AccessTokensLocked.cshtml Locked UI for store access tokens when disallowed.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Plugins/MinmoApiKeyLockdown/Views/_ViewImports.cshtml Razor imports/injections for the plugin views.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Models/MinmoApiKeyLockdownViewModel.cs View model for settings page (enabled flag, allowed roles list).
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/MinmoApiKeyLockdownSettings.cs Persisted settings model for role restrictions.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/MinmoApiKeyLockdownPolicy.cs Computes whether a user is allowed under configured role rules.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/MinmoApiKeyLockdownPlugin.cs Plugin registration (UI extension, settings accessor, filter).
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/MinmoApiKeyLockdownFilter.cs Global MVC action filter enforcing the lockdown behavior.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Minmo.BTCPayServer.ApiKeyLockdown.Plugin.csproj New plugin project definition targeting net10.0.
btcpayserver/Minmo.BTCPayServer.ApiKeyLockdown.Plugin/Controllers/UIMinmoApiKeyLockdownController.cs Server-settings controller to view/update plugin settings.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +56 to +60
TempData.SetStatusMessageModel(new StatusMessageModel
{
Severity = StatusMessageModel.StatusSeverity.Success,
Message = "Greenfield API key policy saved"
});
Comment on lines +66 to +70
var stores = await _storeRepository.GetStoresByUserId(userId);
return stores
.SelectMany(store => store.UserStores)
.Where(userStore => userStore.ApplicationUserId == userId)
.Any(userStore => allowedRoleIds.Contains(userStore.StoreRoleId, StringComparer.OrdinalIgnoreCase));
Comment on lines +13 to +15
<div class="alert alert-warning" role="alert" text-translate="true">
API key management is disabled for your role on this BTCPay Server instance.
</div>
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.

2 participants