Skip to content

Provide an env var that controls the user with which the launch script runs the app #16973

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

Conversation

wagnerluis1982
Copy link
Contributor

@wagnerluis1982 wagnerluis1982 commented May 27, 2019

Enhance the launch.script by adding RUN_AS_USER option, suitable when run as a service.

Here, it's introduced a new way to make the service change user when starting. The old way, by relying on the jar file ownership is still supported.

Closes gh-16667

@pivotal-issuemaster
Copy link

@wagnerluis1982 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@wagnerluis1982 Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2019
@wagnerluis1982
Copy link
Contributor Author

wagnerluis1982 commented May 27, 2019

Adding some information, for clarity.

This configuration is an environment variable used by the launch.script, used when we build an executable jar.

Say we put the executable jar in /var/api/spring-boot-app.jar and we have a configuration file /var/api/spring-boot-app.conf with the following content:

RUN_AS=wagner

When we sudo service spring-boot-app start, the java process is started changing uid to wagner, instead of root (supposing the jar file belongs to root).


Side notes:

  1. Changing uid is currently possible by changing jar file ownership by

    chown wagner /var/api/spring-boot-app.jar
    

    In the issue adding a forced run_user assignment to launch.script #16667 is discussed why with RUN_AS is better.

  2. When RUN_AS is used, the file ownership doesn't matter, the process uid is going to be what is in the configuration.

  3. An error is issued if RUN_AS is present and the user is not root. No check is actually done if action is status or run.

@wagnerluis1982
Copy link
Contributor Author

Hi, I don't think the errors on checks are caused by my changes, can someone confirm?

@snicoll
Copy link
Member

snicoll commented May 28, 2019

can someone confirm?

Yes

@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 28, 2019
@philwebb philwebb added this to the 2.2.x milestone May 28, 2019
@wagnerluis1982
Copy link
Contributor Author

Hi, only checking, this new entry must be documented in https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html, right?

@wagnerluis1982
Copy link
Contributor Author

wagnerluis1982 commented May 29, 2019

Hmmm, seeing the doc I forgot that some config entries are also Gradle/Maven properties (used when the script is written).

So, my question, these properties must be implemented with this PR or that must be another issue?

@wilkinsona
Copy link
Member

Hi, only checking, this new entry must be documented in https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html, right?

Yes, please.

So, my question, these properties must be implemented with this PR or that must be another issue?

What new properties did you have in mind? As currently proposed the RUN_AS environment variable is used. As such, I'm not sure that we need a property the gets applied when writing the launch script into the fully executable jar.

@wagnerluis1982
Copy link
Contributor Author

wagnerluis1982 commented May 29, 2019

What new properties did you have in mind? As currently proposed the RUN_AS environment variable is used. As such, I'm not sure that we need a property the gets applied when writing the launch script into the fully executable jar.

Ops, I miswrote in my previous comment, when I said "these new properties", I was meaning "this new property" (RUN_AS). Forgot about it, I see now that a build property is not really needed.

@wagnerluis1982
Copy link
Contributor Author

In addtion, I have a suggestion here: to change the variable from RUN_AS to RUN_USER.

Motivation: I think RUN_AS, even being self-explanatory, its spelling is too much similar to RUN_ARGS.

@wagnerluis1982
Copy link
Contributor Author

Hi, only passing to say I didn't have time last week to update the documentation, but I'm going to do soon.

@wilkinsona
Copy link
Member

@wagnerluis1982 How are things going with an update to the docs?

With regards to RUN_AS or RUN_USER, how about RUN_AS_USER to avoid possible confusion with the runuser shell command?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jul 10, 2019
@wagnerluis1982
Copy link
Contributor Author

@wagnerluis1982 How are things going with an update to the docs?

Sorry about that, my time became scarce and I couldn't get to do. I can come back to do next week.

With regards to RUN_AS or RUN_USER, how about RUN_AS_USER to avoid possible confusion with the runuser shell command?

For me it's okay.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 10, 2019
@wagnerluis1982
Copy link
Contributor Author

Sorry again for the delay, I'm coming back to this issue today and I see the tests are now using JUnit Jupiter.

I will change my tests and write the documentation, I hope to finish tomorrow.

Suggested by @wilkinsona in comment gh-16973#issuecomment-509919654
@wagnerluis1982 wagnerluis1982 changed the title Add config entry RUN_AS to launch.script Add config entry RUN_AS_USER to launch.script Jul 28, 2019
@wagnerluis1982
Copy link
Contributor Author

wagnerluis1982 commented Jul 28, 2019

@wilkinsona I finish to rewrite the tests and write the documentation entry for the new property RUN_AS_USER.

Now, I feel the section Securing an init.d Service should be rewritten to recommend the users to use the new property, but I don't know I'm not sure what to write there.

@wagnerluis1982
Copy link
Contributor Author

Hi, is there still any pending on this PR?

@snicoll
Copy link
Member

snicoll commented Aug 5, 2019

None I am aware of @wagnerluis1982, we need to review the update you pushed a week ago and couldn't find time to do so yet.

@wagnerluis1982
Copy link
Contributor Author

Fine, thanks, @snicoll 👍

@wagnerluis1982
Copy link
Contributor Author

wagnerluis1982 commented Sep 17, 2019

Hi, I noticed the branch is in conflict again. In that case what do you prefer? Merge or rebase?

Last conflict I did on my own a rebase, now I am not sure if was the right thing to do...

@philwebb
Copy link
Member

@wagnerluis1982 Rebase is best, but we're happy to take that task on when we merge the PR.

@wilkinsona wilkinsona removed the status: feedback-provided Feedback has been provided label Sep 20, 2019
@wilkinsona wilkinsona self-assigned this Sep 21, 2019
@wilkinsona wilkinsona changed the title Add config entry RUN_AS_USER to launch.script Provide an env var that controls the user with which the launch script runs the app Sep 21, 2019
@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.0.RC1 Sep 21, 2019
@wilkinsona
Copy link
Member

wilkinsona commented Sep 21, 2019

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

@wagnerluis1982 wagnerluis1982 deleted the launch-script-run-as branch October 28, 2019 03:39
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.

adding a forced run_user assignment to launch.script
6 participants