Skip to content

Conversation

@Firstsawyou
Copy link
Contributor

@Firstsawyou Firstsawyou commented Jan 8, 2021

What this PR does / why we need it:

Cause of the bug: After APISIX is started, the worker process has the authority of nobody ordinary user. When APISIX is in the /root directory, ordinary users do not have the authority to access the /root directory. Therefore, when APISIX is started, the error log error.log will show the following error message:

init_worker_by_lua error: /root/apisix-2.1/apisix/init.lua:89: module 'resty.worker.events' not found:
        no field package.preload['resty.worker.events']
        no file '/root/apisix-2.1//deps/share/lua/5.1/resty/worker/events.lua'
        no file '/root/apisix-2.1//deps/share/lua/5.1/resty/worker/events/init.lua'
        no file '/root/apisix-2.1/resty/worker/events.lua'
        no file '/root/apisix-2.1/resty/worker/events/init.lua'

The solution: it is forbidden to execute make run in the /root directory to run apisix.

close #3207

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

Makefile Outdated
@echo "Non-zero exit status: 1"
@echo "Error, It is forbidden to run APISIX in the /root directory."
@echo "Error: It is forbidden to run APISIX in the /root directory."
@exit 1
Copy link
Member

Choose a reason for hiding this comment

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

We need to add a test for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how to add test cases for Makefile. Can you give me some suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

See

out=$(make init 2>&1 || true)

Copy link
Contributor Author

@Firstsawyou Firstsawyou Jan 8, 2021

Choose a reason for hiding this comment

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

Ok, got it.

@moonming
Copy link
Member

moonming commented Jan 9, 2021

I don't think this method can completely solve the permission problem. Can an error be thrown if the code file cannot be found in the init phase of apisix?

@Firstsawyou
Copy link
Contributor Author

I don't think this method can completely solve the permission problem. Can an error be thrown if the code file cannot be found in the init phase of apisix?

There will be no errors when executing make init. Only when make run is executed, it will cause an error that dependent files cannot be found. Therefore, I think prohibiting the execution of make run under /root can solve this problem.

Makefile Outdated
.PHONY: run
run: default
ifeq ("$(wildcard logs/nginx.pid)", "")
ifeq ("$(findstring /root, ${PWD})", "/root")
Copy link
Member

Choose a reason for hiding this comment

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

We need a thorough solution, not a temporary patch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.


local function start(env, ...)
if env.is_root_path then
util.die("Error: It is forbidden to run APISIX in the /root directory.\n")
Copy link
Member

Choose a reason for hiding this comment

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

I think you don’t understand the permissions issues under Linux at all

Copy link
Member

Choose a reason for hiding this comment

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

the current way is right, but it is hard to read. @Firstsawyou please add some comment here.

image

Copy link
Member

Choose a reason for hiding this comment

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

any news? @Firstsawyou

Copy link
Contributor Author

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.

Cause of the bug: After APISIX is started, the worker process has the authority of nobody ordinary user. When APISIX is in the /root directory, ordinary users do not have the authority to access the /root directory. Therefore, when APISIX is started, the error log error.log will show the following error message:

init_worker_by_lua error: /root/apisix-2.1/apisix/init.lua:89: module 'resty.worker.events' not found:
        no field package.preload['resty.worker.events']
        no file '/root/apisix-2.1//deps/share/lua/5.1/resty/worker/events.lua'
        no file '/root/apisix-2.1//deps/share/lua/5.1/resty/worker/events/init.lua'
        no file '/root/apisix-2.1/resty/worker/events.lua'
        no file '/root/apisix-2.1/resty/worker/events/init.lua'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any news? @Firstsawyou

updated.

t/cli/cli.t Outdated
=== TEST 2: It is forbidden to run APISIX under the /root directory(is_root_path is true).
Copy link
Member

Choose a reason for hiding this comment

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

we should use shell script to test this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.


local function start(env, ...)
if env.is_root_path then
util.die("Error: It is forbidden to run APISIX in the /root directory.\n")
Copy link
Member

Choose a reason for hiding this comment

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

the current way is right, but it is hard to read. @Firstsawyou please add some comment here.

image

@membphis
Copy link
Member

@Firstsawyou CI failed, please fix it first

@Firstsawyou
Copy link
Contributor Author

@Firstsawyou CI failed, please fix it first

Okay, I will fix it later.


local function start(env, ...)
if env.is_root_path then
util.die("Error: It is forbidden to run APISIX in the /root directory.\n")
Copy link
Member

Choose a reason for hiding this comment

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

any news? @Firstsawyou

@Firstsawyou Firstsawyou changed the title chore: it is forbidden to execute make run in the /root directory to run apisix. fix: APISIX runs in the /root directory and reports errors Jan 13, 2021
@Firstsawyou Firstsawyou requested a review from membphis January 13, 2021 03:31
@membphis
Copy link
Member

ping @moonming

@spacewander spacewander merged commit a815391 into apache:master Jan 19, 2021
@Firstsawyou Firstsawyou deleted the IssueNum3207 branch April 12, 2021 01:36
@ccxhwmy
Copy link
Contributor

ccxhwmy commented Jul 3, 2022

I think this only solves the permission problem of apisix deployed under /root, if I deploy it under /home/work1 and I use work2 as user, the problem still exists.

@tzssangglass
Copy link
Member

I think this only solves the permission problem of apisix deployed under /root, if I deploy it under /home/work1 and I use work2 as user, the problem still exists.

Obviously, this PR solves the problem that APISIX runs under /root.

Please submit a new issue describing your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apisix-2.1/apisix/init.lua:89: module 'resty.worker.events' not found:

6 participants