Created
February 25, 2015 03:30
-
-
Save cynipe/df7cbb7665f51df3168a to your computer and use it in GitHub Desktop.
Securing Github Webhook Endpoint with Nginx + Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 多分こんな感じでできる | |
local x_hub_signature = ngx.hader['X_Hub_Signature'] | |
local body = ngx.req.read_body | |
local expected_signature = 'sha1=' .. ngx.hmac_sha1(ngx.var.secret_token, body) | |
if expected_signature ~= x_hub_signature then | |
ngx.log(ngx.WARN, 'Invalid access detected') | |
ngx.header.content_type = 'text/plain' | |
ngx.status = ngx.HTTP_UNAUTHORIZED | |
ngx.print('401 Access Denied') | |
return | |
end | |
-- TODO execでいいのかしら? | |
ngx.exec('/jenkins') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment