-
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
Changes from 2 commits
6685b6a
61486b7
1562bdf
f71af96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 escCompliant; | ||
|
||
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.escCompliant = ecsCompliant; | ||
} | ||
|
||
@Override | ||
|
@@ -93,7 +99,11 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception { | |
switch (property) { | ||
case USERNAME: | ||
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. This makes it so that the user can specify the |
||
if (user.principal() != null) { | ||
userObject.put("username", user.principal()); | ||
if (escCompliant) { | ||
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 isEscCompliant() { | ||
return escCompliant; | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
|
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.
there are many places with the
esc
->ecs
inversion (including the PR title).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.
Fixed most of them other than the one in the PR branch name. Thanks for spotting this.