From b213ecc2dd15330119912330420d56f7b8179baa Mon Sep 17 00:00:00 2001 From: linoman <2051016+linoman@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:19:45 +0200 Subject: [PATCH] SSO LDAP: Add configuration for root ca, client key and client certificate (#92866) * Add missing properties with `_value` prefix * Add RadioButtonGrpoup * Add file/value section for certs * Add mapping for keys and certificates * Rename base and file types * Add styles * Add base64 values configuration flags * Add function to render root ca certificate contents * generate i18n files --- public/app/features/admin/ldap/LdapDrawer.tsx | 274 ++++++++++++++---- .../features/admin/ldap/LdapSettingsPage.tsx | 34 ++- public/app/types/ldap.ts | 12 + public/locales/en-US/grafana.json | 105 +++---- public/locales/pseudo-LOCALE/grafana.json | 105 +++---- 5 files changed, 352 insertions(+), 178 deletions(-) diff --git a/public/app/features/admin/ldap/LdapDrawer.tsx b/public/app/features/admin/ldap/LdapDrawer.tsx index eec47a0100d..53e1eb6a96f 100644 --- a/public/app/features/admin/ldap/LdapDrawer.tsx +++ b/public/app/features/admin/ldap/LdapDrawer.tsx @@ -1,5 +1,5 @@ import { css } from '@emotion/css'; -import { useId } from 'react'; +import { Dispatch, SetStateAction, useEffect, useId, useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; @@ -12,25 +12,41 @@ import { Icon, Input, Label, + MultiSelect, Select, Stack, Switch, Text, TextLink, Tooltip, + RadioButtonGroup, + SecretInput, } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; -import { LdapPayload } from 'app/types'; +import { LdapPayload, MapKeyCertConfigured } from 'app/types'; interface Props { onClose: () => void; + mapKeyCertConfigured: MapKeyCertConfigured; + setMapKeyCertConfigured: Dispatch>; } +const serverConfig = 'settings.config.servers.0'; const tlsOptions: Array> = ['TLS1.2', 'TLS1.3'].map((v) => ({ label: v, value: v })); +enum EncryptionProvider { + Base64 = 'base64', + FilePath = 'path', +} + +export const LdapDrawerComponent = ({ + onClose, + mapKeyCertConfigured: mapCertConfigured, + setMapKeyCertConfigured: setMapCertConfigured, +}: Props) => { + const [encryptionProvider, setEncryptionProvider] = useState(EncryptionProvider.Base64); -export const LdapDrawerComponent = ({ onClose }: Props) => { const styles = useStyles2(getStyles); - const { register, setValue, watch } = useFormContext(); + const { getValues, register, setValue, watch } = useFormContext(); const nameId = useId(); const surnameId = useId(); @@ -38,6 +54,22 @@ export const LdapDrawerComponent = ({ onClose }: Props) => { const memberOfId = useId(); const emailId = useId(); + useEffect(() => { + const { client_cert, client_key, root_ca_cert } = getValues(serverConfig); + setEncryptionProvider( + !client_cert.length && !client_key.length && !root_ca_cert?.length + ? EncryptionProvider.Base64 + : EncryptionProvider.FilePath + ); + }, [getValues]); + + const renderMultiSelectLabel = (value: string) => { + if (value.length >= 5) { + return `${value.slice(0, 2)}...${value.slice(-2)}`; + } + return value; + }; + const groupMappingsLabel = (