Helion OpenStack 2.X Nova インスタンスのリサイズ – 有効化/無効化

2016-03-17

Helion OpenStack 2.X Nova インスタンスのリサイズ – 有効化/無効化

Machine-translated — the English original is authoritative.

インスタンスのリサイズとコールドマイグレーションの有効化

設計上、Helion OpenStack 2.X では、これらのサービスが OpenStack (Kilo) で現在実装されている方法においてセキュリティリスクをもたらすため、Nova インスタンスのリサイズと Nova コールドマイグレーションが無効になっています。

セキュリティリスク

これらのサービスは、パスワードレス SSH アクセスと基盤となるファイルシステムへの変更権限を必要とします。計算ノードは他のすべての計算ノードにアクセスできる必要があります。これにより、攻撃者やウイルスがいずれかのノードにアクセスした場合、ホスト間で隔離が行われなくなります。

将来の展望: 上記の問題に対処するために、いくつかのアップストリームでのブループリントが、いくつかの変更を加えたセキュアな Nova ライブマイグレーションプロセスを活用して取り組んでいます。これには、TLS を介してデータを安全に転送するために libvirt/qemu が使用されます。

上記のセキュリティリスクを受け入れることができる場合は、以下に進んでください。

手順

これは熟練した Linux/OpenStack エンジニアによって実行されるべきです。手順は非常にシンプルです。

インスタンスのリサイズを有効化

例:

# デプロイヤーノードで - キーペアを生成します(これは一度だけ実行すればよく、同じキーペアをすべての計算ホストで使用する必要があります)

ssh-keygen -t rsa -f ~/nova_resize/id_rsa -N ''

# これにより、秘密鍵 (id_rsa) と公開鍵 (id_rsa.pub) の2つのファイルが生成されます

# 秘密鍵を転送します - すべての計算ノードに対してこれを繰り返します
scp nova_resize/id_rsa* stack@helion-cp1-comp0001-mgmt:~/

# 各計算ホストで、以下のフォルダーが存在することを確認します:

mkdir /var/lib/nova/.ssh

# 各計算ホストで、秘密鍵を .ssh フォルダーにコピーし、適切な権限/所有者を設定します

cp id_rsa /var/lib/nova/.ssh
chmod 600 /var/lib/nova/.ssh/id_rsa
chown nova:nova /var/lib/nova/.ssh/id_rsa

# 各ホストで、公開鍵を承認済みキーのリストに追加します

cat id_rsa.pub >> /var/lib/nova/.ssh/authorized_keys

# 各計算ホストで厳格なホストチェックを無効にします

echo 'StrictHostKeyChecking no' >> /var/lib/nova/.ssh/config

# 各計算ホストで、nova ユーザーがシェルにログインできることを確認します

usermod -s /bin/bash nova

# migrate と resize を許可するように、各種 policy.json ファイルを変更します

"compute:resize": "rule:admin_api",

"compute_extension:admin_actions:migrate": "rule:admin_api",

# 各コントローラーノードで、Horizon の nova_policy.json ファイルを変更してリサイズを有効にします

"compute:resize": "",

"compute:confirm_resize": "",

"compute:revert_resize": "", 

# すべてのノードで Nova と Horizon サービスを再起動します。

# Nova インスタンスのリサイズと Nova コールドマイグレーションが正常に動作するはずです。

インスタンスのリサイズを無効化

注意

このような設定変更を「手動」で行う際の大きな課題の一つは、クラウドの再デプロイやアップグレードを行う際に、これらの変更が Helion Lifecycle Manager の設定リポジトリに記録されていないため、再デプロイされたクラウドには存在しないということです。

解決策 - これらすべての設定変更に対して Ansible Playbook を使用し、HLM git リポジトリに追加する

私自身 Ansible に慣れていませんでしたが、上記で特定された手動手順を実装するために、以下のプレイブックをすぐに作成することができました。Helion OpenStack に関しては、Ansible をまだ試したことがない場合でも、数日かけて Ansible をいじる価値は十分にあります。それは素晴らしい生産性向上ツールです。

