PluginDetailsSignature.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { PluginErrorCode, PluginSignatureStatus } from '@grafana/data';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { Alert } from '@grafana/ui';
  5. import { CatalogPlugin } from '../types';
  6. type Props = {
  7. className?: string;
  8. plugin: CatalogPlugin;
  9. };
  10. // Designed to show signature information inside the active tab on the plugin's details page
  11. export function PluginDetailsSignature({ className, plugin }: Props): React.ReactElement | null {
  12. const isSignatureValid = plugin.signature === PluginSignatureStatus.valid;
  13. const isCore = plugin.signature === PluginSignatureStatus.internal;
  14. const isDisabled = plugin.isDisabled && isDisabledDueTooSignatureError(plugin.error);
  15. // The basic information is already available in the header
  16. if (isSignatureValid || isCore || isDisabled) {
  17. return null;
  18. }
  19. return (
  20. <Alert
  21. severity="warning"
  22. title="Invalid plugin signature"
  23. aria-label={selectors.pages.PluginPage.signatureInfo}
  24. className={className}
  25. >
  26. <p>
  27. Grafana Labs checks each plugin to verify that it has a valid digital signature. Plugin signature verification
  28. is part of our security measures to ensure plugins are safe and trustworthy. Grafana Labs can’t guarantee the
  29. integrity of this unsigned plugin. Ask the plugin author to request it to be signed.
  30. </p>
  31. <a
  32. href="https://grafana.com/docs/grafana/latest/plugins/plugin-signatures/"
  33. className="external-link"
  34. target="_blank"
  35. rel="noreferrer"
  36. >
  37. Read more about plugins signing.
  38. </a>
  39. </Alert>
  40. );
  41. }
  42. function isDisabledDueTooSignatureError(error: PluginErrorCode | undefined) {
  43. // If the plugin is disabled due to signature error we rely on the disabled
  44. // error message instad of the warning about the signature.
  45. switch (error) {
  46. case PluginErrorCode.invalidSignature:
  47. case PluginErrorCode.missingSignature:
  48. case PluginErrorCode.modifiedSignature:
  49. return true;
  50. default:
  51. return false;
  52. }
  53. }