Skip to content

Avoid NPE in set_security_user without security #52691

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

Merged

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Feb 24, 2020

If security was disabled (explicitly), then the SecurityContext would
be null, but the set_security_user processor was still registered.

Attempting to define a pipeline that used that processor would fail
with an (intentional) NPE. This behaviour, introduced in #52032, is a
regression from previous releases where the pipeline was allowed, but
was no usable.

This change restores the previous behaviour (with a new warning).

Resolves: #52474

If security was disabled (explicitly), then the SecurityContext would
be null, but the set_security_user processor was still registered.

Attempting to define a pipeline that used that processor would fail
with an (intentional) NPE. This behaviour, introduced in elastic#52032, is a
regression from previous releases where the pipeline was allowed, but
was no usable.

This change restores the previous behaviour (with a new warning).
@tvernum tvernum added >non-issue :Security/Security Security issues without another label v8.0.0 v7.7.0 labels Feb 24, 2020
@tvernum tvernum requested review from ywangd and jkakavas February 24, 2020 05:38
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (:Security/Security)

@tvernum
Copy link
Contributor Author

tvernum commented Feb 24, 2020

I added 2 new QA tests for running the security plugin but not enabling it.

At the moment this set_security_user processor tests are the only things in those suites, but they're likely to be useful for other things we want to test when security is disabled/not-explicitly-enabled.

Marked >non-issue because this bug only exists in unreleased versions.

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM.

I understand that this change is to keep the existing behaviour. But I wonder whether there are some guidelines on how we should deal with these kinda of situations in general, i.e. user configures something that is not yet available. Here we are trying to be lenient. But issue #48773 suggests we should be strict at it (it is a different use case but spirit is similar) and I have PR up to fix it. Now I am not sure whether my PR should be labeled as "breaking" change (or even necessary).

Comment on lines 28 to 29
setting 'xpack.security.authc.token.enabled', 'true'
setting 'xpack.security.authc.api_key.enabled', 'true'
Copy link
Member

Choose a reason for hiding this comment

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

Are these two settings necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I'll remove them, I copied the build from another project, and missed them.

Comment on lines 49 to 50
logger.warn("Creating processor [{}] (tag [{}]) on field [{}] but no security context is available" +
" - this processor will fail at runtime if it is used", TYPE, tag, field);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how feasible or necessary it is to test the warning message. Another nitpick is maybe change "no security context is available" to something like "security is not enabled" for consistency with other exception message and easier to understand for users.

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'll come up with something. My concern is trying to diagnose a root cause from secondary symptoms (I know there's no security context, I don't know for sure exactly why that is), but I'll sort something out.

Copy link
Member

@jkakavas jkakavas left a comment

Choose a reason for hiding this comment

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

LGTM ,apart from echoing @ywangd 's suggestion to add a more user friendly error message. I think the only case ever where SecurityContext would be null is if security is disabled so we can point that out

this.field = field;
this.properties = properties;
}

@Override
public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
if (this.securityContext == null) {
throw new IllegalStateException("No security context available (is security enabled on this cluster?)");
Copy link
Member

Choose a reason for hiding this comment

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

If we are sure, we could state instead of frame it as a Q

@tvernum
Copy link
Contributor Author

tvernum commented Mar 5, 2020

@elasticmachine update branch

@tvernum tvernum merged commit cc0fdaf into elastic:master Mar 5, 2020
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Mar 13, 2020
If security was disabled (explicitly), then the SecurityContext would
be null, but the set_security_user processor was still registered.

Attempting to define a pipeline that used that processor would fail
with an (intentional) NPE. This behaviour, introduced in elastic#52032, is a
regression from previous releases where the pipeline was allowed, but
was no usable.

This change restores the previous behaviour (with a new warning).

Backport of: elastic#52691
tvernum added a commit that referenced this pull request Mar 17, 2020
If security was disabled (explicitly), then the SecurityContext would
be null, but the set_security_user processor was still registered.

Attempting to define a pipeline that used that processor would fail
with an (intentional) NPE. This behaviour, introduced in #52032, is a
regression from previous releases where the pipeline was allowed, but
was no usable.

This change restores the previous behaviour (with a new warning).

Backport of: #52691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE when creating a set_security_user processor
5 participants