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

Improve ownership and permissions of files in OpenSearch deb and rpm packages #3898

Merged

Conversation

smortex
Copy link
Contributor

@smortex smortex commented Aug 17, 2023

Description

When installing OpenSearch from .deb or .rpm packages, the files permissions are unexpectedly relaxed allowing all local users to access all files from the OpenSearch, and allowing OpenSearch itself to update any file installed in the package.

This PR adjust the permissions so that the configuration, logs and data cannot be accessed by random users, and the application code cannot be updated by the opensearch user.

Issues Resolved

Fixes #3815

The files installed in /usr/share/opensearch do not need to be owned by
the opensearch user.  The default ownership from Debian packages,
root:root is fine and should be preferred.

Remove the post-installation line that customized these permissions.

Signed-off-by: Romain Tartière <romain@blogreen.org>
The configuartion files installed by the opensearch package can contain
sensitive information such as clear-text passwords (e.g. to reach an
LDAP directory to authenticate users).  When installing from a tarball,
the configuration file are only accessible to the owner and members of
the group of the file.

Adjust the post-installation script to setup permissions for these files
similar to the ones of the tarball.

Currently, OpenSearch create files in the configuartion directory on
first start (opensearch.keystore), so we cannot change the configuration
directory ownership to prevent the service from tinkering with these
files.

Signed-off-by: Romain Tartière <romain@blogreen.org>
The OpenSearch logs may contain sensitive data.  In order to prevent
random users from accessing log files, Debian packages often setup the
log directory so that only the service can write to it, members of the
adm group can read these files, and other users are not granted access.

Adjust the log directory owner and permissions to match that behavior.

Signed-off-by: Romain Tartière <romain@blogreen.org>
Other users on the system have no reason to access the OpenSearch raw
data files.

Make sure these files are only available to the user running the
service.

Signed-off-by: Romain Tartière <romain@blogreen.org>
Now that the deb permissions and files ownerships are better, adjust the
rpm receipe is a similar fashion for a consistent experience accross
different operating systems.

Signed-off-by: Romain Tartière <romain@blogreen.org>
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #3898 (71c7c34) into main (1ac48c3) will increase coverage by 0.01%.
Report is 8 commits behind head on main.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #3898      +/-   ##
==========================================
+ Coverage   92.03%   92.05%   +0.01%     
==========================================
  Files         186      187       +1     
  Lines        5639     5662      +23     
==========================================
+ Hits         5190     5212      +22     
- Misses        449      450       +1     

see 2 files with indirect coverage changes

@peterzhuamazon
Copy link
Member

Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

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

Hi @smortex thanks for the contribution here.

I have some comments and once we clear these, I would need to run a full-ledge build on ci images with this code, to ensure it is running without issues.

Thanks.

Instead of adding and removing permission bits, use explicit values.

Signed-off-by: Romain Tartière <romain@blogreen.org>
@peterzhuamazon
Copy link
Member

Thanks @smortex, once you address my last comment / open conversation, we can queue this up for merging.

Bare in mind we might have a patch release before 2.10.0, so we might keep this PR open a bit until we enter the 2.10.0 release cycle, since there are a lot of essential changes on both deb/rpm.

I will start the test on my side once all the existing conversation addressed.

Thanks.

They where changed unexpectedly in
eb0e032 but while the change seems
noop, better limit the number of changes to avoid unexpected
regressions.

Signed-off-by: Romain Tartière <romain@blogreen.org>
@peterzhuamazon
Copy link
Member

Hi @smortex ,

Add a comment and want to know if opensearch-project/OpenSearch#9447 needs to go in before this?

Thanks.

The presence of this bit on the files seems to have no consequence on
the final package as the installed files do not have the SGID bit set.
But for consistency with the rpm packaging, unset the bit before
building the package.

Signed-off-by: Romain Tartière <romain@blogreen.org>
@smortex
Copy link
Contributor Author

smortex commented Aug 21, 2023

@peterzhuamazon I added a commit to have the .deb and .rpm packaging doing the same stripping of the SGID bit. I am good with this PR as it is now, no need to wait for opensearch-project/OpenSearch#9447 to be merged IMHO as we have all required workarounds here.

When opensearch-project/OpenSearch#9447 is merged, we can do the cleanup in this repo in a new PR.

Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

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

Thanks @smortex for the help and commit to fix this issue.

@peterzhuamazon peterzhuamazon merged commit 35db59d into opensearch-project:main Aug 21, 2023
12 checks passed
@smortex smortex deleted the deb-rpm-owner-permissions branch August 21, 2023 23:40
smortex added a commit to smortex/opensearch-build that referenced this pull request Sep 1, 2023
Similar to the issue fixed in opensearch-project#3898, OpenSearch-Dashboards package has
unexpected files owner and permissions.

This ensure the installed files are not owner by the
opensearch-dashboards user (preventing the program to overwrite itself
with malicious code if the service has some kind of vulnerability), and
make sure logs and data cannot be accessed by random users.

Signed-off-by: Romain Tartière <romain@blogreen.org>
smortex added a commit to smortex/opensearch-build that referenced this pull request Sep 11, 2023
Similar to the issue fixed in opensearch-project#3898, OpenSearch-Dashboards package has
unexpected files owner and permissions.

This ensure the installed files are not owner by the
opensearch-dashboards user (preventing the program to overwrite itself
with malicious code if the service has some kind of vulnerability), and
make sure logs and data cannot be accessed by random users.

Signed-off-by: Romain Tartière <romain@blogreen.org>
@smortex smortex changed the title Improve ownership and permissions of files in deb and rpm packages Improve ownership and permissions of files in OpenSearch deb and rpm packages Sep 19, 2023
peterzhuamazon added a commit to peterzhuamazon/opensearch-build that referenced this pull request Sep 19, 2023
peterzhuamazon pushed a commit to peterzhuamazon/opensearch-build that referenced this pull request Sep 19, 2023
peterzhuamazon pushed a commit to peterzhuamazon/opensearch-build that referenced this pull request Sep 19, 2023
…pensearch-project#3898)

Signed-off-by: Romain Tartière <romain@blogreen.org>
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
peterzhuamazon pushed a commit to peterzhuamazon/opensearch-build that referenced this pull request Mar 14, 2024
…pensearch-project#3898)

Signed-off-by: Romain Tartière <romain@blogreen.org>
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Defaut config permission too relaxed in deb and rpm packages
2 participants