-
Notifications
You must be signed in to change notification settings - Fork 165
[RORDEV-1414] ES node details audit reporting #1116
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
Open
mgoworko
wants to merge
30
commits into
sscarduzio:develop
Choose a base branch
from
mgoworko:RORDEV-1414-es-node-details-reporting
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
911872b
qs
mgoworko 23c9fd3
qs
mgoworko f424f8e
qs
mgoworko 0e3d102
Merge remote-tracking branch 'origin/develop' into 1414
mgoworko 1ef3add
qs
mgoworko 90708dc
qs
mgoworko d17387a
qs
mgoworko d7d1709
Merge remote-tracking branch 'origin/develop' into 1414
mgoworko 85c7115
qs
mgoworko eb74b87
Merge remote-tracking branch 'origin/develop' into 1414
mgoworko d207a7f
qs
mgoworko 2fe43a2
qs
mgoworko 37efe2d
qs
mgoworko 65f1e9b
qs
mgoworko b59a83b
qs
mgoworko bd0dd23
Merge remote-tracking branch 'origin/develop' into 1414
mgoworko eaf09fc
merge fixes
mgoworko 2a74995
qs
mgoworko 7afc0b9
qs
mgoworko 50062d9
qs
mgoworko 72b9af7
qs
mgoworko 01cceae
review changes and fix Scala 2.11 cross compile
mgoworko 809c1b7
versioned QueryAuditLogSerializer and fixed unit tests
mgoworko 446d0e4
qs
mgoworko 3558efa
add test
mgoworko 1ee2e3b
Merge remote-tracking branch 'origin/develop' into RORDEV-1414-es-nod…
mgoworko b7e875f
fix test compilation problems
mgoworko 8e02b87
qs
mgoworko 80998ed
qs
mgoworko 9970cd8
Fix Scala 2.11 cross build
mgoworko 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
20 changes: 20 additions & 0 deletions
20
audit/src/main/scala/tech/beshu/ror/audit/AuditEnvironmentContext.scala
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.audit | ||
|
||
final case class AuditEnvironmentContext(esNodeName: String, | ||
esClusterName: String) |
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
99 changes: 99 additions & 0 deletions
99
audit/src/main/scala/tech/beshu/ror/audit/instances/DefaultAuditLogSerializerV1.scala
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.audit.instances | ||
|
||
import org.json.JSONObject | ||
import tech.beshu.ror.audit.AuditResponseContext._ | ||
import tech.beshu.ror.audit.{AuditEnvironmentContext, AuditLogSerializer, AuditRequestContext, AuditResponseContext} | ||
|
||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
import scala.collection.JavaConverters._ | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
class DefaultAuditLogSerializerV1 extends AuditLogSerializer { | ||
|
||
private val timestampFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(ZoneId.of("GMT")) | ||
|
||
override def onResponse(responseContext: AuditResponseContext, | ||
environmentContext: AuditEnvironmentContext): Option[JSONObject] = responseContext match { | ||
case Allowed(requestContext, verbosity, reason) => | ||
verbosity match { | ||
case Verbosity.Info => | ||
Some(createEntry(matched = true, "ALLOWED", reason, responseContext.duration, requestContext, None)) | ||
case Verbosity.Error => | ||
None | ||
} | ||
case ForbiddenBy(requestContext, _, reason) => | ||
Some(createEntry(matched = true, "FORBIDDEN", reason, responseContext.duration, requestContext, None)) | ||
case Forbidden(requestContext) => | ||
Some(createEntry(matched = false, "FORBIDDEN", "default", responseContext.duration, requestContext, None)) | ||
case RequestedIndexNotExist(requestContext) => | ||
Some(createEntry(matched = false, "INDEX NOT EXIST", "Requested index doesn't exist", responseContext.duration, requestContext, None)) | ||
case Errored(requestContext, cause) => | ||
Some(createEntry(matched = false, "ERRORED", "error", responseContext.duration, requestContext, Some(cause))) | ||
} | ||
|
||
private def createEntry(matched: Boolean, | ||
finalState: String, | ||
reason: String, | ||
duration: FiniteDuration, | ||
requestContext: AuditRequestContext, | ||
error: Option[Throwable]) = { | ||
new JSONObject() | ||
.put("match", matched) | ||
.put("block", reason) | ||
.put("id", requestContext.id) | ||
.put("final_state", finalState) | ||
.put("@timestamp", timestampFormatter.format(requestContext.timestamp)) | ||
.put("correlation_id", requestContext.correlationId) | ||
.put("processingMillis", duration.toMillis) | ||
.put("error_type", error.map(_.getClass.getSimpleName).orNull) | ||
.put("error_message", error.map(_.getMessage).orNull) | ||
.put("content_len", requestContext.contentLength) | ||
.put("content_len_kb", requestContext.contentLength / 1024) | ||
.put("type", requestContext.`type`) | ||
.put("origin", requestContext.remoteAddress) | ||
.put("destination", requestContext.localAddress) | ||
.put("xff", requestContext.requestHeaders.getValue("X-Forwarded-For").flatMap(_.headOption).orNull) | ||
.put("task_id", requestContext.taskId) | ||
.put("req_method", requestContext.httpMethod) | ||
.put("headers", requestContext.requestHeaders.names.asJava) | ||
.put("path", requestContext.uriPath) | ||
.put("user", SerializeUser.serialize(requestContext).orNull) | ||
.put("impersonated_by", requestContext.impersonatedByUserName.orNull) | ||
.put("action", requestContext.action) | ||
.put("indices", if (requestContext.involvesIndices) requestContext.indices.toList.asJava else List.empty.asJava) | ||
.put("acl_history", requestContext.history) | ||
.mergeWith(requestContext.generalAuditEvents) | ||
} | ||
|
||
private implicit class JsonObjectOps(val mainJson: JSONObject) { | ||
def mergeWith(secondaryJson: JSONObject): JSONObject = { | ||
jsonKeys(secondaryJson).foldLeft(mainJson) { | ||
case (json, name) if !json.has(name) => | ||
json.put(name, secondaryJson.get(name)) | ||
case (json, _) => | ||
json | ||
} | ||
} | ||
|
||
private def jsonKeys(json: JSONObject) = { | ||
Option(JSONObject.getNames(json)).toList.flatten | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
audit/src/main/scala/tech/beshu/ror/audit/instances/DefaultAuditLogSerializerV2.scala
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.audit.instances | ||
|
||
import org.json.JSONObject | ||
import tech.beshu.ror.audit.{AuditEnvironmentContext, AuditResponseContext} | ||
|
||
class DefaultAuditLogSerializerV2 extends DefaultAuditLogSerializerV1 { | ||
|
||
override def onResponse(responseContext: AuditResponseContext, | ||
environmentContext: AuditEnvironmentContext): Option[JSONObject] = { | ||
lazy val additionalFields = Map( | ||
"es_node_name" -> environmentContext.esNodeName, | ||
"es_cluster_name" -> environmentContext.esClusterName | ||
) | ||
super.onResponse(responseContext, environmentContext) | ||
.map(additionalFields.foldLeft(_) { case (soFar, (key, value)) => soFar.put(key, value) }) | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
audit/src/main/scala/tech/beshu/ror/audit/instances/QueryAuditLogSerializerV1.scala
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.audit.instances | ||
|
||
import org.json.JSONObject | ||
import tech.beshu.ror.audit.{AuditEnvironmentContext, AuditResponseContext} | ||
|
||
class QueryAuditLogSerializerV1 extends DefaultAuditLogSerializerV1 { | ||
|
||
override def onResponse(responseContext: AuditResponseContext, | ||
environmentContext: AuditEnvironmentContext): Option[JSONObject] = { | ||
super.onResponse(responseContext, environmentContext) | ||
.map(_.put("content", responseContext.requestContext.content)) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
audit/src/main/scala/tech/beshu/ror/audit/instances/QueryAuditLogSerializerV2.scala
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.audit.instances | ||
|
||
import org.json.JSONObject | ||
import tech.beshu.ror.audit.{AuditEnvironmentContext, AuditResponseContext} | ||
|
||
class QueryAuditLogSerializerV2 extends DefaultAuditLogSerializerV2 { | ||
|
||
override def onResponse(responseContext: AuditResponseContext, | ||
environmentContext: AuditEnvironmentContext): Option[JSONObject] = { | ||
super.onResponse(responseContext, environmentContext) | ||
.map(_.put("content", responseContext.requestContext.content)) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
What about backward compatibility here? The existing custom serializers should work with the new approach too.
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.
I modified it in a following way:
def onResponse
is restored to its previous stateAuditEnvironmentContext
is instead provided in a Serializer's constructor, with modified class Decoder implementation