From 439f4309a4c3dbd97235e78972ccbd9985e956a6 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 4 Jun 2021 13:23:07 +0200 Subject: [PATCH] move registry tracking to separate file --- docker/nginx/conf.d/client.conf | 20 +------------------- docker/nginx/conf.d/include/track-registry | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 docker/nginx/conf.d/include/track-registry diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index c155ca5d..eb54c2eb 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -253,6 +253,7 @@ server { location /skynet/registry { include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/sia-auth; + include /etc/nginx/conf.d/include/track-registry; limit_req zone=registry_access_by_ip burst=600 nodelay; limit_req zone=registry_access_by_ip_throttled burst=200 nodelay; @@ -274,25 +275,6 @@ server { end end } - - # register the registry access in accounts service (cookies should contain jwt) - log_by_lua_block { - -- this block runs only when accounts are enabled - if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end - - if ngx.status == ngx.HTTP_OK or ngx.status == ngx.HTTP_NOT_FOUND then - local http = require("socket.http") - local method = ngx.req.get_method() == ngx.HTTP_GET and "read" or "write" - local ok, statusCode, headers, statusText = http.request { - url = "http://accounts:3000/track/registry/" .. method, - method = "POST", - headers = ngx.req.get_headers() - } - if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then - ngx.log(ngx.ERR, "accounts endpoint /track/registry/" .. method .. " failed with error " .. statusCode) - end - end - } } location /skynet/skyfile { diff --git a/docker/nginx/conf.d/include/track-registry b/docker/nginx/conf.d/include/track-registry new file mode 100644 index 00000000..a8324f3b --- /dev/null +++ b/docker/nginx/conf.d/include/track-registry @@ -0,0 +1,18 @@ +# register the registry access in accounts service (cookies should contain jwt) +log_by_lua_block { + -- this block runs only when accounts are enabled + if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end + + if ngx.status == ngx.HTTP_OK or ngx.status == ngx.HTTP_NOT_FOUND then + local http = require("socket.http") + local method = ngx.req.get_method() == ngx.HTTP_GET and "read" or "write" + local ok, statusCode, headers, statusText = http.request { + url = "http://accounts:3000/track/registry/" .. method, + method = "POST", + headers = ngx.req.get_headers() + } + if statusCode ~= ngx.HTTP_NO_CONTENT and statusCode ~= ngx.HTTP_UNAUTHORIZED then + ngx.log(ngx.ERR, "accounts endpoint /track/registry/" .. method .. " failed with error " .. statusCode) + end + end +}