Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output a warning from the launch script if the application will run as root #10275

Closed
wants to merge 1 commit into from
Closed

Output a warning from the launch script if the application will run as root #10275

wants to merge 1 commit into from

Conversation

obfischer
Copy link
Contributor

The user used in the launch script to run the application is now configurable if needed. Closes #10273.

if [[ -z "{{runUser}}" ]]; then
# Determine the user to run as if we are root
# shellcheck disable=SC2012
[[ $(id -u) == "0" ]] && run_user=$(ls -ld "$jarfile" | awk '{print $3}')

Choose a reason for hiding this comment

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

What if root is the owner of the jar file? Might be good to print a warning if someone configures the run as user to root?

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 thought the same but I didn't want to address this in this PR. As a running an program as root is a potential security problem. We could issues an warning or abort the script. But this would be breaking change for existing users who updated.

I see to possible solutions:

  1. Print a simple warning while starting the program.
  2. Refuse to start the program if it would run as root unless the user set runUser=root explicitly.

WDYT?

Choose a reason for hiding this comment

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

I think a warning is the way to go (as you stated it might break something otherwise). I think the Apache Webserver does the same (probably a couple of others as well)

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, I will update the PR but tomorrow. It is already later for me... Ok?

Choose a reason for hiding this comment

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

I'm not in the position to (and I never would) demand anything from you :) plus we're in the same time zone ;)

fi

# Issue an warning if the application will run as root
[[ $(id -u) == "0" ]] && { echoRed "Application is running as root (UID 0)."; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now also a warning will be printed if the effective user at runtime is root.

Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, particularly as it's your first contribution to Spring Boot. This looks like a good addition to make. I've left a few, mostly minor, comments. Would you mind taking a look and, if you agree, updating the PR?

@@ -780,6 +780,12 @@ for Gradle and to `${project.name}` for Maven.
|The default value for the name of the pid file in `PID_FOLDER`. Only valid for an
`init.d` service.

|`runUser`
| The user under which the application will run under at runtime. If not set
Copy link
Member

Choose a reason for hiding this comment

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

No need for the second "under" in this sentence

@@ -780,6 +780,12 @@ for Gradle and to `${project.name}` for Maven.
|The default value for the name of the pid file in `PID_FOLDER`. Only valid for an
`init.d` service.

|`runUser`
| The user under which the application will run under at runtime. If not set
the application will run under the id of user who runs the script. If
Copy link
Member

Choose a reason for hiding this comment

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

Add "the" so it read "the id of the user"?

fi

# Issue an warning if the application will run as root
[[ $(id -u) == "0" ]] && { echoRed "Application is running as root (UID 0)."; }
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 this should be echoYellow rather than echoRed. The latter is only used in the script when there's an error and the script will exit with a non-zero exit code.

Copy link

@kartoffelsup kartoffelsup Sep 14, 2017

Choose a reason for hiding this comment

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

And maybe also re-phrase to something like
"[WARN] Application is running as root (UID 0). This is considered insecure."
to emphasize that it is a warning and not just a yellow colored information :)
Also, shouldn't this be:

[[ $(id -u $run_user) == "0" ]] ...

?

@obfischer
Copy link
Contributor Author

I applied all suggested changes.

@obfischer
Copy link
Contributor Author

Is there anything that needs still to be done?

@wilkinsona wilkinsona added priority: normal type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 18, 2017
@wilkinsona wilkinsona added this to the 2.0.0.M5 milestone Sep 18, 2017
@wilkinsona
Copy link
Member

No, I don't think so. Thanks again for the PR.

fi

# Issue an warning if the application will run as root
[[ $(id -u) == "0" ]] && { echoYellow "[WARN] Application is running as root (UID 0). This is considered insecure."; }

Choose a reason for hiding this comment

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

Shouldn't this be $(id -u $run_user)?

Copy link
Member

Choose a reason for hiding this comment

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

Well spotted, @kartoffelsup. I think you're right. Thank you.

That raises the issue of adding some tests for this which I overlook when I said that I didn't think that there was anything left to be done.

@obfischer do you have the time to look at adding some tests please? I'm happy to guide you through the process as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course. Which tests are missing from your perspective?

Copy link
Member

Choose a reason for hiding this comment

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

A couple of tests would be good:

  1. Verify that the warning is generated when the application will run as root
  2. Verify that the warning is not generated when the application will run as another user

