support session metadata generation for encrypted sessions#60838
support session metadata generation for encrypted sessions#60838
Conversation
Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
d669043 to
56e1fbf
Compare
rosstimothy
left a comment
There was a problem hiding this comment.
Can you include a manual test plan either in the PR description of in a comment on this PR detailing which configurations you tested in and that all tests pass as expected?
| if err := summarizer.SummarizeSSH(ctx, o); err != nil { | ||
| s.logger.WarnContext(ctx, "failed to summarize upload", "error", err) | ||
| } | ||
| metadataSvc := s.recordingMetadataProvider.Service() |
There was a problem hiding this comment.
What happens if recordingMetadataProvider is nil?
There was a problem hiding this comment.
nothing. Nothing will fail because it will return a no-op service
| err = l.UploadHandler.CompleteUpload(ctx, *upload, streamParts) | ||
| if err != nil { | ||
| return trace.Wrap(err, "completing upload") | ||
| } | ||
|
|
||
| sessionEnd, err := l.findSessionEndEvent(ctx, upload.SessionID) | ||
| if err != nil || sessionEnd == nil { | ||
| return nil | ||
| } | ||
|
|
||
| summarizer := l.AuditLogConfig.SessionSummarizerProvider.SessionSummarizer() | ||
| switch o := sessionEnd.(type) { | ||
| case *apievents.SessionEnd: | ||
| if err := summarizer.SummarizeSSH(ctx, o); err != nil { | ||
| l.log.WarnContext(ctx, "failed to summarize upload", "error", err) | ||
| } | ||
| metadataSvc := l.AuditLogConfig.RecordingMetadataProvider.Service() | ||
| if !o.EndTime.IsZero() && !o.StartTime.IsZero() { | ||
| duration := o.EndTime.Sub(o.StartTime) | ||
| if err := metadataSvc.ProcessSessionRecording(ctx, upload.SessionID, duration); err != nil { | ||
| l.log.WarnContext(ctx, "failed to process session recording metadata", "error", err) | ||
| } | ||
| } | ||
| case *apievents.DatabaseSessionEnd: | ||
| if err := summarizer.SummarizeDatabase(ctx, o); err != nil { | ||
| l.log.WarnContext(ctx, "failed to summarize upload", "error", err) | ||
| } | ||
| } | ||
|
|
||
| return trace.Wrap(l.UploadHandler.CompleteUpload(ctx, *upload, streamParts), "completing upload") | ||
| return nil | ||
| } | ||
|
|
||
| // findSessionEndEvent streams session events to find the session end event for the given session ID. | ||
| // It returns either a SessionEnd or DatabaseSessionEnd event, or nil if none is found. | ||
| func (l *AuditLog) findSessionEndEvent(ctx context.Context, sessionID session.ID) (apievents.AuditEvent, error) { |
There was a problem hiding this comment.
This is the second time in this PR that this same pattern has been implemented. Is there anything that we can do to avoid the repetition?
There was a problem hiding this comment.
I plan to change this code soon to avoid downloading all the sessions to find the session.end event. instead I plan to download only the last parts of the session
| package postprocessing | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/gravitational/trace" | ||
|
|
||
| apievents "github.com/gravitational/teleport/api/types/events" | ||
| "github.com/gravitational/teleport/lib/auth/recordingmetadata" | ||
| "github.com/gravitational/teleport/lib/auth/summarizer" | ||
| "github.com/gravitational/teleport/lib/session" | ||
| ) | ||
|
|
||
| // SessionPostProcessorConfig is the configuration for the session post-processor. | ||
| type SessionPostProcessorConfig struct { |
There was a problem hiding this comment.
Thanks for unifying this in a single location! I'm struggling to come up with a good suggestion, naming is hard, but postprocessing.SessionPostProcessorConfig is slightly redundant and a lot to type.
My first instinct was session.PostProcessingConfig but session is overloaded.
| ServerID: "testcluster", | ||
| PrintData: []string{"net", "stat"}, | ||
| }) | ||
| returnChan <- events[len(events)-1] |
There was a problem hiding this comment.
Should we stream at least the last two events to make sure earlier events are discarded?
There was a problem hiding this comment.
This is already tested in sessionend_test.go.
* support session metadata generation for encrypted sessions Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * add unit tests for session completer * add unit tests for audit log session completer * move file decrypter to file * handle code review comments * add todo list * remove duplicate code * fix typo * rename --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
* support session metadata generation for encrypted sessions Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * add unit tests for session completer * add unit tests for audit log session completer * move file decrypter to file * handle code review comments * add todo list * remove duplicate code * fix typo * rename --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
…60945) * support session metadata generation for encrypted sessions Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 * add unit tests for session completer * add unit tests for audit log session completer * move file decrypter to file * handle code review comments * add todo list * remove duplicate code * fix typo * rename --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
* support session metadata generation for encrypted sessions Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * add unit tests for session completer * add unit tests for audit log session completer * move file decrypter to file * handle code review comments * add todo list * remove duplicate code * fix typo * rename --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
* support session metadata generation for encrypted sessions Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server. This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog. Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the `session.end` event. This can be further improved in the future. This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data. Contributes to #60689 Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * add unit tests for session completer * add unit tests for audit log session completer * move file decrypter to file * handle code review comments * add todo list * remove duplicate code * fix typo * rename --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Encrypted sessions do not use the normal uploader flow as the agents encrypt the data themselves and push the encrypted blobs directly to auth server.
This behavior caused the session metadata and summaries generation to be skipped. This PR hooks the session summarization and metadata generation into the encrypted sessions completer - it can be via gRPC call or the local AuditLog.
Since the encrypted session recordings receives the payloads encrypted and parts might be sent to different auth servers in case one disconnects in the middle, we always stream the full parts to retrieve the
session.endevent. This can be further improved in the future.This PR also adds support for encrypted session metadata and thumbnails files so all data stored in the recordings backend will be encrypted and users can't download the file and inspect the svg data.
Contributes to #60689
Changelog: Enabled summarization and metadata generation for encrypted session recordings, storing metadata and summaries in encrypted form.