はじめに
SoftLayerのカスタマーポータルは、権限を持っているユーザーでログインしてしまえば、注文でもキャンセルでもパスワードの閲覧もできてしまいます。よって、カスタマーポータルに対して、
- どの時間帯にどんなユーザーがどこからアクセスしているか
- 攻撃と思われるようなアクセス試行がされていないか(大量のログイン失敗が発生していないか)
などを知り、不正な攻撃を受けていないかどうかを確認することはセキュリティ管理の上で重要なことだと考える方がいらっしゃるかもしれません。そういう攻撃対象のユーザーは、場合によっては一時的に使用不可にするなどといった対処も必要になるでしょう。今回は、そういった履歴情報を取得するためのサンプルスクリプトを作ってみたので紹介します。
(参考)ステータスの変更方法
Account -> Users -> (対象ユーザー)にて、Status欄を変更します。
Active/Disabled/Inactive/VPN Onlyの意味は、以下のリンクに記載されています。
http://knowledgelayer.softlayer.com/faq/what-are-available-categories-users-status-within-customer-portal
アクセス履歴取得スクリプトサンプル
getPortalAuditLogs.py
import SoftLayer
from prettytable import PrettyTable
client = SoftLayer.create_client_from_env()
table = PrettyTable(['Login Time',
'User Name',
'First Name',
'Last Name',
'Current Status',
'From IP',
'Auth Result'])
_filter={
'loginAttempts': {
'createDate': {
'operation': 'betweenDate',
'options': [
{'name': 'startDate', 'value': ['01/24/2015 00:00:00']},
{'name': 'endDate', 'value': ['01/24/2015 23:59:59']}
]
}
}
}
users=client['Account'].getUsers(mask='id,firstName,lastName,userStatus')
for user in users:
loginAttempts = client['User_Customer'].getLoginAttempts(id=user['id'], filter=_filter)
loginAttempts = sorted(loginAttempts, key= lambda x: x['createDate'], reverse=False)
for loginAttempt in loginAttempts:
table.add_row([
loginAttempt['createDate'],
loginAttempt['username'],
user['firstName'],
user['lastName'],
user['userStatus']['name'],
loginAttempt['ipAddress'],
loginAttempt['successFlag']
])
print(table)
出力結果
以下注意点
- ユーザーごとに、アクセス日時順で並べています。ユーザーの数だけgetLoginAttemptsが呼び出されるので、ユーザー数が多い場合は、検索範囲を変更したり(もともとあまり広範囲にしない方が良い)、現在Activeなユーザーだけ探索するというのも1つの方法だと思います。
- 範囲指定で'01/24/2015 00:00:00'~'01/24/2015 23:59:59'にしているにも関わらず、1/25のデータが取得されている理由は、このAPIでの範囲指定がGMT-6:00を基準とされているからだと思われます。以下の記事も併せてご一読下さい。
http://qiita.com/testnin2/items/aa3c735977d602350d8a