OpenGamePanel / OGP-Agent-Linux

GNU General Public License v2.0
85 stars 33 forks source link

(Run Game Servers Under Different Users) - owner and group permissions #47

Closed TAPL-93 closed 1 year ago

TAPL-93 commented 1 year ago

Hi,

The update to run the game servers under different users lead to issue with the game server files permissions.

OS Ubuntu 22.04 - PHP 8.1 / latest OGP version as of today 21 April 2023.

1- Create "Multi Theft Auto" game server. 2- Use the option (Rsync Instal). 3- At this point all of the game server files have the owner and group permissions set to "ogp_agent ogp_agent". Screenshot_1 4- Files can be edited, renamed, moved, deleted using File Manager. Screenshot_2 5- Start the game server. 6- Check the game server files owner and group permissions, they are mixed to "gamehome1 gamehome1" and "gamehome1 ogp_agent": Screenshot_3 Files with "gamehome1 gamehome1" can't be edited with the displayed error "Failed to write file to remote server.", files with permissions "gamehome1 ogp_agent" can be edited without issue. Screenshot_4 7- Restart the game server, the permissions will be switched to "gamehome1 ogp_agent". Screenshot_5 8- Any files that are created by the game server process will have the permissions "gamehome1 gamehome1" which cannot be edited, renamed, moved, deleted using File Manager until the game server is restarted. Screenshot_6

Zorrototo commented 1 year ago

File permissions are fixed on server start. If game server creates files, their permission may indeed be given to the user only and not the Agent group. However, starting the server again should get all new file the proper permission for you to work with in the Panel. I don't think this is an issue, this is how it should work I guess.

TAPL-93 commented 1 year ago

It wouldn't make sense to have files that are supposedly accessible via the file manager but can't take any actions until you start/stop the server.

i think the files permissions should be fixed during the game server files installation with any of the available options such as rsync or manually installation, in additional it would make more sense to have the file permissions verify and fixed during the execution of the selected action to avoid a case where you select a file and try to remove or rename it but nothing happen. Screenshot_7

own3mall commented 1 year ago

What are the permissions set to on the files that you can't edit via the panel when the ownership is gamehome1:gamehome1? The ogp_agent user is added as a group member of each created (gamehomex) user. Assuming the group has read and write permissions on the file in question, it should be editable.

TAPL-93 commented 1 year ago

What are the permissions set to on the files that you can't edit via the panel when the ownership is gamehome1:gamehome1? The ogp_agent user is added as a group member of each created (gamehomex) user. Assuming the group has read and write permissions on the file in question, it should be editable.

You're right, however it require ogp agent restart every time a new game server is created which will create a separated user for that game server (gamehomex) but seems like some of the permissions is only set after ogp agent restart. so that would be the issue.

1- Create "Multi Theft Auto" game server x1. 2- Use the option (Rsync Instal). 3- Start the game server. 4- File Manager -> /home/ogp_agent/OGP_User_Files/1/mods/deathmatch -> try to edit settings.xml -> Failed to write file to remote server. 5- Restart ogp agent. 6- File Manager -> /home/ogp_agent/OGP_User_Files/1/mods/deathmatch -> try to edit settings.xml -> Changes saved successfully.

1- Create "Multi Theft Auto" game server x2. 2- Use the option (Rsync Instal). 3- Start the game server. 4- File Manager -> /home/ogp_agent/OGP_User_Files/2/mods/deathmatch -> try to edit settings.xml -> Failed to write file to remote server. 5- Restart ogp agent. 6- File Manager -> /home/ogp_agent/OGP_User_Files/2/mods/deathmatch -> try to edit settings.xml -> Changes saved successfully.

Zorrototo commented 1 year ago

The files you're trying to edit did not exist before you start the server from what I understand, so to me it is expected that they only have the user permission. The game server process create these files when you start the server. Files taken from Rsync seem to have proper rights to be editable. Am I right?

TAPL-93 commented 1 year ago

The files you're trying to edit did not exist before you start the server from what I understand, so to me it is expected that they only have the user permission. The game server process create these files when you start the server. Files taken from Rsync seem to have proper rights to be editable. Am I right?

Skip that part, the issue as i said in my previous reply, files with ownership gamehomeX:gamehomeX is not editable until the ogp agent is restarted.

Zorrototo commented 1 year ago

"skip that part" really interesting way to discuss an issue. I'm out.

TAPL-93 commented 1 year ago

You misunderstand, i meant that what i initially thought is not the issue, it's something to do with having to restart the ogp agent to get it working after the game server created which create the user so that's the issue.

own3mall commented 1 year ago

This is tricky because there is no easy way to apply the new group membership permissions mid-script execution without restarting the agent (have it run in a new / updated shell).

