MaxscaleでDatabase Firewall (マスキング編)
49日目
MaxscaleでDatabase Firewall (データベースファイアウォール編) - tsaekiのブログの続き。
マスキングを試してみます。特定のカラムの値をマスキングします。
サンプルのconfigurationです。
[Sample-Service] type=service router=readconnroute router_options=running servers=server1 user=maxscale password=maxscale_password filters=SampleMasking [SampleMasking] type=filter module=masking rules=/etc/maxscale.modules.d/sample-masking-rules.json
| 項目 | 値 | 備考 |
|---|---|---|
| rules | /etc/maxscale.modules.d/sample-masking-rules.json | マスキングするRuleファイル。設定内容は後述 |
Ruleファイル
概要
JSON形式で設定します。
replaceでどのカラムを、withでどのようなマスキングをするか、を設定します。
applies_toやexemptedでマスキングを適用するユーザ、適用しないユーザの設定ができます。
{
"rules": [
{
"replace": { ... },
"with": { ... },
"applies_to": [ ... ],
"exempted": [ ... ]
}
]
}
詳細は公式をご確認ください。
Ruleサンプル
$ cat /etc/maxscale.modules.d/sample-masking-rules.json
{
"rules": [
{
"replace": {
"column": "tel"
},
"with": {
"value": "xxx-xxxx-xxxx"
}
},
{
"replace": {
"column": "zip"
},
"with": {
"value": "xxx-xxxx"
}
},
{
"replace": {
"column": "credit_card_number"
},
"with": {
"fill": "*"
}
}
]
}
# Run
$ mysql -usample -h 127.0.0.1 -P 4008 -psample_password sampledb -e "SELECT * FROM users limit 10"
+-----+------------------+-----------------------------+----------+---------------+--------------------+
| id | name | email | zip | tel | credit_card_number |
+-----+------------------+-----------------------------+----------+---------------+--------------------+
| 101 | 杉山 結衣 | hidaka@gmail.com | xxx-xxxx | xxx-xxxx-xxxx | **************** |
| 102 | 渚 真綾 | minoru40@yahoo.com | xxx-xxxx | XXXXXXXXXXXX | **************** |
| 103 | 井上 修平 | taichikudo@hotmail.com | xxx-xxxx | XXXXXXXXXXXX | **************** |
| 104 | 中津川 和也 | nuno@yahoo.com | xxx-xxxx | XXXXXXXXXXXX | **************** |
| 105 | 杉山 春香 | mai42@gmail.com | xxx-xxxx | xxx-xxxx-xxxx | **************** |
| 106 | 三宅 桃子 | hirokawatomoya@hotmail.com | xxx-xxxx | xxx-xxxx-xxxx | **************** |
| 107 | 小林 英樹 | nagisaasuka@gmail.com | xxx-xxxx | xxx-xxxx-xxxx | *************** |
| 108 | 松本 学 | sugiyamaasuka@hotmail.com | xxx-xxxx | xxx-xxxx-xxxx | **************** |
| 109 | 加納 太一 | manabunomura@gmail.com | xxx-xxxx | xxx-xxxx-xxxx | ************ |
| 110 | 中津川 健一 | atsushimiyagawa@hotmail.com | xxx-xxxx | XXXXXXXXXXXX | **************** |
+-----+------------------+-----------------------------+----------+---------------+--------------------+
説明
zipはxxx-xxxxに置き換わる- ただし
123-4567のフォーマットに合わない場合はすべてXに置き換わる
- ただし
telはxxx-xxxx-xxxxに置き換わる- ただし
080-1111-1111のフォーマットに合わない場合はすべてXに置き換わる
- ただし
credit_card_numberは*に置き換わる