-
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
Conversation
Fix: #5119 |
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 |
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
ngx.log(ngx.ERR, log_path.." not exists") | ||
ngx.status = ngx.HTTP_NOT_FOUND | ||
return ngx.exit(ngx.HTTP_OK) | ||
end | ||
|
||
local logs | ||
if (tail_mode == "true") then | ||
logs = io.popen("tail -c 16k "..log_path) | ||
ngx.req.set_uri(log_path) |
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.
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.
We can not fix this issue. Just check the url to make sure it's validate
local path_prefix = "/api/v1/logs/" | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
could you unify the name folder
and dir
, and differ from path
?
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
@@ -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.."/" | |||
local path_prefix = "/api/v1/logs/" |
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.
file_prefix
?
internal; | ||
add_header Accept-Ranges bytes; | ||
|
||
root /; |
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.
could this service serve /usr/local/pai/logs/
directory only, and remove this prefix when processing?
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
576296e
to
0137d65
Compare
No description provided.