1. 利用アプリケーション
• 各サブドメイン毎に利用可能なアプリケーションが異なる
•申込時に選択
• 後に追加・削除が可能
• lua から以下の制御を行う
• 利用不能なアプリケーションへのアクセスは拒否する
• 利用可能なアプリケーションへのアクセスは適切なアプリケーション
サーバにリバースプロキシする
27
nginx
hagi.cybozu.com
fukaya-coop.cybozu.com
garoon
AP
kinton
eAP
g
k
28.
利用アプリケーション動的化実装例
28
location / {
rewrite_by_lua‘
if use_garoon then
ngx.exec(“/proxy/garoon”)
end
if use_kintone the
ngx.exec(“/proxy/kintone”)
end
ngx.exit(ngx.HTTP_NOT_FOUND)
‘;
}
location /proxy/garoon {
proxy_pass http://garoon-ap/;
}
location /proxy/kintone {
proxy_pass http://kintone-ap/;
}
lua によるアプリケー
ション利用可否と振り分
けロジック
リバースプロキシ用の
location
29.
利用アプリケーション動的化実装例
29
location / {
rewrite_by_lua‘
if use_garoon then
ngx.exec(“/proxy/garoon”)
end
if use_kintone the
ngx.exec(“/proxy/kintone”)
end
ngx.exit(ngx.HTTP_NOT_FOUND)
‘;
}
location /proxy/garoon {
proxy_pass http://garoon-ap/;
}
location /proxy/kintone {
proxy_pass http://kintone-ap/;
}
• 予め DB ファイルの内容を lua
の変数に読み込んでおく
• アプリケーションが利用可能な
らリバースプロキシ用の
location に internal redirect す
る
30.
利用アプリケーション動的化実装例
30
location / {
rewrite_by_lua‘
if use_garoon then
ngx.exec(“/proxy/garoon”)
end
if use_kintone the
ngx.exec(“/proxy/kintone”)
end
ngx.exit(ngx.HTTP_NOT_FOUND)
‘;
}
location /proxy/garoon {
proxy_pass http://garoon-ap/;
}
location /proxy/kintone {
proxy_pass http://kintone-ap/;
}
• 予め DB ファイルの内容を lua
の変数に格納しておく
• アプリケーションが利用可能な
らリバースプロキシ用の
location に internal redirect す
る
• 利用可能なアプリケーションが
なければ 404 エラーをクライ
アントに返す
31.
2. IP アドレス制限
•標準モジュールではアクセス毎動的に設定を変更することが出
来ない
• lua で IP アドレス制限を実装した
31
• 192.168.0.1
• 192.168.0.2
• 172.16.0.1
fukaya-coop
192.168.0.1
192.168.0.3
32.
IP アドレス制限の実装
32
function authenticate_remote_addr(allows)
localbit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
33.
IP アドレス制限の実装
33
function authenticate_remote_addr(allows)
localbit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
nginx の内部変数からクライア
ント IP アドレスを取得する
34.
IP アドレス制限の実装
34
function authenticate_remote_addr(allows)
localbit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
データベースファイルから読み込んだ
許可リストと比較してアクセス可否を
判定