本番環境で実装する前に、これらのスクリプトを徹底的にテストしてください。前述の通り、これらは私がこのツールに触れて初めて作成したものです。

プレイブックの使用手順は、各プレイブック内のコメントに記載されています。

HOS 2.X インスタンスのリサイズ有効化プレイブック

# Author: Graham Joseph Land
# Blog: allthingscloud.eu
# Twitter: @allthingsclowd
# Email: graham@the above domain
# Date: 03/03/2016
# 
# Name: nova-enable-resize.yml
# Version: 1.1
# Purpose: This playbook is one of 5 that must be run in order to re-enable nova instance resize and cold migration
#
# Instructions: 
# 1. Copy this playbook to the following two ansible directories on the deployer node -> ~/scratch/ansible/next/hos/ansible AND ~/helion/hos/ansible
# 2. Log on to the Helion Lifecycle Manager (HLM Deployer) as the deployer user and change to this directory -> ~/scratch/ansible/next/hos/ansible
# 3. Enable nova instance resize and nova cold-migration by performing the following steps:
#      a.) ansible-playbook -v -i hosts/verb_hosts nova-enable-resize.yml
#      b.) cd ~/helion/hos/ansible
#      c.) git add -A
#      d.) git commit -m "Reconfigured Nova's policy.json to allow instance resize and cold migration for admins"
#      e.) cd ~/helion/hos/ansible
#      f.) ansible-playbook -i hosts/localhost config-processor-run.yml
#      g.) cd ~/helion/hos/ansible
#      h.) ansible-playbook -i hosts/localhost ready-deployment.yml
#      i.) cd ~/scratch/ansible/next/hos/ansible
#      j.) ansible-playbook -i hosts/verb_hosts nova-reconfigure.yml
#       k.) ansible-playbook -i hosts/verb_hosts horizon-reconfigure.yml

---
#
# on the deployer node
# 
    - hosts: OPS-LM

      tasks:
# get username of the current user
      - name: get the current username running this playbook
        local_action: command whoami
        register: username_on_the_host

# create temporary directory
      - name: create directory to store ssh keys
        file: path=~/nova_resize state=directory

# if it's a re-run remove existing private key to facilitate new key creation      
      - name: for repeat runs remove old private key from directory
        file: path=~/nova_resize/id_rsa state=absent

# if it's a re-run remove existing public key to facilitate new key creation
      - name: for repeat runs remove old public key from directory
        file: path=~/nova_resize/id_rsa.pub state=absent

# create new ssh keys
      - name: creating SSH keys for nova user login
        command: ssh-keygen -t rsa -f '~/nova_resize/id_rsa' -N ""

# modify nova policy.json file in mycloud repo to enable resize
      - name: modify nova policy.json file in deployer git repo - enable resize
        lineinfile: 'dest=~/helion/my_cloud/config/nova/policy.json state=present regexp="compute:resize" create=yes line="    \"compute:resize\": \"rule:admin_api\"," owner={{ username_on_the_host.stdout }} group={{ username_on_the_host.stdout }} mode=0777'

# modify nova policy.json file in mycloud repo to enable cold migration
      - name: modify nova policy.json file in deployer git repo - enable cold migrate
        lineinfile: 'dest=~/helion/my_cloud/config/nova/policy.json state=present regexp="\"compute_extension:admin_actions:migrate\"" create=yes line="    \"compute_extension:admin_actions:migrate\": \"rule:admin_api\"," owner={{ username_on_the_host.stdout }} group={{ username_on_the_host.stdout }} mode=0777'

#
# on each compute node
#

    - hosts: NOV-CMP
      sudo: yes
      vars:
# load the public ssh key into a variable
        nova_public_ssh_key: "{{ lookup('file', '~/nova_resize/id_rsa.pub') }}"

      tasks:
