---
title: "ステップ 3: シークレットを作成する"
description: チャートをインストールする前に、OpenLM Platform の接続情報と TLS 証明書を格納する Kubernetes Secret を作成します。
product: OpenLM Platform
---

チャートをインストールする前に、接続情報を格納する Kubernetes Secret を 1 つのスクリプトで作成します。チャートには**パスワードが含まれていません**。各サービスは、お客様が namespace に作成した Secret から接続情報を読み取ります。

このページのコマンドは、[インストールワークシート](https://www.openlm.com/documentation/ja/cloud/deployment-operations/on-premise/deployment-guide/kubernetes/before-you-start/worksheet) から作成したファイル `openlm-install.env` から変数を読み込みます。

:::note[シークレットが Helm に含まれない理由]
シークレットは、意図的に Helm ではなく `kubectl` で作成します。こうすることで、`helm uninstall` やアップグレードの失敗によって認証情報が削除されることはなく、Helm リリースに手を加えずにパスワードをローテーションできます。
:::

## 3.1 スクリプトを保存する

次のブロックを、ワークシートと同じフォルダーに `create-openlm-secrets.sh` として保存します。すべての値をワークシートから読み取るため、編集する必要はありません。

```bash
#!/usr/bin/env bash
# create-openlm-secrets.sh: creates or updates every Secret the OpenLM Platform reads.
# Safe to run again: existing secrets are updated in place.
set -euo pipefail
: "${NS:?load openlm-install.env first}" "${SQL_HOST:?}" "${SQL_USER:?}" "${SQL_PASSWORD:?}" "${DB_PREFIX:?}"
: "${MONGO_URI:?}" "${KAFKA_BOOTSTRAP:?}" "${REDIS_HOST:?}" "${REDIS_PASSWORD:?}" "${HANGFIRE_PASSWORD:?}"

apply() { local name="$1"; shift
  kubectl -n "$NS" create secret generic "$name" "$@" --dry-run=client -o yaml | kubectl -n "$NS" apply -f - >/dev/null
  echo "  ok  $name"; }

# SQL Server. Connection strings carry the password BASE64-ENCODED (the services decode it).
# Split-field secrets carry it as plain text.
SQL_PASSWORD_B64="$(printf '%s' "$SQL_PASSWORD" | base64 | tr -d '\n')"
DS="$SQL_HOST"; [ "$SQL_PORT" != "1433" ] && DS="$SQL_HOST,$SQL_PORT"
TAIL="Min Pool Size=0;Max Pool Size=100;Encrypt=${SQL_ENCRYPT};TrustServerCertificate=True"
conn() { echo "Data Source=$DS;Initial Catalog=$1;User ID=$SQL_USER;Password=$SQL_PASSWORD_B64;$TAIL"; }

# Redis. With TLS the services need ssl=True in the connection string.
REDIS_CONN="$REDIS_HOST:$REDIS_PORT,password=$REDIS_PASSWORD,abortConnect=false"
[ "${REDIS_TLS:-false}" = "true" ] && REDIS_CONN="$REDIS_CONN,ssl=True"

echo "Creating secrets in namespace $NS ..."
apply openlm-generic-identity-db-credentials \
  --from-literal="IDENTITY_DATABASE_CONNECTIONSTRING=$(conn "${DB_PREFIX}_identity")" \
  --from-literal="ConnectionString=$(conn "${DB_PREFIX}_identity")"
apply openlm-generic-server-db-credentials \
  --from-literal="INFRASTRUCTURE__ServerConnectionStringTemplate=$(conn '{0}')"
apply openlm-generic-reporting-db-credentials \
  --from-literal="REPORTING_DATABASE_CONNECTIONSTRING=$(conn "${DB_PREFIX}_reporting")"
apply openlm-generic-reporting-mssql-credentials \
  --from-literal="HOST_NAME=$SQL_HOST" --from-literal="PORT=$SQL_PORT" \
  --from-literal="USERNAME=$SQL_USER" --from-literal="PASSWORD=$SQL_PASSWORD"
apply openlm-dss-db-credentials \
  --from-literal="DbType=2" --from-literal="DbServer=$SQL_HOST" --from-literal="DbPort=$SQL_PORT" \
  --from-literal="DbName=${DB_PREFIX}_dss" --from-literal="DbUser=$SQL_USER" --from-literal="DbPassword=$SQL_PASSWORD_B64"

apply openlm-generic-mongo-db-credentials \
  --from-literal="MONGODB__CONNECTIONSTRING=$MONGO_URI" \
  --from-literal="MONGODB_CONNECTION=$MONGO_URI" --from-literal="MONGOURI=$MONGO_URI" --from-literal="MONGO_URI=$MONGO_URI"
apply openlm-generic-kafka-bootstrap-credentials \
  --from-literal="INFRASTRUCTURE__KAFKABOOTSTRAPSERVERS=$KAFKA_BOOTSTRAP"
apply openlm-generic-redis-connection-credentials \
  --from-literal="REDIS__CONNECTIONSTRING=$REDIS_CONN" \
  --from-literal="INFRASTRUCTURE__REDIS__CONNECTIONSTRING=$REDIS_CONN" \
  --from-literal="INFRASTRUCTURE__REDISCONNECTION=$REDIS_CONN" --from-literal="REDIS_CONNECTION=$REDIS_CONN"

# Sign-in to the background-job dashboard of the identity discovery service.
apply openlm-identitydiscovery-hangfire-credentials \
  --from-literal="Hangfire__Dashboard__Authorization__Username=admin" \
  --from-literal="Hangfire__Dashboard__Authorization__Password=$HANGFIRE_PASSWORD"

# Optional integrations. They must exist; leave them empty unless you use the integration.
apply openlm-auditservice-aws-credentials --from-literal=ACCESSKEY= --from-literal=SECRETKEY=
apply openlm-licensefilecomparator-aws-credentials \
  --from-literal=AWS_SQS_ACCESS_KEY= --from-literal=AWS_SQS_SECRET_ACCESS_KEY=
apply openlm-licensefilecomparator-servicenow-credentials \
  --from-literal=SERVICENOW_CLIENTID= --from-literal=SERVICENOW_CLIENTSECRET= \
  --from-literal=SERVICENOW_USERNAME= --from-literal=SERVICENOW_PASSWORD= --from-literal=SERVICENOW_INSTANCE_URL= \
  --from-literal=AWS_SQS_QUEUE_URL= --from-literal=AWS_SQS_REGION= \
  --from-literal=BROKERHUBAPI_DELAY_IN_MILLISECONDS=10000 --from-literal=BROKERHUBAPI_MAX_RETRY_COUNT=5 \
  --from-literal=AWS_SQS_MAX_MESSAGES=5 --from-literal=AWS_SQS_QUEUE_WORKER_COUNT=3 --from-literal=AWS_SQS_WAIT_TIME_SECONDS=10
for p in alertservice:ALERT_SERVICE identityservice:IDENTITY identityalignment:IDENTITYALIGNMENT; do
  args=(); for f in TYPE PROJECT_ID PRIVATE_KEY_ID PRIVATE_KEY CLIENT_MAIL CLIENT_ID AUTH_URI TOKEN_URI AUTH_PROVIDER_X509 CLIENT_x509; do
    args+=("--from-literal=${p#*:}__$f="); done
  apply "openlm-pushnotification-${p%%:*}-credentials" "${args[@]}"
done
apply openlm-sam-apikeys --from-literal=EXCHANGERATES__CURRENCYFREAKS__APIKEY= \
  --from-literal=EXCHANGERATES__FREECURRENCYAPI__APIKEY= --from-literal=EXCHANGERATES__OPENEXCHANGERATES__APIKEY=
echo "Done."
```

## 3.2 スクリプトを実行する

```bash
source ./openlm-install.env
bash ./create-openlm-secrets.sh
```

すべての行に `ok` と表示される必要があります。スクリプトが `load openlm-install.env first` または変数名を表示して停止した場合は、ワークシートのその変数が空です。

## 3.3 TLS 証明書を追加する

証明書を `openlm-lb-cert` という名前のシークレットに格納します。Ingress はこのシークレットから証明書を提供します。

```bash
kubectl -n "$NS" create secret tls openlm-lb-cert --cert="$TLS_CERT_FILE" --key="$TLS_KEY_FILE"
```

証明書については、次の 2 点に注意してください。

- **証明書の順序**: 証明書ファイルには、最初にサーバー証明書、次に中間証明書を含める必要があります。証明書がプライベート CA から発行されている場合は、末尾にルート証明書も追加します。これがサインインにとって重要な理由は、[TLS 証明書](https://www.openlm.com/documentation/ja/cloud/deployment-operations/on-premise/deployment-guide/kubernetes/concepts/tls-certificates) で説明しています。
- **OpenShift**: ルートは既定でルーターの証明書を使用します。このステップの前に [OpenShift: 証明書](https://www.openlm.com/documentation/ja/cloud/deployment-operations/on-premise/deployment-guide/kubernetes/platforms/openshift#証明書) をお読みください。

## よくある問題

後のステップが失敗した場合は、次の表で症状を探してください。

| 後で発生する症状 | 原因 |
|---|---|
| サービスのログに `FormatException` または `Login failed for user` が出力される | 接続文字列内の SQL パスワードが base64 エンコードされていないか、`SQL_PASSWORD` に入力ミスがあります。エンコードはスクリプトが処理します。接続文字列を手作業で編集しないでください。 |
| Pod が `CreateContainerConfigError` のまま止まる | Pod が必要とするシークレットが存在しません。スクリプトを再実行し、すべての行に `ok` と表示されたことを確認してください。 |
| 一部のデータジョブが、エラーを出さずにデータを一切書き込まない | `MONGO_URI` が `/` で終わっています。`/` を削除して、スクリプトを再実行してください。 |

:::tip[確認]
```bash
kubectl -n "$NS" get secrets | grep -c "^openlm-"
```

**17** と表示される必要があります（スクリプトによる 16 個と `openlm-lb-cert`）。
:::

:::note[後でパスワードを変更する]
ワークシートの値を変更してスクリプトを再実行し、OpenLM Platform の Pod を再起動して新しい値を読み込ませます: `kubectl -n openlm rollout restart deployment`。Pod は起動時にのみ Secret を読み取ります。
:::