Info:

https://www.linuxquestions.org/questions/programming-9/newgrp-command-within-perl-csh-script-1827/ https://linux.die.net/man/1/newgrp https://man7.org/linux/man-pages/man1/sg.1.html

Can you please try this version, and see if it works (untested)?

https://raw.githubusercontent.com/own3mall/OGP-Agent-Linux/master/ogp_agent.pl

You will need to set

agent_auto_update=0

in bash_prefs.cfg in order to use the custom ogp_agent.pl file linked above.

Then, just use sudo service ogp_agent restart to get the agent to run this new code.

Essentially, what happens is that the agent will restart itself after a quick 2 second wait after a game server has been started (only if a new gameserverx user has been created) to apply the new group permissions to the ogp_agent user which should then make it so files are editable in the panel.

Not sure if this is a viable fix which is why I'm asking you to test it to see if it works.

@DieFeM any ideas for a better approach?

We could run chown commands before modifying files, but that would require larger changes (sending of additional information for some remote calls) and would affect APIs, so we probably just need an easy way to do this if a viable approach exists.

TAPL-93 commented 1 year ago

This line failed to restart the agent.

sudo_exec_without_decrypt("sleep 2 && service ogp_agent restart &");

have to remove '&' at the end.

The side effect as i can see is after the game server start that error will appear, the game server is started and afterward everything seems to be working.

Failed to start the remote server. Error code: -1

own3mall commented 1 year ago

The & is supposed to run the command in the background so that it will not block execution of the agent. Will have to play with it some more if the & doesn't actually move it to the background.

own3mall commented 1 year ago

@TAPL-93 Please try this version and let me know what your results are:

https://raw.githubusercontent.com/own3mall/OGP-Agent-Linux/master/ogp_agent.pl

Make sure you CTRL + F5 on the ogp_agent.pl code in your browser to make sure your browser fetches the latest changes.

DieFeM commented 1 year ago

I'd take a read on this post How to set the group that new files will be created with?

Basically says that you can change the group to which the files are saved.

You can change the default group for all files created in a particular directory by setting the setgid flag on the directory (chmod g+s dir). New files in the directory will then be created with the group of the directory (set using chgrp group dir). This applies to any program that creates files in the directory..

There's another post giving the very same solution, but explained with example: Set default group for user when they create new files?

Would you implement it own3mall?

own3mall commented 1 year ago

@DieFeM Thank you! That's an excellent suggestion. I'm not sure why I didn't think of it.

@TAPL-93 Please try / test this version: https://raw.githubusercontent.com/own3mall/OGP-Agent-Linux/feature/correct-group-perms/ogp_agent.pl

TAPL-93 commented 1 year ago

@TAPL-93 Please try / test this version: https://raw.githubusercontent.com/own3mall/OGP-Agent-Linux/feature/correct-group-perms/ogp_agent.pl

The issue is still ongoing.