# create a .ssh directory if it doesn't already exist
      - name: create nova ssh directory on compute host
        file: path=/var/lib/nova/.ssh state=directory owner=nova group=nova mode=0755

# copy the private key to the .ssh directory
      - name: copy nova ssh private key to .ssh directory and set correct permissions on compute nodes
        copy: src=/home/stack/nova_resize/id_rsa dest=/var/lib/nova/.ssh/id_rsa owner=nova group=nova mode=0600

# add the public ssh key to the authorized_hosts file
      - name:  add nova ssh public key to the authorized_keys file on each compute nodes
        lineinfile: 'dest=/var/lib/nova/.ssh/authorized_keys state=present backup=yes create=yes line="\"{{ nova_public_ssh_key }}\"" owner=nova group=nova mode=0644'

# set stricthostkeychecking to no in the ssh config file
      - name: turn off strict host checking on each compute nodes
        lineinfile: dest=/var/lib/nova/.ssh/config state=present backup=yes regexp="^StrictHostKeyChecking" create=yes line="StrictHostKeyChecking no" owner=nova group=nova mode=0644

# set bash shell as default for nova user
      - name: set nova user shell on each compute node
        command: usermod -s /bin/bash nova

# verify that nova user can login without a password locally
      - name: verify passwordless login for nova user
        become: yes
        become_user: nova
        command: ssh nova@{{ inventory_hostname }} 'echo Passwordless Login Successfully!'

#
# on each controller node
#
    - hosts: HZN-WEB
      sudo: yes

      tasks:

# find path to horizons nova_policy_json file
      - shell:  find /opt/stack/venv/ -name nova_policy.json | grep dashboard
        register: nova_policy_json

# enable nova instance resize in horizons nova_policy_json
      - name: enable nova instance resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:resize" create=yes line="    \"compute:resize\": \"rule:admin_api\"," owner=horizon-venv group=horizon-venv mode=0664'

# enable nova instance resize in horizons nova_policy_json
      - name: enable nova instance confirm resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:confirm_resize" create=yes line="    \"compute:confirm_resize\": \"rule:admin_api\"," owner=horizon-venv group=horizon-venv mode=0664'

# enable nova instance resize in horizons nova_policy_json
      - name: enable nova instance revert resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:revert_resize" create=yes line="    \"compute:revert_resize\": \"rule:admin_api\"," owner=horizon-venv group=horizon-venv mode=0664'

HOS 2.X インスタンスのリサイズ無効化プレイブック

# Author: Graham Joseph Land
# Blog: allthingscloud.eu
# Twitter: @allthingsclowd
# Email: graham@the above domain
# Date: 04/03/2016
# 
# Name: nova-disable-resize.yml
# Version: 1.1
# Purpose: This playbook is one of 5 that must be run in order to disable nova instance resize and cold migration
#
# Instructions: 
# 1. Copy this playbook to the following two ansible directories on the deployer node -> ~/scratch/ansible/next/hos/ansible AND ~/helion/hos/ansible
# 2. Log on to the Helion Lifecycle Manager (HLM Deployer) as the deployer user and change to this directory -> ~/scratch/ansible/next/hos/ansible
# 3. Disable nova instance resize and nova cold-migration by performing the following steps:
#      a.) ansible-playbook -v -i hosts/verb_hosts nova-disable-resize.yml
#      b.) cd ~/helion/hos/ansible
#      c.) git add -A
#      d.) git commit -m "Reconfigured Nova's policy.json to disable instance resize and cold migration for admins"
#      e.) cd ~/helion/hos/ansible
#      f.) ansible-playbook -i hosts/localhost config-processor-run.yml
#      g.) cd ~/helion/hos/ansible
#      h.) ansible-playbook -i hosts/localhost ready-deployment.yml
#      i.) cd ~/scratch/ansible/next/hos/ansible
#      j.) ansible-playbook -i hosts/verb_hosts nova-reconfigure.yml
#       k.) ansible-playbook -i hosts/verb_hosts horizon-reconfigure.yml

