import React, { SyntheticEvent, useState } from 'react'; import { DataSourcePluginOptionsEditorProps, onUpdateDatasourceJsonDataOption, onUpdateDatasourceSecureJsonDataOption, SelectableValue, updateDatasourcePluginJsonDataOption, updateDatasourcePluginResetOption, } from '@grafana/data'; import { ConfigSection, ConfigSubSection, DataSourceDescription, Stack } from '@grafana/experimental'; import { config } from '@grafana/runtime'; import { ConnectionLimits, Divider, TLSSecretsConfig, useMigrateDatabaseFields } from '@grafana/sql'; import { Input, Select, SecretInput, Field, Tooltip, Label, Icon, Switch, SecureSocksProxySettings, Collapse, } from '@grafana/ui'; import { PostgresOptions, PostgresTLSMethods, PostgresTLSModes, SecureJsonData } from '../types'; import { useAutoDetectFeatures } from './useAutoDetectFeatures'; export const postgresVersions: Array> = [ { label: '9.0', value: 900 }, { label: '9.1', value: 901 }, { label: '9.2', value: 902 }, { label: '9.3', value: 903 }, { label: '9.4', value: 904 }, { label: '9.5', value: 905 }, { label: '9.6', value: 906 }, { label: '10', value: 1000 }, { label: '11', value: 1100 }, { label: '12', value: 1200 }, { label: '13', value: 1300 }, { label: '14', value: 1400 }, { label: '15', value: 1500 }, ]; export const PostgresConfigEditor = (props: DataSourcePluginOptionsEditorProps) => { const [versionOptions, setVersionOptions] = useState(postgresVersions); const [isOpen, setIsOpen] = useState(true); useAutoDetectFeatures({ props, setVersionOptions }); useMigrateDatabaseFields(props); const { options, onOptionsChange } = props; const jsonData = options.jsonData; const onResetPassword = () => { updateDatasourcePluginResetOption(props, 'password'); }; const tlsModes: Array> = [ { value: PostgresTLSModes.disable, label: 'disable' }, { value: PostgresTLSModes.require, label: 'require' }, { value: PostgresTLSModes.verifyCA, label: 'verify-ca' }, { value: PostgresTLSModes.verifyFull, label: 'verify-full' }, ]; const tlsMethods: Array> = [ { value: PostgresTLSMethods.filePath, label: 'File system path' }, { value: PostgresTLSMethods.fileContent, label: 'Certificate content' }, ]; const onJSONDataOptionSelected = (property: keyof PostgresOptions) => { return (value: SelectableValue) => { updateDatasourcePluginJsonDataOption(props, property, value.value); }; }; const onTimeScaleDBChanged = (event: SyntheticEvent) => { updateDatasourcePluginJsonDataOption(props, 'timescaledb', event.currentTarget.checked); }; const onDSOptionChanged = (property: keyof PostgresOptions) => { return (event: SyntheticEvent) => { onOptionsChange({ ...options, ...{ [property]: event.currentTarget.value } }); }; }; const WIDTH_LONG = 40; return ( <> setIsOpen((x) => !x)}> The database user should only be granted SELECT permissions on the specified database & tables you want to query.
Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements like DELETE FROM user; and DROP TABLE user; would be executed.
To protect against this we Highly recommend you create a specific PostgreSQL user with restricted permissions. Check out the docs for more information.
TLS/SSL Mode This option determines whether or with what priority a secure TLS/SSL TCP/IP connection will be negotiated with the server } > } > ) : null} {jsonData.sslmode !== PostgresTLSModes.disable ? ( <> {jsonData.tlsConfigurationMethod === PostgresTLSMethods.fileContent ? ( ) : ( <> TLS/SSL Root Certificate If the selected TLS/SSL mode requires a server root certificate, provide the path to the file here. } > } > TLS/SSL Client Certificate To authenticate with an TLS/SSL client certificate, provide the path to the file here. Be sure that the file is readable by the user executing the grafana process. } > } > TLS/SSL Client Key To authenticate with a client TLS/SSL certificate, provide the path to the corresponding key file here. Be sure that the file is only readable by the user executing the grafana process. } > } > )} ) : null} Version This option controls what functions are available in the PostgreSQL query builder } > } > TimescaleDB TimescaleDB is a time-series database built as a PostgreSQL extension. If enabled, Grafana will use time_bucket in the $__timeGroup macro and display TimescaleDB specific aggregate functions in the query builder. } > } > {config.secureSocksDSProxyEnabled && ( )} ); };