Copy link
Contributor Author

@obfischer obfischer Sep 18, 2017

Choose a reason for hiding this comment

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

I think the correct module for such tests will be spring-boot-launch-script-tests?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's right. Thanks.

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 will start now with it.

@wilkinsona
Copy link
Member

@obfischer Any luck with writing those tests?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 24, 2017
@obfischer
Copy link
Contributor Author

Not until now. I have a hugh workload until the end of the month.

@wilkinsona
Copy link
Member

Understood. Thanks. There's no major rush from our perspective.

@obfischer
Copy link
Contributor Author

Hi @wilkinsona, I am trying to run the integration tests via mvn -P docker clean install but all tests are failing. The readme states that native Docker on macOS is not support and I need the Docker Toolbox. As far as I know the Docker Toolbox is not available anymore.

Any idea?

@wilkinsona
Copy link
Member

It has been quite some time since I set Docker up on my Mac. Does the Docker Toolbox installation available here not work?

@obfischer
Copy link
Contributor Author

To stupid to Google. I will check it out.

@obfischer
Copy link
Contributor Author

The testsetup is now running on my machine.

@obfischer
Copy link
Contributor Author

@wilkinsona I updated the existing tests. Currently there is still one missing test I hope to write it during the next days.

@wilkinsona
Copy link
Member

@obfischer Thanks for the updates

@obfischer
Copy link
Contributor Author

Hi @wilkinsona I added all positive and negative tests and eleminated found bugs. Could you please review them if you have time.

@obfischer
Copy link
Contributor Author

Hi @wilkinsona is there a chance that this PR will be accepted for the 1.5 branch? And is it planned to have a new 1.5.x release in the next time? Please let me know if something could be done by me.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Dec 21, 2017
@wilkinsona wilkinsona added this to the 2.0.0.RC1 milestone Dec 21, 2017
@wilkinsona
Copy link
Member

No, sorry. Given that this is an enhancement, it will have to go into 2.0 at the earliest. I’ll target it at 2.0.0.RC1 and see what we can do.

@wilkinsona
Copy link
Member

Thanks.

Sorry, but I don't find that argument sufficiently compelling to merge this. The proposal leaves users with multiple ways of doing the same thing and that's something that we try to avoid. We already document some advice on securing a jar so that it cannot be manipulated or replaced.

If you prefer your approach to the documented approach, I'd recommend that you consider building your jar with a custom script.

@obfischer
Copy link
Contributor Author

Ok.

@kartoffelsup
Copy link

@wilkinsona will the warning be added?

@obfischer
Copy link
Contributor Author

Would be nice to have a least a warning.

@wilkinsona
Copy link
Member

@obfischer Are you happy for us to extract just that part of the proposed changes from this PR?

@obfischer
Copy link
Contributor Author

Yes, I will do that. Update this PR or should I open a new one?

@wilkinsona
Copy link
Member

Thanks. Let's use this one. I've reopened it.

@wilkinsona wilkinsona reopened this Feb 5, 2018
@wilkinsona wilkinsona added type: enhancement A general enhancement status: waiting-for-feedback We need additional information before we can continue priority: normal and removed status: declined A suggestion or change that we don't feel we should currently apply labels Feb 5, 2018
@wilkinsona
Copy link
Member

@obfischer Are you still interested in slimming this PR down to the piece that logs the warning?

@obfischer
Copy link
Contributor Author

Hi @wilkinsona, yes. Give me a last chance until next Monday. It is a official holiday here in Germany.

@obfischer
Copy link
Contributor Author

Hi @wilkinsona I changed my PR as you requested.

@wilkinsona wilkinsona changed the title The user used in the launch script to run the application is now configurable. Output a warning from the launch script if the application will run as root Aug 13, 2018
@wilkinsona
Copy link
Member

Thanks very much.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Aug 13, 2018
@wilkinsona wilkinsona added this to the Backlog milestone Aug 13, 2018
@wilkinsona
Copy link
Member

@obfischer Thank you very much for making your first contribution to Spring Boot. The proposed changes have now been merged into master.

wilkinsona added a commit that referenced this pull request Sep 11, 2018
* gh-10275:
  Polish "Issue a warning from launch script when app will run as root"
  Issue a warning from launch script when app will run as root
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.0.M3 Sep 11, 2018
@obfischer
Copy link
Contributor Author

Thank you for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make run_user for the launch script configurable
5 participants