カオスエンジニアリングツールGremlinにてネットワーク障害を注入してみた #reinvent

カオスエンジニアリングツールGremlinは、システムに障害を注入することができるサービスです。 本エントリでは、Network Gremlinsを利用して、ネットワーク障害(トラフィック遅延、損失など)を注入してみたいと思います。
2019.12.30

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

カオスエンジニアリングツールGremlinは、システムに障害を注入することができるサービスです。

本エントリでは、Network Gremlinsを利用して、ネットワーク障害(トラフィック遅延、損失など)を注入してみたいと思います。

以下のようなイメージです。

10

前提

  • Gremlin PROアカウント
    • Gremlin Freeではネットワーク障害が利用できないのでご注意ください
    • 参考:Pricing

やってみた

Gremlin Clientインストール

まずは、カオス実験(以下、攻撃)の対象となるサーバに、Gremlin Clientをインストールします。 以下、ハイライトしているコマンドの実行でインストールは完了します。なお、Gremlinの初期化(sudo gremlin init)には、Gremlin Team ID、Secret Keyの情報が必要になります。

[ec2-user@ip-172-31-34-232 ~]$ sudo yum install -y iproute-tc

(省略)

Installed:
  iproute-tc.x86_64 0:4.15.0-1.amzn2.0.3

Complete!
[ec2-user@ip-172-31-34-232 ~]$ sudo curl https://rpm.gremlin.com/gremlin.repo -o /etc/yum.repos.d/gremlin.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   330  100   330    0     0    372      0 --:--:-- --:--:-- --:--:--   372
[ec2-user@ip-172-31-34-232 ~]$ sudo yum install -y gremlin gremlind

(省略)

Installed:
  gremlin.noarch 0:2.12.21-1                                               gremlind.noarch 0:2.12.21-1

Complete!
[ec2-user@ip-172-31-34-232 ~]$ sudo gremlin init
Please input your Team ID:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Please input your Team Secret:

(省略)

Using xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx for Team Id
Using c6959695-4d86-5ebc-8c9f-49a69cfd0716 for Team Id
Using 172.31.34.232 for Gremlin identifier

インストールが完了すると、Gremlinコンソール「Clients」より、Gremlin Clientをインストールしたサーバ(以下、Gremlin Client)を確認することができます。

レイテンシー攻撃

Gremlin Clientから出力する通信に、遅延を注入してみます。

攻撃の設定を行いますので「Attacks」-「Infrastructure」-「New Attack」をクリックします。

以下を指定します。

  • What do you want to attack? … Hosts
  • Choose Hosts to target … 先程構築したGremlin Clientにチェック

以下の設定を行いました。

  • Category … Network
  • Atacks … Latency
  • Length … 攻撃の長さ(ここでは60秒)
  • IP Addresses … トラフィックの影響をうけるIP(ここでは172.31.33.251)
  • MS … 出力パケットを遅延させる時間(ここでは3秒)

上記は、172.31.33.251へのネットワーク通信に、1分間、3秒(3000ミリ秒)の遅延を発生させる設定です。 「Unleash Gremlin」をクリックして、障害を注入します。

AttackのステータスがRunningになります。

Gremlin Clientから、指定IPへの通信に遅延を確認することができました。

64 bytes from 172.31.33.251: icmp_seq=15 ttl=255 time=0.380 ms
64 bytes from 172.31.33.251: icmp_seq=16 ttl=255 time=0.441 ms
64 bytes from 172.31.33.251: icmp_seq=17 ttl=255 time=3000 ms
64 bytes from 172.31.33.251: icmp_seq=18 ttl=255 time=3000 ms

(省略)

64 bytes from 172.31.33.251: icmp_seq=71 ttl=255 time=3000 ms
64 bytes from 172.31.33.251: icmp_seq=72 ttl=255 time=3000 ms
64 bytes from 172.31.33.251: icmp_seq=76 ttl=255 time=0.368 ms
64 bytes from 172.31.33.251: icmp_seq=77 ttl=255 time=0.432 ms

他の宛先にも通信を行い、影響がないことを確認しました。

64 bytes from 172.31.38.127: icmp_seq=15 ttl=255 time=0.376 ms
64 bytes from 172.31.38.127: icmp_seq=16 ttl=255 time=0.406 ms
64 bytes from 172.31.38.127: icmp_seq=17 ttl=255 time=0.431 ms
64 bytes from 172.31.38.127: icmp_seq=18 ttl=255 time=0.404 ms

(省略)

