Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Fix bug: arbitrary file read in log manager & remove block io ops #5101

Merged
merged 13 commits into from
Nov 27, 2020

Conversation

Binyang2014
Copy link
Contributor

No description provided.

@Binyang2014 Binyang2014 requested a review from abuccts November 19, 2020 10:29
@coveralls
Copy link

coveralls commented Nov 19, 2020

Coverage Status

Coverage remained the same at 33.999% when pulling fd38c2f on binyli/security-log into 9c11f48 on master.

@Binyang2014
Copy link
Contributor Author

Fix: #5119

@Binyang2014 Binyang2014 requested a review from Gerhut November 23, 2020 11:53
src/log-manager/src/nginx/nginx.conf.default Outdated Show resolved Hide resolved
src/log-manager/src/nginx/list_logs.lua Outdated Show resolved Hide resolved
Comment on lines 30 to 37
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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/"
Copy link
Member

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 /;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Binyang2014 Binyang2014 changed the title Fix bug: arbitrary file read in log manager Fix bug: arbitrary file read in log manager & remove block io ops Nov 26, 2020
@Binyang2014 Binyang2014 merged commit 1f3d691 into master Nov 27, 2020
@Binyang2014 Binyang2014 deleted the binyli/security-log branch November 27, 2020 06:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants