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

[DOCS] RHEL Security TMP override #77285

Closed
wants to merge 1 commit into from
Closed

Conversation

stefnestor
Copy link
Contributor

Adding content for top last 30d Elastic Discuss post which covers a BlackHat RHEL start-up error with this solution.

Not sure if it makes sense to include "if you don't do this, you'll get these errors" or some kind of better framing/context. Putting in raw helpful content for review 🙏🏼

@stefnestor stefnestor added >docs General docs changes Team:Docs Meta label for docs team labels Sep 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-docs (Team:Docs)

@elasticsearchmachine elasticsearchmachine added v8.0.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Sep 4, 2021
@jrodewig jrodewig changed the title [+DOC] RHEL Security TMP override [DOCS] RHEL Security TMP override Sep 9, 2021
@jrodewig jrodewig added the :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts label Sep 9, 2021
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Sep 9, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

@mark-vieira
Copy link
Contributor

@pugnascotia were you involved in tracking down this issue? If so you can give the 👍 on this?

@@ -123,6 +123,17 @@ endif::[]

include::skip-set-kernel-parameters.asciidoc[]

[[install-rhel-security]]
==== Override Red Hat TMP if Security Compliance
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be something like the following? This feels convoluted.

Suggested change
==== Override Red Hat TMP if Security Compliance
==== Override Red Hat TMP if Security Compliant

Copy link
Contributor

Choose a reason for hiding this comment

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

Compliant is better than Compliance, but "Security Compliant" is still vague. Can we be more specific here and say something like, "Override Red Hat TMP if FIPS mode is enabled"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately it's nothing to do with FIPS mode - these steps are necessary today if the user is using SELinux with a particular config (which we don't test and haven't even fully characterised). Admittedly there will be significant overlap between users of FIPS mode and users of this kind of SELinux config.

==== Override Red Hat TMP if Security Compliance

If you are applying a security compliance in your RHEL installation
you must change the path of the TMP directory that will use elasticsearch as Java.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
you must change the path of the TMP directory that will use elasticsearch as Java.
you must change the path of the TMP directory that Java and {es} will use.


1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
2. Add `ES_TMPDIR=/usr/share/elasticsearch/tmp` under `/etc/sysconfig/elasticsearch`
3. Create the /usr/share/elasticsearch/tmp directory and make sure that the owner and group are elasticsearch and the permissions are `0755`
Copy link
Contributor

@pugnascotia pugnascotia Sep 10, 2021

Choose a reason for hiding this comment

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

Suggested change
3. Create the /usr/share/elasticsearch/tmp directory and make sure that the owner and group are elasticsearch and the permissions are `0755`
3. Create the `/usr/share/elasticsearch/tmp` directory and make sure that the owner and group are `elasticsearch` and the permissions are `0755`.

Copy link
Contributor

Choose a reason for hiding this comment

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

If step 4 is deemed unacceptable, I'd add a note to this step indicating that no users other than the elasticsearch user should have access to this directory.

@pugnascotia
Copy link
Contributor

@DaveCTurner knows more about this than me, so I've added him as a reviewer.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

I think we shouldn't copy the instructions from the forum post without validating them and considering some simpler alternatives. I believe we could fix this whole thing ourselves by setting TMPDIR to the value of ES_TMPDIR in our startup scripts. Does anything bad happen if we set TMPDIR for every Linux user?

A more targeted fix will be #77014 but this needs JNA to upgrade their libffi and then we need to upgrade our JNA so it'll be a while before we can do that.

I'm also not sure we actually need to override ES_TMPDIR in these environments either. If you hit the segfault in the linked forum post then we know that JNA's temporary directory supports executables so it should be enough to tell libffi to use the same location.

If you are applying a security compliance in your RHEL installation
you must change the path of the TMP directory that will use elasticsearch as Java.

1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't be telling users to edit jvm.options, they should be adding extra options files in jvm.options.d.

But then I think this isn't necessary anyway, we already copy ES_TMPDIR to java.io.tmpdir IIRC.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we tell people to add custom options files. If this step is necessary, I'd cross reference the info on setting JVM options (https://www.elastic.co/guide/en/elasticsearch/reference/master/advanced-configuration.html#set-jvm-options). Something like:

In a <<set-jvm-options, custom JVM options>> file, override the -Djava.io.tempdir setting:

-Djava.io.tmpdir=${ES_TMPDIR}

Copy link
Contributor

Choose a reason for hiding this comment

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

I can confirm this is unnecessary: we already have this setting in the default jvm.options file:

## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}

1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
2. Add `ES_TMPDIR=/usr/share/elasticsearch/tmp` under `/etc/sysconfig/elasticsearch`
3. Create the /usr/share/elasticsearch/tmp directory and make sure that the owner and group are elasticsearch and the permissions are `0755`
4. Lastly make sure that `/dev/shm` doesn't have the noexec attribute with command: `mount | grep tmpfs | grep '/dev/shm'`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably unacceptable to many users of locked-down systems. Instead we should set TMPDIR (eventually LIBFFI_TMPDIR to point to a location to which only the elasticsearch user has access.

@pugnascotia
Copy link
Contributor

@DaveCTurner so we also have #74163, and I don't think it's too much of a stretch to expand that to just using $ES_HOME/tmp for all tmp-related matters. What do you think?

@DaveCTurner
Copy link
Contributor

#74163 is related but kinda different, libffi doesn't care about system properties so fixing the temp dir for libffi is fairly orthogonal to overriding java.io.tmpdir. Not that I hold a strong opinion about how we organise these issues, up to you and the core/infra folks really.

@jrodewig jrodewig requested review from debadair and removed request for jrodewig October 4, 2021 12:54
Copy link
Contributor

@debadair debadair left a comment

Choose a reason for hiding this comment

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

I added some comments and suggestions. It took me a bit to wrap my head around what was going on here, so not 100% sure the details are correct. However, I do thing we need to work in a bit more context about what you're doing and why.

Also, we should add an IMPORTANT note to https://www.elastic.co/guide/en/elasticsearch/reference/master/important-settings.html#es-tmpdir that indicates that you must use a dedicated TMP directory outside of the system TMP directory if you are running on a system with FIPS mode enabled.

@@ -123,6 +123,17 @@ endif::[]

include::skip-set-kernel-parameters.asciidoc[]

[[install-rhel-security]]
==== Override Red Hat TMP if Security Compliance
Copy link
Contributor

Choose a reason for hiding this comment

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

Compliant is better than Compliance, but "Security Compliant" is still vague. Can we be more specific here and say something like, "Override Red Hat TMP if FIPS mode is enabled"?

If you are applying a security compliance in your RHEL installation
you must change the path of the TMP directory that will use elasticsearch as Java.

1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we tell people to add custom options files. If this step is necessary, I'd cross reference the info on setting JVM options (https://www.elastic.co/guide/en/elasticsearch/reference/master/advanced-configuration.html#set-jvm-options). Something like:

In a <<set-jvm-options, custom JVM options>> file, override the -Djava.io.tempdir setting:

-Djava.io.tmpdir=${ES_TMPDIR}

you must change the path of the TMP directory that will use elasticsearch as Java.

1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
2. Add `ES_TMPDIR=/usr/share/elasticsearch/tmp` under `/etc/sysconfig/elasticsearch`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make this the first step, even if you do need to explicitly set the JVM TMP directory to ES_TMPDIR.

Suggested change
2. Add `ES_TMPDIR=/usr/share/elasticsearch/tmp` under `/etc/sysconfig/elasticsearch`
2. Configure a dedicated {es} TMP directory outside of the system TMP directory:
+
[source,shell]
----
ES_TMPDIR=/usr/share/elasticsearch/tmp
---


1. Uncomment `-Djava.io.tmpdir=${ES_TMPDIR}` under `/etc/elasticsearch/jvm.options`
2. Add `ES_TMPDIR=/usr/share/elasticsearch/tmp` under `/etc/sysconfig/elasticsearch`
3. Create the /usr/share/elasticsearch/tmp directory and make sure that the owner and group are elasticsearch and the permissions are `0755`
Copy link
Contributor

Choose a reason for hiding this comment

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

If step 4 is deemed unacceptable, I'd add a note to this step indicating that no users other than the elasticsearch user should have access to this directory.

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Nov 15, 2021
Today if `libffi` cannot allocate pages of memory which are both
writeable and executable then it will attempt to write code to a
temporary file. Elasticsearch configures itself a suitable temporary
directory for use by JNA but by default `libffi` won't find this
directory and will try various other places. In certain configurations,
none of the other places that `libffi` tries are suitable. With older
versions of JNA this would result in a `SIGSEGV`; since elastic#80617 the JVM
will exit with an exception.

With this commit we use the `LIBFFI_TMPDIR` environment variable to
configure `libffi` to use the same directory as JNA for its temporary
files if they are needed.

Closes elastic#18272
Closes elastic#73309
Closes elastic#74545
Closes elastic#77014
Closes elastic#77053
Relates elastic#77285

Co-authored-by: Rory Hunter <[email protected]>
@DaveCTurner
Copy link
Contributor

Now that #80651 is merged I think users don't need to do most of this stuff. It should be sufficient to just set ES_TMPDIR to point somewhere other than a subdirectory of /tmp. If we want to write step-by-step instructions for that then IMO it'd be better in docs/reference/setup/sysconfig/executable-jna-tmpdir.asciidoc since they are applicable to all distributions, not just RPM. Admittedly it affects RHEL folks more than others, so a cross-link from these RPM docs would be helpful.

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Nov 15, 2021
Today if `libffi` cannot allocate pages of memory which are both
writeable and executable then it will attempt to write code to a
temporary file. Elasticsearch configures itself a suitable temporary
directory for use by JNA but by default `libffi` won't find this
directory and will try various other places. In certain configurations,
none of the other places that `libffi` tries are suitable. With older
versions of JNA this would result in a `SIGSEGV`; since elastic#80617 the JVM
will exit with an exception.

With this commit we use the `LIBFFI_TMPDIR` environment variable to
configure `libffi` to use the same directory as JNA for its temporary
files if they are needed.

Closes elastic#18272
Closes elastic#73309
Closes elastic#74545
Closes elastic#77014
Closes elastic#77053
Relates elastic#77285

Co-authored-by: Rory Hunter <[email protected]>
elasticsearchmachine pushed a commit that referenced this pull request Nov 15, 2021
Today if `libffi` cannot allocate pages of memory which are both
writeable and executable then it will attempt to write code to a
temporary file. Elasticsearch configures itself a suitable temporary
directory for use by JNA but by default `libffi` won't find this
directory and will try various other places. In certain configurations,
none of the other places that `libffi` tries are suitable. With older
versions of JNA this would result in a `SIGSEGV`; since #80617 the JVM
will exit with an exception.

With this commit we use the `LIBFFI_TMPDIR` environment variable to
configure `libffi` to use the same directory as JNA for its temporary
files if they are needed.

Closes #18272
Closes #73309
Closes #74545
Closes #77014
Closes #77053
Relates #77285

Co-authored-by: Rory Hunter <[email protected]>

Co-authored-by: Rory Hunter <[email protected]>
elasticsearchmachine pushed a commit that referenced this pull request Nov 15, 2021
* Set LIBFFI_TMPDIR at startup (#80651)

Today if `libffi` cannot allocate pages of memory which are both
writeable and executable then it will attempt to write code to a
temporary file. Elasticsearch configures itself a suitable temporary
directory for use by JNA but by default `libffi` won't find this
directory and will try various other places. In certain configurations,
none of the other places that `libffi` tries are suitable. With older
versions of JNA this would result in a `SIGSEGV`; since #80617 the JVM
will exit with an exception.

With this commit we use the `LIBFFI_TMPDIR` environment variable to
configure `libffi` to use the same directory as JNA for its temporary
files if they are needed.

Closes #18272
Closes #73309
Closes #74545
Closes #77014
Closes #77053
Relates #77285

Co-authored-by: Rory Hunter <[email protected]>

* Fix incorrect SSL usage

Co-authored-by: Rory Hunter <[email protected]>
@arteam arteam added v8.1.0 and removed v8.0.0 labels Jan 12, 2022
@mark-vieira mark-vieira added v8.2.0 and removed v8.1.0 labels Feb 2, 2022
@elasticsearchmachine
Copy link
Collaborator

@stefnestor please enable the option "Allow edits and access to secrets by maintainers" on your PR. For more information, see the documentation.

@stefnestor
Copy link
Contributor Author

@debadair I'm suppose to ... but I don't show the option from the documentation ... . Can you help me convert to whatever Docs needs to move forward? 🙏🏼

@stefnestor please enable the option "Allow edits and access to secrets by maintainers" on your PR. For more information, see the documentation.

screenshot

image

@pugnascotia
Copy link
Contributor

Gah. The GitHub API isn't very helpful when it comes to detecting the "Allow edits and access to secrets by maintainers" setting, sorry for the noise

@elasticsearchmachine elasticsearchmachine changed the base branch from master to main July 22, 2022 23:10
@mark-vieira mark-vieira added v8.5.0 and removed v8.4.0 labels Jul 27, 2022
@csoulios csoulios added v8.6.0 and removed v8.5.0 labels Sep 21, 2022
@kingherc kingherc added v8.7.0 and removed v8.6.0 labels Nov 16, 2022
@rjernst rjernst added v8.8.0 and removed v8.7.0 labels Feb 8, 2023
@stefnestor
Copy link
Contributor Author

Deb's no longer with Elastic ( cc: @elastic/docs ) & per @DaveCTurner ... above, I'll side with this no longer being needed & close. Cheers all!

Now that #80651 is merged I think users don't need to do most of this stuff.

@stefnestor stefnestor closed this Apr 21, 2023
@stefnestor stefnestor deleted the stefnestor-patch-2 branch November 9, 2023 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts >docs General docs changes external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Delivery Meta label for Delivery team Team:Docs Meta label for docs team v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.