Open7

Amazon OpenSearch 覚書

えんぶんえんぶん

AdvancedSecurityOptions

Security Hub controlesの評価項目の一つとしてOS Domainに対してきめ細かな(fine-grained)アクセス制御が有効になっていることが求められる

https://docs.aws.amazon.com/securityhub/latest/userguide/opensearch-controls.html#opensearch-7

This control checks whether OpenSearch domains have fine-grained access control enabled. The control fails if the fine-grained access control is not enabled. Fine-grained access control requires advanced-security-optionsin the OpenSearch parameter update-domain-config to be enabled.
Fine-grained access control offers additional ways of controlling access to your data on Amazon OpenSearch Service.

Fine-grained access control についての詳細はこちら
https://docs.aws.amazon.com/opensearch-service/latest/developerguide/fgac.html

CloudFormationで指定する場合はDomainのAdvancedSecurityOptions 設定を有効にする必要があるが、このとき以下のプロパティも有効にしている必要がある

えんぶんえんぶん

EncryptionAtRestOptions

https://docs.aws.amazon.com/opensearch-service/latest/developerguide/encryption-at-rest.html

KMSを用いて保存データを暗号化する設定を有効化する。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-opensearchservice-domain.html#cfn-opensearchservice-domain-encryptionatrestoptions

Update requires: Some interruptionsになってるので更新時は注意が必要
EncryptionAtRestOptionsオブジェクトを確認すると、このオプションが設定されていないときに有効化した場合は中断無し、設定された後に変更される(無効化される場合?KMSキーが変更になる場合も含む?)と ドメインが削除されて再作成される

If no encryption at rest options were initially specified in the template, updating this property by adding it causes no interruption. However, if you change this property after it's already been set within a template, the domain is deleted and recreated in order to modify the property.

設定した後は無効化できないとドキュメントに記載されてるのでそういうことなんだろう。

CloudFormationで有効にする場合

KMS Keyに加えてAliasを作成する必要がある

template.yaml
Type: AWS::OpenSearchService::Domain
Properties:
  EncryptionAtRestOptions:
    Enabled: true
    # KmsKeyId属性を指定しない(記述しない)場合は
    # AWS所有のキーが自動で割り当てられる
    KmsKeyId: "arn:aws:kms:us-east-1:123456789012:alias/my-key" # Alias of KMS Key
えんぶんえんぶん

ドメインの設定/構成変更など行うとBlue/Greenデプロイが実施される

https://docs.aws.amazon.com/opensearch-service/latest/developerguide/managedomains-configuration-changes.html

B/G Deployが実施されるケース

  • インスタンスタイプ変更
  • きめ細やかなアクセス制御の有効化
  • 専用マスターノードの有効化または無効化
  • ストレージタイプ、ボリュームタイプ、ボリュームサイズの変更
  • OpenSearch ダッシュボードの Amazon Cognito 認証を有効化または無効化
  • 別の Amazon Cognito ユーザープールまたは ID プールを選択する
  • 新しい OpenSearch バージョンへのアップグレード
    • ダッシュボードは一時的に使えなくなるかも
  • 保存データの暗号化またはノード間暗号化の有効化

など

B/Gが実施されないケース

  • アクセスポリシー、カスタムエンドポイントなどの変更
  • HTTPSリクエストの必須化を有効にする
  • タグの追加/削除

ダウンタイムは発生する?

B/Gデプロイされない場合はダウンタイムが発生するのか??
-> 発生しなさそう

https://aws.amazon.com/jp/opensearch-service/faqs/

Amazon OpenSearch Service ドメインをスケーリングするにはダウンタイムが必要ですか?

いいえ。インスタンスおよびストレージボリュームの追加/変更オペレーションはオンラインで行うことができ、Amazon OpenSearch Service ドメインのスケーリングにダウンタイムは必要ありません。

ログ記録をオンまたはオフにする際、クラスターにダウンタイムは発生しますか?

いいえ。ダウンタイムは発生しません。ログステータスが更新されるたびに、AWS では、バックグラウンドで新しいクラスターがデプロイされ、既存のクラスターが新しいクラスターに置き換えられます。この処理によってダウンタイムは発生しません。ただし、新しいクラスターがデプロイされるため、ログステータスの更新は瞬時に行われません。

アップグレードした場合、ダウンタイムは発生しますか?

アップグレードの際には、ブルー/グリーン (BG) デプロイプロセスを使用します。BG の間、サービスは新しい設定とバージョンで OpenSearch Service クラスターにノードを追加し、古いノードからデータを移行し、データ移行が完了したら古いノードを削除します。BG の間、検索 API とインデックス作成 API は利用可能で、通常通り機能します。BG はクエリやインデックスのリクエストに干渉しないように設計されていますが、一部の変更 (特にセキュリティ関連の設定の変更を伴うもの) により、変更期間中にダッシュボードが使用できなくなることがあります。

ただしアップグレード中など負荷が増大する可能性があるので、ピークタイムは避けて実施し、逐次メトリクスを確認するのが良い

えんぶんえんぶん

saved objectsのエクスポート

ダッシュボードから

ダッシュボード左のハンバーガーメニューから

Management > Dashboards Management > Saved Objects

に保存されている様々なオブジェクトが表示されており、それぞれエクスポートできる。またインポートもここからできる
オブジェクトの種類としては

  • index patterns
  • config
  • dashboard
  • query
  • visualization

など。また各オブジェクトと関連するオブジェクトも確認できる。例えばvisualizationについては子のindex patternや親のdashboardなど。

APIから

ドキュメントに記載されてないが存在はする?

https://github.com/opensearch-project/OpenSearch-Dashboards/issues/987

https://qiita.com/curtain6935/items/15d6e5bd284c55e4996d

えんぶんえんぶん

ソースコードからAPIを探してみる。
仕様はバージョンによって変わりそうなので、使用しているOSのバージョンごとに確認するのがよかろうもん

https://github.com/search?q=repo%3Aopensearch-project%2FOpenSearch-Dashboards+path%3A+path%3A%2F^src\%2Fplugins\%2F.*\%2Fserver\%2Froutes\%2F%2F&type=code&p=2

# GitHubのリポジトリから以下の条件を検索
repo:opensearch-project/OpenSearch-Dashboards path: path:/^src\/plugins\/.*\/server\/routes\//

例えばSavedObjectの取得API

# qiita記事から抜粋
# 記事中はダッシュボード一覧になってるけどtypeで他の物指定すればダッシュボード以外も取得できそう
curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -X GET \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/management/saved_objects/_find?type=dashboard \
  | jq

export APIはこれ

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -d '{"typesToInclude": ["dashboard"]}' \
  -X POST \
   https://$ENDPOINT/_dashboards/api/opensearch-dashboards/management/saved_objects/scroll/export \
  | jq > export_dashboard.json
えんぶんえんぶん

saved objectのtypeの種類としては以下がありそう

  • config
  • url
  • index-pattern
  • query
  • dashboard
  • visualization
  • map
  • visualization-visbuilder
  • augment-vis
  • observability-panel
  • observability-visualization
  • observability-search
  • search