64 bytes from 172.31.38.127: icmp_seq=71 ttl=255 time=0.529 ms
64 bytes from 172.31.38.127: icmp_seq=72 ttl=255 time=0.409 ms
64 bytes from 172.31.38.127: icmp_seq=73 ttl=255 time=0.400 ms
64 bytes from 172.31.38.127: icmp_seq=74 ttl=255 time=0.466 ms

ブラックホール攻撃

Gremlin Clientから出力する通信に、ドロップを注入してみます。以下の設定を行いました。

  • Category … Network
  • Atacks … Blackhole
  • Length … 攻撃の長さ(ここでは60秒)
  • IP Addresses … トラフィックの影響をうけるIP(ここでは172.31.33.251)

こちらのAttackが実行されている間、シーケンス(icmp_seq)5〜63がドロップされていることが確認できました。

[ec2-user@ip-172-31-34-232 ~]$ ping 172.31.33.251
PING 172.31.33.251 (172.31.33.251) 56(84) bytes of data.
64 bytes from 172.31.33.251: icmp_seq=1 ttl=255 time=0.741 ms
64 bytes from 172.31.33.251: icmp_seq=2 ttl=255 time=0.429 ms
64 bytes from 172.31.33.251: icmp_seq=3 ttl=255 time=0.608 ms
64 bytes from 172.31.33.251: icmp_seq=4 ttl=255 time=0.438 ms
64 bytes from 172.31.33.251: icmp_seq=64 ttl=255 time=0.511 ms
64 bytes from 172.31.33.251: icmp_seq=65 ttl=255 time=0.427 ms
64 bytes from 172.31.33.251: icmp_seq=66 ttl=255 time=0.408 ms
^C
--- 172.31.33.251 ping statistics ---
66 packets transmitted, 7 received, 89% packet loss, time 66553ms

パケットロス攻撃

Gremlin Clientから出力する通信に、パケット損失を実施してみます。以下の設定を行いました。

  • Category … Network
  • Atacks … Blackhole
  • Length … 攻撃の長さ(ここでは60秒)
  • IP Addresses … トラフィックの影響をうけるIP(ここでは172.31.33.251)
  • Percent … 30

こちらのAttackを実行すると、想定どおりの損失が確認できました。(実行前後でパケットを送信していたので、多少損失の割合が小さくなっている)

