
BIG-IPのiRulesデバッグ その2!
こんにちは、Anti-Patternの塚本です。
今回は、バグ修正時にやってしまったアンチパターンを書こうと思います!
httpリダイレクトの場合にロケーションヘッダのURLをhttp://からhttps://に書き換えるiRuleです
その他にこの様な条件があります
・FQDN、IPアドレスのどちらかでアクセスされる
・IPアドレスは、Data Group Listに定義されている
修正前
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
if { [string tolower [URI::host [HTTP::header Location]]] contains "testsystem.com" or
[class match [URI::host [HTTP::header Location]] contains target_group_list ] and
[URI::protocol [HTTP::header Location]] equals "http"} {
HTTP::header replace Location [string replace [HTTP::header Location] 0 3 https]
}
}
}
修正後)
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
if { ([string tolower [URI::host [HTTP::header Location]]] contains "testsystem.com" ) or
[class match [URI::host [HTTP::header Location]] contains target_group_list ] and
[URI::protocol [HTTP::header Location]] equals "http"} {
HTTP::header replace Location [string replace [HTTP::header Location] 0 3 https]
}
}
}修正した箇所はここになります。(host or target_group_list) and protocol
動作確認iRule
検証環境で動作確認をしました。
IPアドレス(192.168.10.10)でアクセスしてみると、ロケーションヘッダがhttps://となって正常に通信ができてます。これが失敗すると、https://→http://となり、ブラウザが混合コンテンツと判定しアクセスがブロックされます。
次に、FQDN(https://testsystem.com)でアクセスしてみます。
あれ? エラーだ
TCL error: /Common/redirect_test <HTTP_RESPONSE>
- bad IP network address format (line 1)invalid IP match item testsystem.com for IP class /Common/target_group_list (line 1)
invoked from within "class match [URI::host [HTTP::header Location]] equals target_group_list "target_group_listの値で判定する処理は変えてないんだけど・・・
Data Group Listの設定値を確認すると
ltm data-group internal target_group_list {
records {
192.168.10.10/32 { }
}
**type ip**}あれ?typeがip(IPアドレス型)だ。
再修正
FQDNでアクセスされた場合に、target_group_listとの突合は型が異なるのできませんでした。なので、IPアドレスを指定してアクセスされたかどうか、条件分岐を入れました。
IPアドレス判定はこのサイトを参考にしてますhttps://www.javadrive.jp/regex-basic/sample/index4.html
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
if { [string tolower [URI::host [HTTP::header Location]]] contains "testsystem.com" and [URI::protocol [HTTP::header Location]] equals "http"} {
HTTP::header replace Location [string replace [HTTP::header Location] 0 3 https]
}
set host [string tolower [URI::host [HTTP::header Location]]]
if { $host matches_regex {^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$}} {
if { [class match $host contains target_group_list] and [URI::protocol [HTTP::header Location]] equals "http"} {
HTTP::header replace Location [string replace [HTTP::header Location] 0 3 https]
}
}
}
}FQDN、IPアドレス共に期待通りの挙動となりました。
おしまい!
だと良かったんですが、
嫌な予感がしたので本番環境の設定値を確認すると・・
ltm data-group internal target_group_list {
records {
192.168 { }
}
type string
}あ・・・ type stringね。値もちがうし。そして、最初の修正でよくね?
まとめ
検証環境のData Group List定義を本番環境に合わせて、最初のiRuleで動作確認し、問題ありませんでした。
今回の対応は、早く終わらせたかったのでやっちゃいましたが、
あれ?typeがip(IPアドレス型)だ。
この時に、本番環境を確認してれば再修正の時間は不要だったはずです。
この環境差異については、“ムムムッ”となるところですが、
慌てた自分に反省しつつ、年の瀬を感じる今日この頃です。