Skip to main content

AWS Security Group Mapping Tool

Project description

sgmap - AWS Security Group Mapping Tool

sgmapは、AWS のセキュリティグループの接続関係を可視化するための CLI ツールおよびライブラリです。指定した VPC 内のセキュリティグループ間の接続関係を mermaid 記法のフローチャートまたは JSON 形式で出力します。

機能

  • 指定した VPC 内のすべてのセキュリティグループの接続関係を分析
  • 特定のセキュリティグループのみを分析するオプション
  • mermaid 記法のフローチャートまたは JSON 形式での出力
  • セキュリティグループ間の接続プロトコルとポート情報の表示
  • CLI ツールとしての使用だけでなく、Python ライブラリとしても利用可能

インストール

pip を使用したインストール

pip install sgmap

ソースからのインストール

git clone https://github.com/youyo/sgmap.git
cd sgmap
pip install -e .

使用方法

CLI ツールとしての使用方法

# VPC内のすべてのセキュリティグループを分析し、mermaid記法で出力
sgmap --vpc-id vpc-12345678

# 特定のセキュリティグループのみを分析
sgmap --vpc-id vpc-12345678 --security-group-id sg-87654321

# JSON形式で出力
sgmap --vpc-id vpc-12345678 --json

オプション

  • --vpc-id, -v (必須): 分析対象の VPC ID
  • --security-group-id, -s (オプション): 特定のセキュリティグループ ID を指定して分析
  • --json, -j (フラグ): JSON 形式で出力(デフォルトは mermaid 記法)

ライブラリとしての使用方法

sgmap は Python ライブラリとしても利用できます。以下は基本的な使用例です:

import sgmap

# VPC内のセキュリティグループ情報を取得
vpc_and_sgs = sgmap.get_security_groups('vpc-12345678')

# 特定のセキュリティグループのみを取得する場合
# vpc_and_sgs = sgmap.get_security_groups('vpc-12345678', 'sg-87654321')

# セキュリティグループの接続関係を分析
connections = sgmap.analyze_security_group_connections(vpc_and_sgs)

# mermaid記法のダイアグラムを生成
mermaid_diagram = sgmap.generate_mermaid_diagram(connections)
print(mermaid_diagram)

# JSON形式の出力を生成
json_output = sgmap.generate_json_output(connections)
print(json_output)

利用可能な関数

  • get_security_groups(vpc_id, security_group_id=None): 指定した VPC 内のセキュリティグループ情報を取得
  • analyze_security_group_connections(vpc_and_sgs): セキュリティグループの接続関係を分析
  • generate_mermaid_diagram(connections): mermaid 記法のダイアグラムを生成
  • generate_json_output(connections): JSON 形式の出力を生成

出力例

mermaid 記法の出力例

flowchart LR
    SG_sg_12345["Web Server\n(sg-12345)"]
    SG_sg_67890["Database\n(sg-67890)"]
    SG_sg_12345 -->|tcp/80| SG_sg_67890

JSON 形式の出力例

{
  "sg-12345": {
    "name": "Web Server",
    "inbound": [],
    "outbound": [
      {
        "id": "sg-67890",
        "name": "Database",
        "protocol": "tcp",
        "from_port": 80,
        "to_port": 80
      }
    ]
  },
  "sg-67890": {
    "name": "Database",
    "inbound": [
      {
        "id": "sg-12345",
        "name": "Web Server",
        "protocol": "tcp",
        "from_port": 80,
        "to_port": 80
      }
    ],
    "outbound": []
  }
}

必要条件

  • Python 3.6 以上
  • boto3
  • click
  • AWS 認証情報(環境変数、~/.aws/credentials など)

開発者向け情報

開発環境のセットアップ

git clone https://github.com/youyo/sgmap.git
cd sgmap
pip install -e ".[dev]"

リリース方法

このプロジェクトは GitHub Actions を使用して PyPI にパッケージを公開しています。タグのバージョンがそのまま PyPI のパッケージバージョンとして使用されます。以下の手順でリリースを行います:

  1. バージョンタグを作成します(例:v0.1.0

    git tag -a v0.1.0 -m "Release version 0.1.0"
    git push origin v0.1.0
    

    注意:

    • タグの形式は必ず v で始まり、その後に X.Y.Z 形式のバージョン番号が続く形式(例:v0.1.0v1.2.3)にしてください。
    • タグのバージョン番号(v を除いた部分)がそのまま PyPI のパッケージバージョンとして使用されます。例えば、v0.2.1 というタグを作成すると、PyPI では 0.2.1 というバージョンでパッケージが公開されます。
    • pyproject.tomlの設定により、タグ付けされていないコミットでもタグのバージョンがそのまま使用されます(開発バージョンとして扱われません)。
    • この形式に従わないタグはリリースプロセスで問題が発生する可能性があります。
  2. GitHub Actions が自動的にパッケージをビルドし、PyPI に公開します。

ローカルでのビルド

pip install -r requirements-dev.txt
python -m build

ライセンス

MIT

作者

youyo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgmap-0.2.3.post1.dev0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgmap-0.2.3.post1.dev0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file sgmap-0.2.3.post1.dev0.tar.gz.

File metadata

  • Download URL: sgmap-0.2.3.post1.dev0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sgmap-0.2.3.post1.dev0.tar.gz
Algorithm Hash digest
SHA256 24fe7956b32cda8cb020f9c25d8a13e2abc940d147730dee3c6eb9180e232a39
MD5 2f244c03ae8978fc0db309c88795d56b
BLAKE2b-256 1c6d0316978e8d676b73a477352a490db9fbac69268672633db0ee33b921a2d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgmap-0.2.3.post1.dev0.tar.gz:

Publisher: publish.yaml on youyo/sgmap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgmap-0.2.3.post1.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for sgmap-0.2.3.post1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 97cc84f2f4b7c3c89ba0e68dab21277d3f876231d4185e91e4881dc7a0c92925
MD5 edeaf6915521e33b9e130214b2d8e5c8
BLAKE2b-256 3614172ec533669de481763c9465f07e930c1af99c08e1595b5e68ff738f35cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgmap-0.2.3.post1.dev0-py3-none-any.whl:

Publisher: publish.yaml on youyo/sgmap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page