itzg / docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
https://docker-minecraft-server.readthedocs.io/
Apache License 2.0
9.18k stars 1.52k forks source link

Ability to run shell command instead/in addition to rcon commands. #2321

Open Buco7854 opened 1 year ago

Buco7854 commented 1 year ago

Enhancement Type

Improve an existing feature

Describe the enhancement

Hello, That would be really nice if we could have something like RCON_CMDS_STARTUP for shell so that we could for example add custom scripts in a volume and run them when some events are triggered. I took a look to rcon-cmds-daemon.sh and I believe it could be easily adaptable for shell commands since it seems it just call the command prepended by rcon-cli. Either we could add a secondary run_command function or just remove the prepend but it woudl kind of break compatibility so I guess first option is better. Please let me know what you think about it and either way thanks for this wonderful image.

itzg commented 1 year ago

That would certainly be quite doable. It feels like a security risk to allow arbitrary system commands to run; however, I can't pinpoint any particular exploit that couldn't already done by exec'ing into the container.

What are some examples of things you would want to script into those events? Arbitrary scripts would also have to make use of things pre-installed.

Buco7854 commented 1 year ago

That would certainly be quite doable. It feels like a security risk to allow arbitrary system commands to run; however, I can't pinpoint any particular exploit that couldn't already done by exec'ing into the container.

What are some examples of things you would want to script into those events? Arbitrary scripts would also have to make use of things pre-installed.

Well for example some kind of webhook when someone gets online for a friends server. that was my use case, but I mean anything can be done, just need the events and then it's up to anyone to develop whatever they feel like doing.

Buco7854 commented 1 year ago

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them, and worst case we coudl use the startup event to run a script to install the dependencies.

itzg commented 1 year ago

I am 100% on board with supporting webhooks. mc-image-helper can be enhanced in any way to streamline that.

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them,

Well, in this case, this image purposely hasn't installed python in order to try minimizing the image size.

and worst case we coudl use the startup event to run a script to install the dependencies.

That's starting to sound a little too arbitrary and makes me nervous. Besides, any extra packages installed will all go away on next container restart. It can take a minute or two to install packages -- that doesn't seem like an acceptable delay for event handling.

I will queue this up for considering webhook support, but even then I'd like to scope to a particular use case or two.

Buco7854 commented 1 year ago

I am 100% on board with supporting webhooks. mc-image-helper can be enhanced in any way to streamline that.

It certainly is dependent on the container itself, but for example, Python is already pre-installed on quite a lot of them,

Well, in this case, this image purposely hasn't installed python in order to try minimizing the image size.

and worst case we coudl use the startup event to run a script to install the dependencies.

That's starting to sound a little too arbitrary and makes me nervous. Besides, any extra packages installed will all go away on next container restart. It can take a minute or two to install packages -- that doesn't seem like an acceptable delay for event handling.

I will queue this up for considering webhook support, but even then I'd like to scope to a particular use case or two.

Well I certainly see your point. Limiting it to webhooks seems fine for me. I guess receive event and then executing some command using rcon from outside for aditional data or would it send some actual data with the event ?

itzg commented 1 year ago

Yeah, I'm thinking the webhook method (GET, POST, etc), URL, and body template string could be the input environment variables. That template can be JSON or whatever the receiver needs and substituted with certain variables: event type, player count, etc.

Buco7854 commented 1 year ago

Yeah, I'm thinking the webhook method (GET, POST, etc), URL, and body template string could be the input environment variables. That template can be JSON or whatever the receiver needs and substituted with certain variables: event type, player count, etc.

That seems like a good way, thanks for considering it 🙂.