-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add ECS compliant option for username field #54051
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6685b6a
Add esc compliant option for username field
ywangd 61486b7
Tighten escCompliant option to enforce parent field name to be user
ywangd 1562bdf
ensure ecs name consistency
ywangd f71af96
Merge remote-tracking branch 'origin/master' into es-51799-username-e…
ywangd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import java.util.function.Supplier; | ||
|
||
import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; | ||
import static org.elasticsearch.ingest.ConfigurationUtils.readBooleanProperty; | ||
import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalList; | ||
import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; | ||
|
||
|
@@ -43,10 +44,14 @@ public final class SetSecurityUserProcessor extends AbstractProcessor { | |
private final XPackLicenseState licenseState; | ||
private final String field; | ||
private final Set<Property> properties; | ||
private final boolean ecsCompliant; | ||
|
||
public SetSecurityUserProcessor(String tag, SecurityContext securityContext, XPackLicenseState licenseState, String field, | ||
Set<Property> properties) { | ||
Set<Property> properties, boolean ecsCompliant) { | ||
super(tag); | ||
if (ecsCompliant && false == "user".equals(field)) { | ||
throw newConfigurationException(TYPE, tag, "ecs_compliant", "ESC compliance requires [field] value to be 'user'"); | ||
} | ||
this.securityContext = securityContext; | ||
this.licenseState = Objects.requireNonNull(licenseState, "license state cannot be null"); | ||
if (licenseState.isAuthAllowed() == false) { | ||
|
@@ -57,6 +62,7 @@ public SetSecurityUserProcessor(String tag, SecurityContext securityContext, XPa | |
} | ||
this.field = field; | ||
this.properties = properties; | ||
this.ecsCompliant = ecsCompliant; | ||
} | ||
|
||
@Override | ||
|
@@ -93,7 +99,11 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception { | |
switch (property) { | ||
case USERNAME: | ||
if (user.principal() != null) { | ||
userObject.put("username", user.principal()); | ||
if (ecsCompliant) { | ||
userObject.put("name", user.principal()); | ||
} else { | ||
userObject.put("username", user.principal()); | ||
} | ||
} | ||
break; | ||
case FULL_NAME: | ||
|
@@ -179,6 +189,10 @@ Set<Property> getProperties() { | |
return properties; | ||
} | ||
|
||
boolean isEcsCompliant() { | ||
return ecsCompliant; | ||
} | ||
|
||
public static final class Factory implements Processor.Factory { | ||
|
||
private final Supplier<SecurityContext> securityContext; | ||
|
@@ -193,6 +207,7 @@ public Factory(Supplier<SecurityContext> securityContext, Supplier<XPackLicenseS | |
public SetSecurityUserProcessor create(Map<String, Processor.Factory> processorFactories, String tag, | ||
Map<String, Object> config) throws Exception { | ||
String field = readStringProperty(TYPE, tag, config, "field"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the field have a default value of |
||
final Boolean ecsCompliant = readBooleanProperty(TYPE, tag, config, "ecs_compliant", true); | ||
List<String> propertyNames = readOptionalList(TYPE, tag, config, "properties"); | ||
Set<Property> properties; | ||
if (propertyNames != null) { | ||
|
@@ -203,7 +218,8 @@ public SetSecurityUserProcessor create(Map<String, Processor.Factory> processorF | |
} else { | ||
properties = EnumSet.allOf(Property.class); | ||
} | ||
return new SetSecurityUserProcessor(tag, securityContext.get(), licenseState.get(), field, properties); | ||
return new SetSecurityUserProcessor(tag, securityContext.get(), licenseState.get(), field, properties, | ||
ecsCompliant); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it so that the user can specify the
username
property when defining the pipeline, but the field is actually namedname
(in 8 whenecs_compliat
istrue
by default). This is mildly confusing. I would suggest that we add a new propertyname
with the same value asusername
.