-
Notifications
You must be signed in to change notification settings - Fork 549
Fix bug: arbitrary file read in log manager & remove block io ops #5101
Changes from 7 commits
b854375
59e917e
111e45a
0be7734
4ae85ae
b8ed292
eac6957
14b9652
e130a54
50b20e7
c9ef18b
0137d65
fd38c2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
|
||
local cjson = require "cjson" | ||
local lfs = require "lfs" | ||
local path = require "path" | ||
|
||
local util = require "util" | ||
|
||
local function has_file_with_pattern(path, pattern) | ||
for file in lfs.dir(path) do | ||
|
@@ -24,10 +27,6 @@ local function has_file_with_pattern(path, pattern) | |
return false | ||
end | ||
|
||
local function is_dir(path) | ||
return lfs.attributes(path, "mode") == "directory" | ||
end | ||
|
||
local args = ngx.req.get_uri_args() | ||
local username = args["username"] | ||
local framework_name = args["framework-name"] | ||
|
@@ -43,19 +42,19 @@ end | |
|
||
local log_query_param = "?username="..username.."&framework-name="..framework_name.. | ||
"&pod-uid="..pod_uid.."&taskrole="..taskrole.."&token="..token | ||
local path = "/usr/local/pai/logs/"..username.."/".. framework_name.."/".. taskrole.."/"..pod_uid.."/" | ||
local log_dir = "/usr/local/pai/logs/"..username.."/".. framework_name.."/".. taskrole.."/"..pod_uid.."/" | ||
Gerhut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local path_prefix = "/api/v1/logs/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
local ret = {} | ||
|
||
if not is_dir(path) then | ||
if not util.is_path_under_log_folder(log_dir) or not path.isdir(log_dir) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you unify the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
ngx.log(ngx.ERR, "log folder not exists") | ||
ngx.status = ngx.HTTP_NOT_FOUND | ||
return ngx.exit(ngx.HTTP_OK) | ||
end | ||
|
||
for file in lfs.dir(path) do | ||
if not is_dir(path..file) then | ||
for file in lfs.dir(log_dir) do | ||
if not path.isdir(log_dir..file) then | ||
if string.match(file, "^user%.pai%..*$") then | ||
local sub_str = string.sub(file, string.len("user.pai.") + 1) | ||
ret[sub_str] = path_prefix..file..log_query_param | ||
|
@@ -65,7 +64,7 @@ for file in lfs.dir(path) do | |
elseif string.match(file, "^user-.*$") then | ||
local sub_str = string.sub(file, string.len("user-") + 1) | ||
ret[sub_str] = path_prefix..file..log_query_param | ||
if has_file_with_pattern(path..file, "^@.*%.s") then | ||
if has_file_with_pattern(log_dir..file, "^@.*%.s") then | ||
ret[sub_str..".1"] = path_prefix..file..".1"..log_query_param | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,8 +70,17 @@ server { | |
limit_except GET { | ||
deny all; | ||
} | ||
default_type text/plain; | ||
default_type application/octet-stream; | ||
Gerhut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
limit_rate_after 1m; | ||
limit_rate 1m; | ||
access_by_lua_file /etc/nginx/lua/guard.lua; | ||
content_by_lua_file /etc/nginx/lua/get_log_content.lua; | ||
} | ||
|
||
location @download_file { | ||
internal; | ||
|
||
root /; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this service serve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
try_files $uri =404; | ||
Gerhut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright (c) Microsoft Corporation | ||
-- All rights reserved. | ||
-- MIT License | ||
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
-- documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
-- the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
-- to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
-- THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
-- BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
local path = require "path" | ||
|
||
local function is_path_under_log_folder(log_path) | ||
local real_path = path.abspath(log_path) | ||
|
||
if not string.match(real_path, "^/usr/local/pai/logs/.*") then | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
return { | ||
is_path_under_log_folder = is_path_under_log_folder, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed