てくなべ (tekunabe)

ansible / network automation / 学習メモ

ネットワーク機器のコンフィグの固有情報を「匿名化」するツール netconan

はじめに

ネットワーク機器のコンフィグファイルをどこかに提示する際、パスワードや IP アドレス、SNMP コミュニティ名などの固有情報をマスクしたり、変更したりする機会はないでしょうか。 netconan はそれを自動で変換してくれるツールです。

github.com

インストール

pip ですぐにインストールできます。

pip install netconan

使い方

オプションで、コンフィグファイル名や、匿名化の詳細を指定します。

  • -i オプションで対象のコンフィグファイル(またはディレクトリ)
  • -o オプションで出力先のファイル名(またはディレクトリ)
  • IPアドレスを匿名化する場合は、-a または --anonymize-ips オプションを指定します
  • -w オプションで「この単語があったら匿名化して」という指定もできます

詳細は、README を参照してください。

以下、ヘルプを転記します。

$ netconan --help
usage: netconan [-h] [-a] [-c CONFIG] [-d DUMP_IP_MAP] -i INPUT
                [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-n AS_NUMBERS] -o
                OUTPUT [-p] [-r RESERVED_WORDS] [-s SALT] [-u]
                [-w SENSITIVE_WORDS] [--preserve-prefixes PRESERVE_PREFIXES]

Args that can start with '--' can also be set in a config file (specified via
-c). If an arg is specified in more than one place, then command line values
override config file values which override defaults. Config file syntax
allows: key=value, flag=true, stuff=[a,b,c] (for more details, see here
https://goo.gl/R74nmi).

optional arguments:
  -h, --help            show this help message and exit
  -a, --anonymize-ips   Anonymize IP addresses
  -c CONFIG, --config CONFIG
                        Netconan configuration file with defaults for these
                        CLI parameters
  -d DUMP_IP_MAP, --dump-ip-map DUMP_IP_MAP
                        Dump IP address anonymization map to specified file
  -i INPUT, --input INPUT
                        Input file or directory containing files to anonymize
  -l {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Determines what level of logs to display
  -n AS_NUMBERS, --as-numbers AS_NUMBERS
                        List of comma separated AS numbers to anonymize
  -o OUTPUT, --output OUTPUT
                        Output file or directory where anonymized files are
                        placed
  -p, --anonymize-passwords
                        Anonymize password and snmp community lines
  -r RESERVED_WORDS, --reserved-words RESERVED_WORDS
                        List of comma separated words that should not be
                        anonymized
  -s SALT, --salt SALT  Salt for IP and sensitive keyword anonymization
  -u, --undo            Undo reversible anonymization (must specify salt)
  -w SENSITIVE_WORDS, --sensitive-words SENSITIVE_WORDS
                        List of comma separated keywords to anonymize
  --preserve-prefixes PRESERVE_PREFIXES
                        List of comma separated IPv4 prefixes to preserve

対応ベンダー

残念ながら一覧になっているドキュメントが見当たりませんでした。 例示されているのは Cisco です。試せてもいませんが、過去の issue などを見ると他に、Juniper、Arista について言及するものはありました。

まとめ

ネットワークコンフィグファイルを「匿名化」するツール netconan をご紹介しました。 この手の作業は意外と手間で、漏れも発生しがちなので、本ツールの活用を検討してみてはいかがでしょうか。