Sun Apr 23 09:23:10 2023 Reading startup flags from /usr/share/ogp_agent/startups
Sun Apr 23 09:23:10 2023 Open Game Panel - Agent started - 68649f2f77583e461f8545432e79abdad727e07a - port 12679 - PID 217188
Sun Apr 23 09:23:11 2023 Error reading tasks file No such file or directory
Sun Apr 23 09:23:34 2023 Log file missing, regenerating: /usr/share/ogp_agent/screenlogs/screenlog.OGP_UPDATE_000000012
Sun Apr 23 09:23:36 2023 /usr/share/ogp_agent/tmp/home_id_12 does not exist yet. Trying to create it...
Sun Apr 23 09:23:36 2023 Running rsync update: /usr/bin/rsync --log-file='/usr/share/ogp_agent/rsync_update_generic.log' --archive --compress --copy-links --update --verbose rsync://rsync.opengamepanel.org/ogp_game_installer/mta/linux/ '/home/ogp_agent/OGP_User_Files/12'
Sun Apr 23 09:23:42 2023 User requested progress on rsync job on home /home/ogp_agent/OGP_User_Files/12.
Sun Apr 23 09:23:42 2023 Found 90952 and /home/ogp_agent/OGP_User_Files/12
Sun Apr 23 09:23:54 2023 Backing up file /home/ogp_agent/OGP_User_Files/12/mods/deathmatch/mtaserver.conf to /home/ogp_agent/OGP_User_Files/12/mods/deathmatch/mtaserver.conf.bak before writing new data.
Sun Apr 23 09:23:54 2023 Wrote /home/ogp_agent/OGP_User_Files/12/mods/deathmatch/mtaserver.conf successfully!
Sun Apr 23 09:23:54 2023 User gamehome12 currently doesn't exist... creating user...
Sun Apr 23 09:23:55 2023 Created startup flag for 188.165.51.67-22003
Sun Apr 23 09:23:55 2023 Startup command [ export WINEDEBUG="fixme-all" && export DISPLAY=:1 && screen -d -m -t "OGP_HOME_000000012" -c /usr/share/ogp_agent/ogp_screenrc -S OGP_HOME_000000012 bash OGP_HOME_000000012_startup_scr.sh ] will be executed in dir /home/ogp_agent/OGP_User_Files/12.
Sun Apr 23 09:24:04 2023 Asked for dirlist of /home/ogp_agent/OGP_User_Files/12/ directory.
Sun Apr 23 09:24:06 2023 Asked for dirlist of /home/ogp_agent/OGP_User_Files/12/mods directory.
Sun Apr 23 09:24:07 2023 Asked for dirlist of /home/ogp_agent/OGP_User_Files/12/mods/deathmatch directory.
Sun Apr 23 09:24:11 2023 Backing up file /home/ogp_agent/OGP_User_Files/12//mods/deathmatch/settings.xml to /home/ogp_agent/OGP_User_Files/12//mods/deathmatch/settings.xml.bak before writing new data.
Sun Apr 23 09:24:11 2023 ERROR - File [ /home/ogp_agent/OGP_User_Files/12//mods/deathmatch/settings.xml ] is not writeable!
Sun Apr 23 09:24:14 2023 Asked for dirlist of /home/ogp_agent/OGP_User_Files/12/mods/deathmatch directory.
own3mall commented 1 year ago

@TAPL-93 Please try this updated version again and let us know:

https://github.com/own3mall/OGP-Agent-Linux/blob/feature/correct-group-perms/ogp_agent.pl

If that doesn't work, please try https://raw.githubusercontent.com/own3mall/OGP-Agent-Linux/master/ogp_agent.pl where the agent gets restarted if you wouldn't mind.

TAPL-93 commented 1 year ago

The updated version is working, the perm after rsync is "ogp_agent ogp_agent", after server start "gamehomex ogp_agent" and after editing "settings.xml" the created .bk file "ogp_agent ogp_agent".

https://prnt.sc/RUw3vzoII-jV https://prnt.sc/KCr-9tMT24KD https://prnt.sc/2hvc0RoiCRCj

i tried to delete the game server, the page is stuck loading: https://prnt.sc/fQfuQfdtQPV1

own3mall commented 1 year ago

What does the ogp_agent log file show after you tried deleting the game server? I don't think I've seen it fail to delete before since it is using sudo commands to do so.

TAPL-93 commented 1 year ago

Something is blocking it somewhere. The game server is deleted normally after the agent server setting "Time Out" pass, which in my case i had it set to high value due to an issue with MySQL module, the database restore option fails if the database file is large and needs more time than the agent server setting "Time Out".

own3mall commented 1 year ago

@TAPL-93 This should be fixed in the latest version of the agent. You can reset the auto_update variable to 1 in bash_prefs and restart the agent service to update.

I don't know why the game server deletion is freezing on your instance. I tried it several times and was unable to reproduce.

Please close this issue if everything is good.

TAPL-93 commented 1 year ago

The latest version of the agent fixed the freezing issue.

TAPL-93 commented 1 year ago

I'm opening this again.

Files uploaded via the FTP or File Manager or the files that been altered through File Manager actions will get the perm "ogp_agent ogp_agent", the issue with this perm is that the game server while running is unable to access these files.

Trying to upload a resource file to "Multi Theft Auto" game server, then using the command "refresh" on the console to load the resource will fail with the error "Loading of resource 'xxx' failed".

own3mall commented 1 year ago

Disable agent auto update, and try this version:

https://pastey.icu/2hycyj1k

Let me know if it works. New files will still be ogp_agent:ogp_agent but they should be readable from the other user initial permission.

There's not a great solution for this. If this version doesn't work, I don't have a fix for it at the moment. Simply restart the server as the work-around.

Zorrototo commented 1 year ago

Another workaround would be to use the "unique user" method, I guess?

own3mall commented 1 year ago

Another workaround would be to use the "unique user" method, I guess?

This is when running each game server under a different user account. This shouldn't be a problem with the old method of running all game servers under the same user (an option in one of the config files).

TAPL-93 commented 1 year ago

Disable agent auto update, and try this version:

https://pastey.icu/2hycyj1k

Let me know if it works. New files will still be ogp_agent:ogp_agent but they should be readable from the other user initial permission.

There's not a great solution for this. If this version doesn't work, I don't have a fix for it at the moment. Simply restart the server as the work-around.

This is working.