Skip to content

Emit new event for DynamoDB requests via app access#17595

Merged
GavinFrazar merged 43 commits intomasterfrom
gavinfrazar/improve_dynamodb_audit_events
Nov 15, 2022
Merged

Emit new event for DynamoDB requests via app access#17595
GavinFrazar merged 43 commits intomasterfrom
gavinfrazar/improve_dynamodb_audit_events

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar commented Oct 19, 2022

Relevant issue: #15572

I will open a PR to the webapps repo to add support for this new event in the Web UI audit log.

What

This PR adds auditing for the new AppSessionDynamoDBRequest event.

  • When an HTTP request for dynamodb is sent to the app service, an audit event is emitted to both the audit log and a session stream.
  • Users will be able to see the request event in the audit log, as well as by playing back the associated app session chunk with tsh play --format=json <chunk id>

Why

  • We want to add database-access for DynamoDB, and for that we plan to emit dynamo HTTP request events containing the request JSON body directly to the audit log.
  • The existing generic AppSessionRequest was not suitable, because we intentionally filter those from being emitted to the audit log - they are only sent to a session stream and uploaded later (typically after 5 minutes).
  • We will continue to support dynamodb via app-access; to be consistent with the planned database-access DynamoDB audit logging, we want to emit app access dynamo request events to the audit log and session stream.

How

I refactored the audit logging in the app service. A new file lib/srv/app/common/audit.go contains the definition of an interface for emitting audit events on session start/end/chunk/request.

  • This was to consolidate the audit logging in one consistent place.

I added an IsDynamoDB method to the types.Application interface, which can be used to determine if an app is for DynamoDB

I added a new event/code for dynamodb events.

I parse dynamo http request bodies into our wrapper for protobuf/types.Struct - this is because the body is already JSON and we need a type that is basically equivalent to map[string]interface{} so that the protobuf can be marshalled to JSON properly.
Example event body in WebUI using this data type for the body:

...
  "body": {
    "TableName": "test"
  },

If I had used bytes for the body type instead, the result is audit logs with base64 encoded json - which is unreadable. Example event body viewed in Web UI, if I use bytes as the body type:

...
"body": "eyJUYWJsZU5hbWUiOiAibmljLXRlc3QifQ==",

If I had used string for the body type and just copied the request body into the string, then when the protobuf is marshaled to JSON for display to the user, the string (which is already JSON) would be escaped to make valid JSON. Example event body viewed in Web UI if I use string as the body type:

...
  "body": "{\"TableName\": \"test\"}"

The branch for this PR is branched off of the protos change PR branch. Github will automatically retarget this PR base to master when the protos changes merge.

We will include a similar event for dynamodb via database-access.
We split the events so that app and database access events are not coupled.
This way we do not have to include optional database/app metadata in one event too.
@GavinFrazar GavinFrazar marked this pull request as ready for review October 19, 2022 19:39
@github-actions github-actions Bot added application-access audit-log Issues related to Teleports Audit Log labels Oct 19, 2022
Comment thread lib/service/service.go
Comment thread lib/utils/aws/aws.go Outdated
Comment thread lib/srv/app/aws/handler.go Outdated
Comment thread lib/srv/app/aws/handler.go
Comment thread lib/srv/app/aws/handler_test.go Outdated
Comment thread lib/utils/aws/aws.go Outdated
Copy link
Copy Markdown
Contributor

@tobiaszheller tobiaszheller left a comment

Choose a reason for hiding this comment

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

lgtm but would appreciate someone more experienced to take closer look

Comment thread lib/service/service.go Outdated
Comment thread lib/service/service.go Outdated
Comment thread lib/srv/app/common/audit.go Outdated
Comment thread lib/srv/app/aws/handler.go Outdated
Comment thread api/types/app.go Outdated
Comment thread lib/srv/app/common/audit.go
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

@smallinsky addressed your concerns

@GavinFrazar GavinFrazar force-pushed the gavinfrazar/improve_dynamodb_audit_events branch from f68a446 to c7a8c65 Compare November 2, 2022 01:05
Base automatically changed from gavinfrazar/improve_dynamodb_audit_events_proto to master November 2, 2022 01:23
@espadolini espadolini removed their request for review November 4, 2022 09:57
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

GavinFrazar commented Nov 15, 2022

@gabrielcorado @mdwn could one of you take a look? I need a group 2 approver apparently

edit: disregard I guess? It failed the reviewer check before but now it seems to be happy. idk why

@GavinFrazar GavinFrazar enabled auto-merge (squash) November 15, 2022 22:39
@GavinFrazar GavinFrazar merged commit d9b80fb into master Nov 15, 2022
@github-actions
Copy link
Copy Markdown
Contributor

@GavinFrazar See the table below for backport results.

Branch Result
branch/v11 Failed

@GavinFrazar GavinFrazar deleted the gavinfrazar/improve_dynamodb_audit_events branch November 16, 2022 01:05
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

Backport to v11 will be pending an answer from product team @smallinsky

GavinFrazar added a commit that referenced this pull request Dec 24, 2022
* Add a new event for app access requests sent to AWS DynamoDB
GavinFrazar added a commit that referenced this pull request Dec 29, 2022
* Add a new event for app access requests sent to AWS DynamoDB
GavinFrazar added a commit that referenced this pull request Dec 29, 2022
* Emit new event for DynamoDB requests via app access (#17595)

* Add a new event for app access requests sent to AWS DynamoDB

* Refactor app access (#19387)

* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request instead of making a new request, and rewrite url to force https
* update header handling
* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
* Remove obsolete header copying helper func

* Remove api error header from backport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

application-access audit-log Issues related to Teleports Audit Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants