# Distribuera Key Connector

Den här artikeln kommer att leda dig genom proceduren för att aktivera och konfigurera Key Connector i en befintlig miljö med egen värd. **Innan du fortsätter** bör du noggrant läsa igenom artikeln [om Key Connector](https://bitwarden.com/sv-se/help/about-key-connector/) för att säkerställa en fullständig förståelse av vad Key Connector är, hur det fungerar och konsekvenserna av implementeringen.

Bitwarden stöder distribution av en nyckelanslutare för användning av en organisation för en självvärd instans.

## Krav

> [!NOTE]
> Management of cryptographic keys is incredibly sensitive and is **only recommended for enterprises with a team and infrastructure** that can securely support deploying and managing a key server.

För att använda Key Connector måste du:

- [Har en företagsorganisation](https://bitwarden.com/sv-se/help/password-manager-plans/#enterprise-organizations/).
- [Har en Bitwarden-server som](https://bitwarden.com/sv-se/help/install-on-premise-linux/) är självvärd.
- [Ha en aktiv SSO-implementering.](https://bitwarden.com/sv-se/help/about-sso/)
- [Aktivera policyerna](https://bitwarden.com/sv-se/help/policies/) för singelorganisation och Kräv enkel inloggning.

Om din organisation uppfyller eller kan uppfylla dessa krav, inklusive ett team och infrastruktur som kan stödja hantering av en nyckelserver, [kontakta oss](https://bitwarden.com/sv-se/contact/) så aktiverar vi Key Connector.

## Konfigurera och distribuera Key Connector

**När du har kontaktat oss angående Key Connector** kommer vi att kontakta oss för att starta en Key Connector-diskussion. Stegen som följer i den här artikeln måste slutföras i samarbete med Bitwardens kundframgångs- och implementeringsspecialister.

### Skaffa ny licensfil

När du har kontaktat oss angående Key Connector kommer en medlem av kundframgångs- och implementeringsteamet att generera en Key Connector-aktiverad licensfil för din organisation. När din Bitwarden-samarbetspartner instruerar dig att den är klar, slutför du följande steg för att få den nya licensen:

1. Öppna Bitwardens molnwebbapp och navigera till din organisations skärm **Fakturering** → **Prenumeration** i administratörskonsolen.
2. Rulla ned och välj knappen **Ladda ner licens**.
3. När du uppmanas, ange installations-ID som användes för att installera din egen värdserver och välj **Skicka**. Om du inte känner till ditt installations-ID direkt kan du hämta det från` ./bwdata/env/global.override.env`.

Du behöver inte din licensfil omedelbart, men du kommer att behöva ladda upp den till din egen värdserver [i ett senare steg](https://bitwarden.com/sv-se/help/deploy-key-connector/#activate-key-connector/).

### Initiera Key Connector

Så här förbereder du din Bitwarden-server för Key Connector:

1. Spara en [säkerhetskopia](https://bitwarden.com/sv-se/help/backup-on-premise/) av, åtminstone, .`bwdata/mssql`. När Key Connector väl har använts, rekommenderas det att du har tillgång till en pre-Key Connector backupbild i händelse av problem.

> [!NOTE] Using external MSSQL
> If you are using an [external MSSQL database](https://bitwarden.com/sv-se/help/external-db/), take a backup of your database in whatever way fits your implementation.
2. Uppdatera din självvärdade Bitwarden-installation för att hämta de senaste ändringarna:

```
./bitwarden.sh update
```
3. Redigera filen `.bwdata/config.yml` och aktivera Key Connector genom att växla `enable_key_connector` till `true`.

```
nano bwdata/config.yml
```
4. Bygg om din självvärdade Bitwarden-installation:

```
./bitwarden.sh rebuild
```
5. Uppdatera din självvärdade Bitwarden-installation igen för att tillämpa ändringarna:

```
./bitwarden.sh update
```

### Konfigurera Key Connector

För att konfigurera Key Connector:

1. Redigera filen `.bwdata/env/key-connector.override.env` som kommer att ha laddats ner med ./`bitwarden.sh-uppdateringen`.

```
nano bwdata/env/key-connector.override.env
```

> [!NOTE]
> This file will be pre-populated with default values that will spin up a functional local Key Connector setup, however the **default values are not recommended for production environments**.
2. I `key-connector.override.env` måste du ange värden för följande:

 - [Endpoints](https://bitwarden.com/sv-se/help/deploy-key-connector/#endpoints/): Vilka Bitwarden endpoints Key Connector kan kommunicera med.
 - [Databas](https://bitwarden.com/sv-se/help/deploy-key-connector/#database/): Där Key Connector lagrar och hämtar användarnycklar.
 - [RSA-nyckelpar](https://bitwarden.com/sv-se/help/deploy-key-connector/#rsa-key/): Hur Key Connector kommer åt ett RSA-nyckelpar för att skydda användarnycklar i vila.

#### Slutpunkter

Automatisk installation kommer att fylla i slutpunktsvärden baserat på din installationskonfiguration, men det rekommenderas att du bekräftar att följande värden i `key-connector.override.env` är korrekta för din installation:

```
keyConnectorSettings__webVaultUri=https://your.bitwarden.domain.com
keyConnectorSettings__identityServerUri=http://identity:5000
```

#### Databas

Key Connector måste komma åt en databas som lagrar krypterade användarnycklar för dina organisationsmedlemmar. Skapa en säker databas för att lagra krypterade användarnycklar och ersätt standardvärdena för `keyConnectorSettings__database`__ i `key-connector.override.env` med värdena som anges i **kolumnen**Required Values för den valda databasen:

> [!NOTE]
> Migration from one database to another is **not supported** at this time. Regardless of which provider you choose, **implement a frequent automated backup schedule** for the database.

| **Databas** | **Obligatoriska värden** |
|------|------|
| Lokal JSON (**standard**) | **Rekommenderas inte utanför testet.** `keyConnectorSettings__database__provider=json` `keyConnectorSettings__database__jsonFilePath={File_Path}` |
| Microsoft SQL Server | `keyConnectorSettings__database__provider=sqlserver` `keyConnectorSettings__database__sqlServerConnectionString={Connection_String}` [Lär dig hur du formaterar MSSQL-anslutningssträngar](https://docs.microsoft.com/en-us/sql/connect/ado-net/connection-string-syntax?view=sql-server-ver15) |
| PostgreSQL | `keyConnectorSettings__database__provider=postgresql` `keyConnectorSettings__database__postgreSqlConnectionString={Connection_String}` [Lär dig hur du formaterar PostgreSQL-anslutningssträngar](https://www.npgsql.org/doc/connection-string-parameters.html) |
| MySQL/MariaDB | `keyConnectorSettings__database__provider=mysql` `keyConnectorSettings__database__mySqlConnectionString={Connection_String}` [Lär dig hur du formaterar MySQL-anslutningssträngar](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) |
| MongoDB | `keyConnectorSettings__database__provider=mongo` `keyConnectorSettings__database__mongoConnectionString={Connection_String}` `keyConnectorSettings__database__mongoDatabaseName={DatabaseName}` [Lär dig hur du formaterar MongoDB-anslutningssträngar](https://docs.mongodb.com/manual/reference/connection-string/) |

#### RSA-nyckelpar

Key Connector använder ett RSA-nyckelpar för att skydda användarnycklar i vila. Skapa ett nyckelpar och ersätt standardvärdena `keyConnectorSettings__rsaKey`__ och `keyConnectorSettings__certificate`__ i `key-connector.override.env` med de värden som krävs för din valda implementering.

> [!NOTE]
> The RSA key pair must be **at a minimum** 2048 bits in length.

I allmänhet inkluderar dina alternativ att ge Key Connector-åtkomst till ett **X509-certifikat** som innehåller nyckelparet eller att ge **Key Connector-åtkomst direkt till nyckelparet**. Key Connector stöder inte rotation av certifikat eller RSA-nyckelpar.

### Certificate

To use an X509 certificate that contains an RSA key pair, specify the values required depending on the location where your certificate is stored (see **Filesystem**, **OS Certificate Store**, and so on):

> [!NOTE]
> The certificate **must** be made available as a PKCS12 `.pfx` file, for example:
> 
> 
> ```
> openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout bwkc.key -out bwkc.crt -subj "/CN=Bitwarden Key Connector" -days 36500
> 
> openssl pkcs12 -export -out ./bwkc.pfx -inkey bwkc.key -in bwkc.crt -passout pass:{Password}
> ```
> 
> In all certificate implementations, you'll need the `CN` value shown in this example.

#### Filesystem (default)

If the certificate is stored on the filesystem of the machine running Key Connector, specify the following values:

> [!NOTE]
> By default, Key Connector will be configured to create a `.pfx` file located at `etc/bitwarden/key-connector/bwkc.pfx` with a generated password. **It is not recommended** for enterprise implementations to use these defaults.

```
keyConnectorSettings__rsaKey__provider=certificate
keyConnectorSettings__certificate__provider=filesystem
keyConnectorSettings__certificate__filesystemPath={Certificate_Path}
keyConnectorSettings__certificate__filesystemPassword={Certificate_Password}
```

#### Azure Blob Storage

If the certificate is uploaded to Azure Blob Storage, specify the following values:

```
keyConnectorSettings__rsaKey__provider=certificate
keyConnectorSettings__certificate__provider=azurestorage
keyConnectorSettings__certificate__azureStorageConnectionString={Connection_String}
keyConnectorSettings__certificate__azureStorageContainer={Container_Name}
keyConnectorSettings__certificate__azureStorageFileName={File_Name}
keyConnectorSettings__certificate__azureStorageFilePassword={File_Password}
```

Set `azureStorageConnectionString` to a **Connection string**you can generate in your Azure portal from the **Shared access signature** (SAS) page of your storage account. The SAS must have:

- Allowed services: Blob and File
- Allowed resource types: Service, Container, and Object
- Allowed permissions: Read, Write, and List
- Allowed blob index permissions: Read/Write and Filter

#### Azure Key Vault

If certificate is stored in Azure Key Vault, specify the following values:

> [!NOTE]
> To use Azure Key Vault to store your `.pfx` certificate, you'll need to create an Active Directory **App Registration**. This App Registration must:
> 
> - Give delegated API permissions to access Azure Key Vault
> - Have a client secret generated to allow access by Key Connector

```
keyConnectorSettings__certificate__provider=azurekv
keyConnectorSettings__certificate__azureKeyvaultUri={Vault_URI}
keyConnectorSettings__certificate__azureKeyvaultCertificateName={Certificate_Name}
keyConnectorSettings__certificate__azureKeyvaultAdTenantId={ActiveDirectory_TenantId}
keyConnectorSettings__certificate__azureKeyvaultAdAppId={AppRegistration_ApplicationId}
keyConnectorSettings__certificate__azureKeyvaultAdSecret={AppRegistration_ClientSecretValue}
```

#### Hashicorp Vault

If the certificate is stored in Hashicorp Vault, specify the following values:

> [!NOTE]
> Key Connector integrates with the Hashicorp Vault KV2 Storage Engine. As per the top of this tab, the certificate file should be in PKCS12 format and stored base64-encoded as the value to a named key in your Vault. If following a Vault tutorial for the KV2 Storage Engine, the key name may be `file` unless otherwise specified.

```
keyConnectorSettings__rsaKey__provider=certificate
keyConnectorSettings__certificate__provider=vault
keyConnectorSettings__certificate__vaultServerUri={Server_URI}
keyConnectorSettings__certificate__vaultToken={Token}
keyConnectorSettings__certificate__vaultSecretMountPoint={Secret_MountPoint}
keyConnectorSettings__certificate__vaultSecretPath={Secret_Path}
keyConnectorSettings__certificate__vaultSecretDataKey={Secret_DataKey}
keyConnectorSettings__certificate__vaultSecretFilePassword={Secret_FilePassword}
```

### Cloud key pair

To use a cloud provider or physical device to store to a RSA 2048 key pair, specify the values required depending on your chosen implementation (see **Azure Key Vault**, **Google Cloud Key Management**, and so on):

#### Azure Key Vault

If you are using Azure Key Vault to store a RSA 2048 key pair, specify the following values:

> [!NOTE]
> To use Azure Key Vault to store your RSA 2048 key, you'll need to create an Active Directory **App Registration**. This App Registration must:
> 
> - Give delegated API permissions to access Azure Key Vault
> - Have a client secret generated to allow access by Key Connector

```
keyConnectorSettings__rsaKey__provider=azurekv
keyConnectorSettings__rsaKey__azureKeyvaultUri={Vault_URI}
keyConnectorSettings__rsaKey__azureKeyvaultKeyName={Key_Name}
keyConnectorSettings__rsaKey__azureKeyvaultAdTenantId={ActiveDirectory_TenantId}
keyConnectorSettings__rsaKey__azureKeyvaultAdAppId={AppRegistration_ApplicationId}
keyConnectorSettings__rsaKey__azureKeyvaultAdSecret={AppRegistration_ClientSecretValue}
```

[Learn how to use Azure Key Vault to create a key pair](https://docs.microsoft.com/en-us/azure/key-vault/keys/quick-create-portal)

#### Google Cloud Key Management

If you are using Google Cloud Key Management to store a RSA 2048 key pair, specify the following values:

```
keyConnectorSettings__rsaKey__provider=gcpkms
keyConnectorSettings__rsaKey__googleCloudProjectId={Project_Id}
keyConnectorSettings__rsaKey__googleCloudLocationId={Location_Id}
keyConnectorSettings__rsaKey__googleCloudKeyringId={Keyring_Id}
keyConnectorSettings__rsaKey__googleCloudKeyId={Key_Id}
keyConnectorSettings__rsaKey__googleCloudKeyVersionId={KeyVersionId}
```

[Learn how to use Google Cloud Key Management Service to create key rings and asymmetric keys](https://cloud.google.com/kms/docs/creating-asymmetric-keys)

#### AWS Key Management Service

If you are using AWS Key Management Service (KMS) to store a RSA 2048 key pair, specify the following values:

```
keyConnectorSettings__rsaKey__provider=awskms
keyConnectorSettings__rsaKey__awsAccessKeyId={AccessKey_Id}
keyConnectorSettings__rsaKey__awsAccessKeySecret={AccessKey_Secret}
keyConnectorSettings__rsaKey__awsRegion={Region_Name}
keyConnectorSettings__rsaKey__awsKeyId={Key_Id}
```

[Learn how to use AWS KMS to create asymmetric keys](https://docs.aws.amazon.com/kms/latest/developerguide/asymm-create-key.html)

### PKCS#11 HSM

If you are using a physical HSM device with the PKCS#11 provider to store a private key, you will need to:

1. Upload the corresponding public key, configured as a PEM-encoded certificate, to a location which can be accessed by the Key Connector container (see **Certificates** tab).
2. Configure Key Connector with the following values, which include *both* PKCS#11-specific values (e.g. `keyConnectorSettings__rsaKey__pkcs11...`) and values specific to the location you've chosen store your public key (e.g. k`eyConnectorSettings_certificate_...`):

```
keyConnectorSettings__rsaKey__provider=pkcs11
keyConnectorSettings__rsaKey__pkcs11Provider={Provider}
keyConnectorSettings__rsaKey__pkcs11SlotTokenSerialNumber={Token_SerialNumber}
keyConnectorSettings__rsaKey__pkcs11LoginUserType={Login_UserType}
keyConnectorSettings__rsaKey__pkcs11LoginPin={Login_PIN}

ONE OF THE FOLLOWING TWO:
keyConnectorSettings__rsaKey__pkcs11PrivateKeyLabel={PrivateKeyLabel}
keyConnectorSettings__rsaKey__pkcs11PrivateKeyId={PrivateKeyId}

OPTIONALLY:
keyConnectorSettings__rsaKey__pkcs11LibraryPath={path/to/library/file}
```

> [!TIP] Referencing local files for PKCS#11 Configuration
> Key Connector may need to access specific files, such as a local PEM certificate or PPKCS#11 driver files. By default, the directory `./bwdata/key-connector` is mounted into the container at `/etc/bitwarden/key-connector`, meaning that a certificate file stored in the host OS at `/opt/bitwarden/bwdata/key-connector/certificate.pem` is available to the container at `/etc/bitwarden/key-connector/certificate.pem`. Key Connector configurations **must** reference files in their mounted locations, as in the following example:
> 
> 
> ```plain text
> keyConnectorSettings__certificate__filesystemPath=/etc/bitwarden/key-connector/certificate.pem
> ```

**Required in all circumstances:**

- `keyConnectorSettings__rsaKey__provider=`: Must be `pkcs11`.
- `keyConnectorSettings__rsaKey__pkcs11Provider=`: Must be `yubihsm` or `opensc`.
- `keyConnectorSettings__rsaKey__pkcs11SlotTokenSerialNumber=`: Serial number used to identify the token to be used.
- `keyConnectorSettings__rsaKey__pkcs11LoginUserType=`: Can be `user`, `so`, or `context_specific`.
- `keyConnectorSettings__rsaKey__pkcs11LoginPin=`: PIN code used to access the token.
- `keyConnectorSettings__certificate__provider=`: Can be `filesystem`, `azurestorage`, `azurekv`, or `vault`.

**Required in some circumstances**:

- `keyConnectorSettings__rsaKey__pkcs11PrivateKeyLabel=`: (Required if not using `...__pkcsPrivateKeyId=`, see below) Label, or "alias", of your privatekey.
- `keyConnectorSettings__rsaKey__pkcs11PrivateKeyId=`: (Required if not using `...__pkcs11PrivateKeyLabel=`) Unique identifier of your private key.
- `keyConnectorSettings__certificate__filesystem...=`: Set both `...__certificate__filesystem...` values if you store your public key on a file system (see **Certificates** tab).
- `keyConnectorSettings__certificate__azure...=`: Set all `...__certificate__azure...` values if you store your public key in Azure Blob Storage (see **Certificates** tab).
- `keyConnectorSettings__certificate__azureKeyvault...=`: Set all `...__certificate__azureKeyvault...` values if you store your public key in Azure Key Vault (see **Certificates** tab).
- `keyConnectorSettings__certificate__vault...=`: Set all `...__certificate__vault...` values if you store your public key in Hashicorp Vault (see **Certificates** tab).

**Optional**:

- `keyConnectorSettings__rsaKey__pkcs11LibraryPath=`: Optionally, point Key Connector to a library file, for example `=/etc/bitwarden/libfxpkcs11.so`. Doing so will supersede the value `keyConnectorSettings__rsaKey__pkcs11Provider=`.

### Säkring av nyckelkontakt

Ytterligare säkerhetsåtgärder för Key Connector-användare rekommenderas för att upprätthålla noll-kunskapskryptering för databaser och dataöverföringar.

- Organisationer som använder en TLS-uppfångande proxy kommer att behöva vidta ytterligare åtgärder för att upprätthålla noll-kunskapskryptering. För att säkerställa säkerhet, lägg till Bitwarden-URL:n till din proxys undantagslista, detta kommer att säkerställa att dataöverföringen med Key Connector förblir krypterad och ologgad under hela dataöverföringsprocessen.
- Det är inte alltid möjligt att migrera mellan krypteringsmekanismer.
- Migrering från en databas till en annan stöds inte för närvarande. Se till att implementera ett ofta automatiskt säkerhetskopieringsschema för databasen.

> [!NOTE]
> Management of cryptographic keys is incredibly sensitive and is **only recommended for enterprises with a team and infrastructure** that can securely support deploying and managing a key server.

### Aktivera Key Connector

Nu när Key Connector är [helt konfigurerad](https://bitwarden.com/sv-se/help/deploy-key-connector/#configure-key-connector/) och du har en [Key Connector-aktiverad licens](https://bitwarden.com/sv-se/help/deploy-key-connector/#obtain-a-new-license/), slutför du följande steg:

1. Starta om din självvärdade Bitwarden-installation för att tillämpa konfigurationsändringarna:

```
./bitwarden.sh restart
```
2. Logga in på din egen värd**Bitwarden som organisationsägare** och navigera till administratörskonsolens **Fakturering** → **Prenumerationsskärm**.
3. Välj knappen **Uppdatera licens** och ladda upp den Key Connector-aktiverade licensen [hämtad i ett tidigare steg](https://bitwarden.com/sv-se/help/deploy-key-connector/#obtain-new-license-file/).
4. Om du inte redan har gjort det navigerar du till skärmen **Inställningar**→ Principer[ och aktiverar **policyerna** ](https://bitwarden.com/sv-se/help/policies/#require-single-sign-on-authentication/)[Enskild organisation](https://bitwarden.com/sv-se/help/policies/#single-organization/) och Kräv enkel inloggning. **Båda krävs för att använda Key Connector**.
5. Navigera till skärmen **Inställningar**→ **Enkel inloggning**.

> [!NOTE]
> The next few steps assume that you already have an active [login with SSO](https://bitwarden.com/sv-se/help/about-sso/) implementation using [SAML 2.0](https://bitwarden.com/sv-se/help/configure-sso-saml/) or [OIDC](https://bitwarden.com/sv-se/help/configure-sso-oidc/). **If you don't**, please implement and test login with SSO before proceeding.
6. I avsnittet **Medlemsdekrypteringsalternativ** väljer du **Key Connector**.
7. I **Key Connector-URL-ingången** anger du adressen Key Connector körs på (som standard `https://din.domän/key-connector`) och välj knappen **Testa** för att säkerställa att du kan nå Key Connector.
8. Bläddra till botten av skärmen och välj **Spara**.