Linux の セキュリティチェックツールを探していて、
OpenSCAP というツール?があることを知りました。
OpenSCAPにはレポートHTMLファイルの生成機能があり、
Mezzanine の dashboardからこのレポートファイルへのリンクが貼れるか試してみましたので、
その結果を記載します。 1
[1] 正直個人ブログでしか使わない。or 個人ブログですら使わない。かもしれませんが。。
0. 前提
以下の環境で実行しています。
-
OS
CentOS release 6.7 (Final) -
Python Version
Python 2.7.8 -
Package (必要そうなものだけ抜粋)
Django (1.10)
Mezzanine (4.2.0)
1. OpenSCAPのインストール方法
以下の記事が参考になりました。
記載の手順でインストール レポート生成までできました。
2. やったこと
以下、dashboard に リンクを追加するために実施したことになります。
2-1. django application を作成する
DASHBOARD に表示する テンプレートタグの格納先となる。
django application を作成します。
-
アプリケーション作成
python2.7 manage.py startapp mezzanine_extentions
-
settings.py に アプリケーションを追加
INSTALLED_APPS = ( "mezzanine_extentions", ... )
2-2. OpenSCAP のレポートを生成する django command を作成する
cron で shellスクリプト実行がラクですが、
作成したアプリケーション下に、django command を作成、実行する形にしました。
相当手抜きな command になりましたが、以下の内容となりました。
-
mezzanine_extentions/management/commands/run_scap.py
# -*- coding: utf-8 -*- from __future__ import print_function from django.core.management.base import BaseCommand from django.conf import settings import subprocess class Command(BaseCommand): def handle(self, *args, **options): print ("-------------------------------------------") print ("run scap START") print ("-------------------------------------------") oscap_xccdf_cmds = [] oscap_xccdf_cmds.append("oscap") oscap_xccdf_cmds.append("xccdf") oscap_xccdf_cmds.append("eval") oscap_xccdf_cmds.append("--report") oscap_xccdf_cmds.append(settings.XCCDF_REPORTS_PATH) oscap_xccdf_cmds.append(settings.XCCDF_FILE_PATH) d = subprocess.check_output(oscap_xccdf_cmds) print(d) oscap_oval_cmds = [] oscap_oval_cmds.append("oscap") oscap_oval_cmds.append("oval") oscap_oval_cmds.append("eval") oscap_oval_cmds.append("--report") oscap_oval_cmds.append(settings.OVAL_REPORTS_PATH) oscap_oval_cmds.append(settings.OVAL_FILE_PATH) d = subprocess.check_output(oscap_oval_cmds) print(d) print ("--------------------------------------------") print ("run scap END") print ("-------------------------")
-
補足
-
作成には、以下の記事を参考にしました。
[Python2.7] subprocess の使い方まとめ - Qiita -
OpenSCAP の定義ファイルパスとレポートパスはsettings.pyから指定するようにしました。
-
2-4. テンプレートタグと、テンプレートHTMLの作成
-
mezzanine_extentions/templatetags/mezzanine_extentions_tags.py 静的リンクのみなので、何もしないテンプレートです。
from __future__ import unicode_literals from mezzanine import template register = template.Library() @register.inclusion_tag("admin/includes/mezzanine_extentions_scap.html") def scap(): """ Dashboard widget for displaying a reports link. """ pass
-
mezzanine_extentions/templates/admin/includes/mezzanine_extentions_scap.html 特に翻訳ファイルを作ったわけではないですが、
{% trans %}
テンプレートタグ でリンク名称を記載しました。
div
タグに指定しているclass="module"
は他のdashboardのテンプレート内で使われているタグになります。
このタグ内のh2
、h3
はそれぞれ背景色が変わります。
{% load i18n mezzanine_tags %} <div class="module" id="scap_module"> <h2>SCAP reports</h2> <h3><a href="{% url 'oval_report' %}">{% trans "OVAL reports" %}</a></h2> <h3><a href="{% url 'xccdf_report' %}">{% trans "XCCDF reports" %}</a></h2> </div>
2-5. views.pyの作成
- mezzanine_extentions/views.py
@staff_member_required
デコレータで、ログインしている人しか、
閲覧不可としました。
静的HTMLの取得方法はいい方法がわからず、レポートファイルをopenして、
取得した結果をそのままHttpResonse
で返すようにしました。
from django.http import HttpResponse from django.contrib.admin.views.decorators import staff_member_required from django.conf import settings # Create your views here. @staff_member_required def oval_report(request): html = open(settings.OVAL_REPORTS_PATH, "r").read() return HttpResponse(html) @staff_member_required def xccdf_report(request): html = open(settings.XCCDF_REPORTS_PATH, "r").read() return HttpResponse(html)
2-6 urls.pyの作成
- urls.py
from __future__ import unicode_literals from django.conf.urls import url from mezzanine_extentions import views urlpatterns = [ url("^oval_report/$", views.oval_report, name="oval_report"), url("^xccdf_report/$", views.xccdf_report, name="xccdf_report"), ]
2-7 mezzanine の settings.py と、urls.py の編集
-
settings.py の “mezzanine_extentions_tags.scap を追加
DASHBOARDには、3列表示されています。
2列目に追加しました。
DASHBOARD_TAGS = ( ("mezzanine_tags.app_list",), ("admin_backup_tags.admin_backup", "mezzanine_extentions_tags.scap", "comment_tags.recent_comments",), ("mezzanine_tags.recent_actions",),)
-
url.py に 作成したアプリケーションのurl include を追加
import mezzanine_extentions.urls urlpatterns += i18n_patterns(url("^xyz_monotalk_admin/", include(mezzanine_extentions.urls))
あとはスケジューラで、コマンドを日次で実行するようにして終わりです。
やったことは以上です。
3. HTTP サーバーを再起動して、ログイン
HTTPサーバーを再起動して、mezzanineの管理画面にログインします。
2列目にSCAP reports が表示されます。
リンクをクリックすると、以下のようなレポートが表示されます。
管理者だけが見れるとかにしたい思いはあります。
ロールを作ったりすれば、できそうな気はします。
以上です。
コメント