---
#
# on each controller node
#
    - hosts: HZN-WEB
      sudo: yes

      tasks:

# find path to horizons nova_policy_json file
      - shell:  find /opt/stack/venv/ -name nova_policy.json | grep dashboard
        register: nova_policy_json

# disable nova instance resize in horizons nova_policy_json
      - name: disable nova instance resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:resize" create=yes line="    \"compute:resize\": \"!\"," owner=horizon-venv group=horizon-venv mode=0664'

# disable nova instance resize in horizons nova_policy_json
      - name: disable nova instance confirm resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:confirm_resize" create=yes line="    \"compute:confirm_resize\": \"!\"," owner=horizon-venv group=horizon-venv mode=0664'

# disable nova instance resize in horizons nova_policy_json
      - name: disable nova instance revert resize in horizon
        lineinfile: 'dest={{ nova_policy_json.stdout }} state=present backup=yes regexp="compute:revert_resize" create=yes line="    \"compute:revert_resize\": \"!\"," owner=horizon-venv group=horizon-venv mode=0664'
#
# on each compute node
#

    - hosts: NOV-CMP
      sudo: yes

# load the public ssh key into a variable
      vars:
        nova_public_ssh_key: "{{ lookup('file', '~/nova_resize/id_rsa.pub') }}"

      tasks:
# remove ssh key from authorized_keys file 
      - authorized_key: 'user=nova key="{{ nova_public_ssh_key }}" path="/var/lib/nova/.ssh/authorized_keys" state=absent'

# remove the private key to the .ssh directory
      - name: copy nova ssh private key to .ssh directory and set correct permissions on compute nodes
        file: path=/var/lib/nova/.ssh/id_rsa state=absent

# set stricthostkeychecking to yes in the ssh config file
      - name: turn on strict host checking on each compute nodes
        lineinfile: dest=/var/lib/nova/.ssh/config state=present backup=yes regexp="^StrictHostKeyChecking" create=yes line="StrictHostKeyChecking yes" owner=nova group=nova mode=0644

# unset bash shell as default for nova user
      - name: unset nova user shell on each compute node
        command: usermod -s /bin/false nova

# verify that nova user can't login without a password locally
      - name: verify passwordless login fails for nova user - RED FAILURE IS GOOD!!!
        become: yes
        become_user: nova
        command: ssh nova@{{ inventory_hostname }} 'echo Passwordless Login Successfully ... NOT!'
        ignore_errors: yes

#
# on the deployer node
# 
    - hosts: OPS-LM

      tasks:
# get username of the current user
      - name: get the current username running this playbook
        local_action: command whoami
        register: username_on_the_host

# if it's a re-run remove existing private key to facilitate new key creation      
      - name: remove private ssh key
        file: path=~/nova_resize/id_rsa state=absent

# delete existing public key 
      - name: delete public ssh key
        file: path=~/nova_resize/id_rsa.pub state=absent

# modify nova policy.json file in mycloud repo to disable resize
      - name: modify nova policy.json file in deployer git repo - disable instance resize
        lineinfile: 'dest=~/helion/my_cloud/config/nova/policy.json state=present regexp="compute:resize" create=yes line="    \"compute:resize\": \"\"," owner={{ username_on_the_host.stdout }} group={{ username_on_the_host.stdout }} mode=0777'

# modify nova policy.json file in mycloud repo to disable cold migration
      - name: modify nova policy.json file in deployer git repo - disable cold migrate
        lineinfile: 'dest=~/helion/my_cloud/config/nova/policy.json state=present regexp="\"compute_extension:admin_actions:migrate\"" create=yes line="    \"compute_extension:admin_actions:migrate\": \"\"," owner={{ username_on_the_host.stdout }} group={{ username_on_the_host.stdout }} mode=0777'

# delete temporary directory
      - name: create directory to store ssh keys
        file: path=~/nova_resize state=absent

Originally published on allthingscloud.eu (2016-03-17).

← All posts