Skip to content

feat: add semgrep rules for marketplace licensing - #1053

Open
xnyo wants to merge 2 commits into
mainfrom
giuseppe/marketplace-licensing-call
Open

xnyo wants to merge 2 commits into
mainfrom
giuseppe/marketplace-licensing-call

Conversation

@xnyo

@xnyo xnyo commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Changes

  • Extends the coderules analyzer (semgrep) to include marketplace licensing checks
  • Add a way to disable specific semgrep rules by default

The new semgrep rules checks if a plugin contains marketplace licensing:

if err := datasource.Manage("grafana-marketplacetest-datasource", plugin.NewDatasource, datasource.ManageOpts{
    Licensing: marketplace.Licensing(marketplace.Opts{}),  // <--- this
}); err != nil {
    log.DefaultLogger.Error(err.Error())
    os.Exit(1)
}

or (for apps)

if err := app.Manage("grafana-marketplacetest-datasource", plugin.NewDatasource, app.ManageOpts{
    Licensing: marketplace.Licensing(marketplace.Opts{}),  // <--- this
}); err != nil {
    log.DefaultLogger.Error(err.Error())
    os.Exit(1)
}

or (nested plugins)

if err := app.Manage("grafana-marketplacetest-app", plugin.NewDatasource, app.ManageOpts{
    Licensing: marketplace.Licensing(marketplace.Opts{        // <--]
        ParentPluginID: "grafana-marketplacetest-datasource"  // <--]-- this
    }),                                                       // <--]
}); err != nil {
	log.DefaultLogger.Error(err.Error())
	os.Exit(1)
}

The new semgrep rules checks imports for both github.com/grafana/grafana-plugin-sdk-go/experimental/marketplace (current package) AND github.com/grafana/grafana-plugin-sdk-go/marketplace: the Go marketplace package will be moved out of experimental soon, and adding both paths will not require us to update the validator when we move marketplace pkg out of experimental pkg

These are disabled by default, they have to run only for marketplace plugins. Non-marketplace plugins will fail this check, and there's no way to fix it: it's a marketplace-specific thing.

To support this, the PR adds a system to disable specific semgrep rules via semgrep metadata field, which is part of its supported schema and can contain arbitrary data attached to the rule that's consumed by whoever runs semgrep:

In the semgrep rules yaml file, a rule can contain:

rules:
  - id: xyz
    metadata: # <-- new field
      plugin-validator:
        disabled-by-default: true
    message: don't do this
    patterns:
        - ...

Then, the rule can be enabled via the validator config:

analyzers:
  code-rules:
    rules:
      code-rules-require-marketplace-licensing:
        enabled: true
        severity: error

Note: disabled rules are still evaluated, but their output is filtered out, which is the same behavior when disabling them via config (when they are enabled by default).

@xnyo xnyo self-assigned this Oct 21, 2026
@xnyo xnyo added the enhancement New feature or request label Oct 21, 2026
@xnyo
xnyo added this pull request to stack #1054 October 21, 2026 15:30
@xnyo xnyo moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Oct 21, 2026
@xnyo
xnyo force-pushed the giuseppe/marketplace-licensing-call branch from 562fffb to 1278790 Compare October 21, 2026 15:40
Comment thread pkg/analysis/passes/requiredlinks/requiredlinks.go Outdated
@xnyo
xnyo marked this pull request as ready for review October 21, 2026 16:45
@xnyo
xnyo requested a review from a team as a code owner October 21, 2026 16:45
@xnyo
xnyo requested review from academo, mckn, oshirohugo, s4kh and toddtreece and removed request for a team October 21, 2026 16:45
@s4kh

s4kh commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Somewhat related to #999 - this checks for links from the plugin.json.

Comment thread pkg/analysis/passes/marketplacelicensing/marketplacelicensing.go Outdated
Comment thread pkg/analysis/passes/marketplacelicensing/marketplacelicensing.go Outdated
Comment thread pkg/analysis/passes/marketplacelicensing/marketplacelicensing.go Outdated

@academo academo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I generally don't like the idea of having marketplace-specific validator and I wonder if you can consider making this a more generic validator. like "sdk function calls" validator where we can define different rules that define specific symbols we want to find inside the binaries and these marketplace licensing ones being one of them.

@xnyo

xnyo commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

I did more research and it looks like we can use semgrep for this, without a new analyzer. It won't cover any case but it should still be reliable and won't introduce marketplace-specific analyzer. I'll see how it looks like and rework this PR accordingly

@xnyo
xnyo marked this pull request as draft October 22, 2026 12:10
@xnyo
xnyo force-pushed the giuseppe/marketplace-licensing-call branch from 3ff97df to 470a55f Compare October 22, 2026 12:34
@xnyo xnyo changed the title feat: add marketplacelicensing analyzer feat: add semgrep rules for marketplace licensing Oct 22, 2026
Base automatically changed from giuseppe/detect-marketplace-dev-mode-new to main October 22, 2026 14:30
@xnyo
xnyo force-pushed the giuseppe/marketplace-licensing-call branch from 470a55f to 6bde13d Compare October 22, 2026 14:33
@xnyo xnyo moved this from 🔬 In review to 🧑‍💻 In development in Grafana Catalog Team Oct 22, 2026
@xnyo
xnyo marked this pull request as ready for review October 23, 2026 13:14
@xnyo

xnyo commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Removed the dedicated analyzer and reworked to use semgrep instead. PR description has been updated with more details. PTAL.

@xnyo
xnyo requested a review from academo October 23, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 🧑‍💻 In development

Development

Successfully merging this pull request may close these issues.

3 participants