1. OSS Development Study Meeting-06 1
Memcached + SELinux engine
OSS開発勉強会-06
KaiGai Kohei (@kkaigai)
<kaigai@kaigai.gr.jp>
2. OSS Development Study Meeting-06 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, ...
3. OSS Development Study Meeting-06 3
Memcachedシステムイメージ
Web-Apps
libmemcached
Web-Server
Memcached
PostgreSQL
User
ライブラリが接続先の
Memcachedサーバを選択
ライブラリが接続先の
Memcachedサーバを選択
個々のMemcachedサーバは
互いに独立にKey-Valueペアを
格納する
個々のMemcachedサーバは
互いに独立にKey-Valueペアを
格納する
4. OSS Development Study Meeting-06 4
Memcached 内部構造
プロトコル解析部
Key-Valueストレージ
これ、Key-Valueストレージの部分を
モジュール化できるよね?
libevent
プロトコル処理部
Key-Value
ストレージ
Key-Value
ストレージ
with
New Feature
get_item()
hash_item *
GET aaa
‘xyzxyz’
5. OSS Development Study Meeting-06 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
*
* @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);
こんな感じでInterfaceが
定義されている
こんな感じでInterfaceが
定義されている
8. OSS Development Study Meeting-06 8
Memcached and Security
できる事はほとんど何もない
絶対に外部ネットワークから接続可能にしちゃダメ
一応、SASL認証で接続の可否を決める事はできる
あと、root権限で走らせてはならない
Memcached Security; by Dustin Sallings
http://dustin.github.com/2010/08/08/memcached-security.html
Memcached
Web Server
Web Apps (1) Firewalling,
always
(1) Firewalling,
always
(2) SASL auth,
if needed
(2) SASL auth,
if needed
(3) Not run as root(3) Not run as root
9. OSS Development Study Meeting-06 9
SELinuxによるアクセス制御
domain of
classified processes
domain of
unclassified processes
inter process
communication channels
Filesystem
classified
information
unclassified
information
Networks
memcached RDBMS
SELinux
Security
Policy
“機密” 情報は、どこに格納
しても“機密”情報として扱う
16. OSS Development Study Meeting-06 16
selinux.c
アクセス制御を行う関数群
interface.c 内の各メソッドから呼び出され、
SELinuxにアクセス制御の問い合わせを行う。
‘denied’の結果が返却されれば、ERROR_EACCESSを呼出し元に返す
Access Vector Cache (AVC)を用いて、システムコール回数を最小化
mselinux_check_write()
avc_has_perms()
on cache?
security_compute_av()
SELinux
security
policy
Yes
No
System-Call
AccessControlDecision
ERROR_SUCCESS
or
ERROR_EACCESS
Query
17. OSS Development Study Meeting-06 17
ベンチマーク
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%?)
0 100000 200000 300000
No IPsec
IPsec(AH)
IPsec(ESP)
number of commands in 30sec
default selinux
0 100000 200000 300000
No IPsec
IPsec(AH)
IPsec(ESP)
number of commands in 30sec
default selinux
251,485251,485
191,409191,409