[ec2-user@ip-172-31-34-232 ~]$ ping 172.31.33.251
PING 172.31.33.251 (172.31.33.251) 56(84) bytes of data.
64 bytes from 172.31.33.251: icmp_seq=1 ttl=255 time=0.615 ms
64 bytes from 172.31.33.251: icmp_seq=2 ttl=255 time=0.493 ms
64 bytes from 172.31.33.251: icmp_seq=3 ttl=255 time=0.364 ms
64 bytes from 172.31.33.251: icmp_seq=4 ttl=255 time=0.567 ms
64 bytes from 172.31.33.251: icmp_seq=5 ttl=255 time=0.421 ms
64 bytes from 172.31.33.251: icmp_seq=6 ttl=255 time=0.408 ms
64 bytes from 172.31.33.251: icmp_seq=7 ttl=255 time=0.414 ms
64 bytes from 172.31.33.251: icmp_seq=9 ttl=255 time=0.565 ms
64 bytes from 172.31.33.251: icmp_seq=10 ttl=255 time=0.412 ms
64 bytes from 172.31.33.251: icmp_seq=11 ttl=255 time=0.477 ms
64 bytes from 172.31.33.251: icmp_seq=13 ttl=255 time=0.422 ms
64 bytes from 172.31.33.251: icmp_seq=14 ttl=255 time=0.478 ms
64 bytes from 172.31.33.251: icmp_seq=17 ttl=255 time=0.438 ms
64 bytes from 172.31.33.251: icmp_seq=19 ttl=255 time=0.529 ms
64 bytes from 172.31.33.251: icmp_seq=22 ttl=255 time=0.410 ms
64 bytes from 172.31.33.251: icmp_seq=24 ttl=255 time=0.381 ms
64 bytes from 172.31.33.251: icmp_seq=25 ttl=255 time=0.542 ms
64 bytes from 172.31.33.251: icmp_seq=27 ttl=255 time=0.404 ms
64 bytes from 172.31.33.251: icmp_seq=29 ttl=255 time=0.488 ms
64 bytes from 172.31.33.251: icmp_seq=30 ttl=255 time=0.493 ms
64 bytes from 172.31.33.251: icmp_seq=31 ttl=255 time=0.519 ms
64 bytes from 172.31.33.251: icmp_seq=32 ttl=255 time=0.420 ms
64 bytes from 172.31.33.251: icmp_seq=34 ttl=255 time=0.454 ms
64 bytes from 172.31.33.251: icmp_seq=36 ttl=255 time=0.448 ms
64 bytes from 172.31.33.251: icmp_seq=39 ttl=255 time=0.333 ms
64 bytes from 172.31.33.251: icmp_seq=40 ttl=255 time=0.408 ms
64 bytes from 172.31.33.251: icmp_seq=42 ttl=255 time=0.447 ms
64 bytes from 172.31.33.251: icmp_seq=44 ttl=255 time=0.524 ms
64 bytes from 172.31.33.251: icmp_seq=45 ttl=255 time=0.458 ms
64 bytes from 172.31.33.251: icmp_seq=46 ttl=255 time=0.432 ms
64 bytes from 172.31.33.251: icmp_seq=47 ttl=255 time=0.429 ms
64 bytes from 172.31.33.251: icmp_seq=48 ttl=255 time=0.395 ms
64 bytes from 172.31.33.251: icmp_seq=49 ttl=255 time=0.414 ms
64 bytes from 172.31.33.251: icmp_seq=50 ttl=255 time=0.413 ms
64 bytes from 172.31.33.251: icmp_seq=51 ttl=255 time=0.434 ms
64 bytes from 172.31.33.251: icmp_seq=52 ttl=255 time=0.438 ms
64 bytes from 172.31.33.251: icmp_seq=53 ttl=255 time=0.426 ms
64 bytes from 172.31.33.251: icmp_seq=54 ttl=255 time=0.423 ms
64 bytes from 172.31.33.251: icmp_seq=56 ttl=255 time=0.460 ms
64 bytes from 172.31.33.251: icmp_seq=57 ttl=255 time=0.479 ms
64 bytes from 172.31.33.251: icmp_seq=60 ttl=255 time=0.403 ms
64 bytes from 172.31.33.251: icmp_seq=61 ttl=255 time=0.429 ms
64 bytes from 172.31.33.251: icmp_seq=62 ttl=255 time=0.465 ms
64 bytes from 172.31.33.251: icmp_seq=63 ttl=255 time=0.460 ms
64 bytes from 172.31.33.251: icmp_seq=65 ttl=255 time=0.467 ms
64 bytes from 172.31.33.251: icmp_seq=66 ttl=255 time=0.442 ms
64 bytes from 172.31.33.251: icmp_seq=67 ttl=255 time=0.469 ms
64 bytes from 172.31.33.251: icmp_seq=68 ttl=255 time=0.470 ms
64 bytes from 172.31.33.251: icmp_seq=69 ttl=255 time=0.412 ms
64 bytes from 172.31.33.251: icmp_seq=70 ttl=255 time=0.394 ms
64 bytes from 172.31.33.251: icmp_seq=71 ttl=255 time=0.413 ms
64 bytes from 172.31.33.251: icmp_seq=72 ttl=255 time=0.399 ms
^C
--- 172.31.33.251 ping statistics ---
72 packets transmitted, 52 received, 27% packet loss, time 72710ms

DNS

Gremlin ClientからDNSサーバーに対するアクセスをブロックしてみます。以下の設定を行いました。

  • Category … Network
  • Atacks … DNS
  • Length … 攻撃の長さ(ここでは60秒)
  • IP Addresses … 影響を与えるDNSサーバのIP(ここでは172.31.0.2)

Attackの実行前にGremlin Clientからec2-18-179-6-97.ap-northeast-1.compute.amazonaws.comの名前解決ができることを確認しました。

[ec2-user@ip-172-31-34-232 ~]$ ping ec2-18-179-6-97.ap-northeast-1.compute.amazonaws.com
PING ec2-18-179-6-97.ap-northeast-1.compute.amazonaws.com (172.31.33.251) 56(84) bytes of data.
64 bytes from ip-172-31-33-251.ap-northeast-1.compute.internal (172.31.33.251): icmp_seq=1 ttl=255 time=4.60 ms
64 bytes from ip-172-31-33-251.ap-northeast-1.compute.internal (172.31.33.251): icmp_seq=2 ttl=255 time=0.377 ms
64 bytes from ip-172-31-33-251.ap-northeast-1.compute.internal (172.31.33.251): icmp_seq=3 ttl=255 time=0.428 ms

Attackを実行している間に名前解決を行うと、想定どおりのエラーとなりました。

[ec2-user@ip-172-31-34-232 ~]$ ping ec2-18-179-6-97.ap-northeast-1.compute.amazonaws.com
ping: ec2-18-179-6-97.ap-northeast-1.compute.amazonaws.com: Name or service not known

さいごに

Gremlinを利用してネットワーク障害を注入してみました。攻撃設定など、直感的に操作することができました。カオスエンジニアリングを検討している方は、いちどGremlinをお試ししてみてはいかがでしょうか。

参考