:>/dev/null

ラガードエンジニアの不撓不屈の精神/unlearning/go beyond

cloudmapperに入門した

awsの構成変更を行う場合、Document更新を忘れるので良い方法がないか調査した。
本来なら構成変更を行ったタイミングで自動化してDocument更新をするのが良いが効果的な方法が見つからない。
cloudmapperを使用した場合、現時点での構成が図表されるので代替え案として検討した。
導入する為に行った時の勉強メモ。

  • 以下構築要件
    • awsの構成管理を行う(現時点で運用されてる構成図を表示)
    • awsのec2インスタンス上にcloudmapperをインストール
    • cloudmapperをインストールしたインスタンスから各インスタンスへ接続可能
    • cloudmapperをインストールしたインスタンスにグローバルからアクセス可能
      • EIPを割当済みの場合、IP変更が発生せず便利

■下記に導入〜動作確認までを記載する

● OSに必要環境セットアップ

$sudo yum install autoconf automake libtool python3-devel.x86_64 python3-tkinter python34-devel awscli w3m jq
$virtualenv venv
$python --version
$pip install -r requirements.txt

● cloudmapperインストール

$git clone https://github.com/duo-labs/cloudmapper.git

● ユーザーが未作成の場合、コンソールより作成

$aws --profile cloudmapper iam create-user --user-name cloudmapper

● accounts確認

[ec2-user@ip-172-31-xxx-xxx cloudmapper]$ cat config.json
{  "accounts":
    [
        {"id": "123456789012", "name": "aws-account-1", "default": true}
    ],
    "cidrs":
    {
        "1.1.1.1/32": {"name": "SF Office"},
        "2.2.2.2/28": {"name": "NY Office"}
    }
}

● credentialsファイル確認

[ec2-user@ip-172-31-xxx-xxx cloudmapper]$ cat ~/.aws/credentials
[default]
aws_access_key_id = *********
aws_secret_access_key = *********

[cloudmapper]
aws_access_key_id = *********
aws_secret_access_key = *********

● 起動

$cd /home/ec2-user/cloudmapper
$./collect_data.sh --account aws-account-1 --profile cloudmapper
$python cloudmapper.py prepare --account aws-account-1
$python cloudmapper.py webserver --public --port 8001

※ 一部起動パラメータが変更になっているので調整する

$ python cloudmapper.py webserver {args}

def run(arguments):
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"--port",
help="Port to listen on",default=8000,type=int)
parser.add_argument(
"--public",
dest='is_public',help="Allow connections from 0.0.0.0 (or :: if --ipv6 was provided) as opposed to only localhost",action='store_true')
parser.add_argument(
"--ipv6",
dest='is_ipv6',help="Listen on IPv6",action='store_true')

● 動作確認

$curl http://localhost:8001/
$w3m http://localhost:8001/

以下のように、VPCやSubnetのレイアウトやSecurity Groupによるアクセス許可を可視化できる
(README.mdより引用) f:id:oguguman:20190517164146p:plain

ref)
https://qiita.com/bukaz/items/4a769065cd14b192319f