Skip to content

Conversation

@christos-diamantis
Copy link
Contributor

This PR introduces per-user authentication to the Grafana Zabbix datasource plugin. When enabled, Grafana users are mapped to corresponding Zabbix users, and all API requests are performed using the permissions of the mapped Zabbix user. This allows organizations to fully leverage Zabbix RBAC and audit capabilities directly from Grafana.

Key Features

  • Per-User Authentication Toggle:
    New option in the datasource config to enable/disable per-user authentication.
  • Identity Field Selection:
    Admins can choose whether to map users by Grafana username or email.
  • Automatic Zabbix Token Management:
    The plugin will generate and use Zabbix API tokens for each user session, ensuring secure and isolated access.
  • Graceful Error Handling:
    If a Grafana user does not exist in Zabbix, a clear error is shown and access is denied.
  • Backward Compatibility:
    When per-user authentication is disabled, the plugin continues to use the global Zabbix credentials as before.

How It Works

  1. When per-user authentication is enabled, each Grafana request extracts the current user’s identity (username or email).
  2. The plugin queries Zabbix for a matching user.
  3. If found, a Zabbix API token is generated and used for all API calls in that session.
  4. If not found, the user is denied access with a clear error message.

Configuration

  • Enable Per-user authentication in the datasource settings.
  • Select the identity field (username or email) for user mapping.
  • Ensure each Grafana user has a corresponding Zabbix user.

Testing

  • Integration and unit tests have been added to cover the new authentication flow.
  • The devenv bootstrap script now creates a test user for integration testing.

Documentation

The README and in-app tooltips have been updated to explain the new feature and its requirements.

Feel free to test thoroughly and propose or do any changes if needed.

Closes #2016

@christos-diamantis christos-diamantis requested a review from a team as a code owner August 3, 2025 08:40
@zoltanbedi
Copy link
Member

@christos-diamantis thanks for your PR. I'll take a look at it shortly.

@zoltanbedi zoltanbedi self-assigned this Aug 8, 2025
@zoltanbedi zoltanbedi moved this to Backlog in OSS Big Tent Aug 8, 2025
@christos-diamantis
Copy link
Contributor Author

Did a quick review:

  • Currently implemented the method only on "QueryData". Need to implement it on all methods that the frontend is using
  • I think that currently a new token is generated every time the method is called (QueryData only now). Need to offload the token generation to be happening only once per session.

@CLAassistant
Copy link

CLAassistant commented Sep 26, 2025

CLA assistant check
All committers have signed the CLA.

@christos-diamantis
Copy link
Contributor Author

Implemented a helper flow that runs when per user auth is enabled.
added also methods to cache the tokens and not generate them each time.
applied the method to all the methods (QueryData, ZabbixAPIHandler, DBConnectionPostProcessingHandler)
debug and logging enhanced to be meaningful.

Feel free to test thoroughly and propose or do any changes if needed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Enable per-user authentication in Zabbix plugin based on Grafana user identity

3 participants