1. Memcached + SELinux engine
OSS開発勉強会-06
KaiGai Kohei (@kkaigai)
<kaigai@kaigai.gr.jp>
OSS Development Study Meeting-06 1
2. Memcachedの特徴
Key-Valueストア
<Key>に対応する<Value>を保存/取得するだけの機能
トランザクション、検索式、型定義...など無い! 速さこそ正義
分散システム
Memcachedサーバ自体に一切の分散機能は無い
ライブラリがKey値に応じたMemcachedサーバを選択して接続
memcached プロトコル
テキストベースのシンプルなプロトコル
http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
多くの互換Key-Valueストア
Tokyo Tyrant, Repocached, Flared, KumoFS, ...
OSS Development Study Meeting-06 2
3. Memcachedシステムイメージ
Web-Server
User
Web-Apps PostgreSQL
ライブラリが接続先の
ライブラリが接続先の
Memcachedサーバを選択
Memcachedサーバを選択 libmemcached
Memcached
個々のMemcachedサーバは
個々のMemcachedサーバは
互いに独立にKey-Valueペアを
互いに独立にKey-Valueペアを
格納する
格納する
OSS Development Study Meeting-06 3
4. Memcached 内部構造
GET aaa get_item()
Key-Value
‘xyzxyz’ プロトコル処理部 hash_item * ストレージ
Key-Value
ストレージ
libevent with
New Feature
プロトコル解析部
Key-Valueストレージ
これ、Key-Valueストレージの部分を
モジュール化できるよね?
OSS Development Study Meeting-06 4
5. Memcached Engine (1/2)
Engine Interface v1
次期メジャーバージョン(v1.6.x系)の新機能
typedef struct engine_interface_v1 {
:
/**
* Retrieve an item.
*
* @param handle the engine handle
* @param cookie The cookie provided by the frontend
* @param item output variable that will receive the located item
* @param key the key to look up
* @param nkey the length of the key
* @param vbucket the virtual bucket id
* こんな感じでInterfaceが
こんな感じでInterfaceが
* @return ENGINE_SUCCESS if all goes well 定義されている
定義されている
*/
ENGINE_ERROR_CODE (*get)(ENGINE_HANDLE* handle,
const void* cookie,
item** item,
const void* key,
const int nkey,
uint16_t vbucket);
OSS Development Study Meeting-06 5
8. Memcached and Security
(3) Not run as root
(3) Not run as root
Memcached
(2) SASL auth,
(2) SASL auth, (1) Firewalling,
ififneeded Web Apps (1) Firewalling,
needed always
always
Web Server
できる事はほとんど何もない
絶対に外部ネットワークから接続可能にしちゃダメ
一応、SASL認証で接続の可否を決める事はできる
あと、root権限で走らせてはならない
Memcached Security; by Dustin Sallings
http://dustin.github.com/2010/08/08/memcached-security.html
OSS Development Study Meeting-06 8
9. SELinuxによるアクセス制御
“機密” 情報は、どこに格納
SELinux
Security しても“機密”情報として扱う
Policy
Filesystem
Networks
classified unclassified
information information
memcached RDBMS
domain of inter process domain of
classified processes communication channels unclassified processes
OSS Development Study Meeting-06 9
16. selinux.c
アクセス制御を行う関数群
interface.c 内の各メソッドから呼び出され、
SELinuxにアクセス制御の問い合わせを行う。
‘denied’の結果が返却されれば、ERROR_EACCESSを呼出し元に返す
Access Vector Cache (AVC)を用いて、システムコール回数を最小化
Query
mselinux_check_write()
Access Control Decision
avc_has_perms()
ERROR_SUCCESS
or Yes
on cache?
ERROR_EACCESS
No security
policy
security_compute_av()
System-Call SELinux
OSS Development Study Meeting-06 16
17. ベンチマーク
default
default selinux
selinux
IPsec(ESP)
IPsec(ESP)
191,409
191,409
IPsec(AH)
IPsec(AH)
251,485
251,485
No IPsec
No IPsec
00 100000
100000 200000
200000 300000
300000
number of commands in 30sec
number of commands in 30sec
Iteration of GET/SET mixture, 8threads-client, 4core server x 2, Gb-ether
Less significant differences in same network environment
Penalties in IPsec(AH) communication (~20%?)
OSS Development Study Meeting-06 17