Skip to content

support session metadata generation for encrypted sessions#60838

Merged
tigrato merged 10 commits intomasterfrom
tigrato/supportsummariesmetadataencrypted
Nov 3, 2025
Merged

support session metadata generation for encrypted sessions#60838
tigrato merged 10 commits intomasterfrom
tigrato/supportsummariesmetadataencrypted

Conversation

@tigrato
Copy link
Copy Markdown
Contributor

@tigrato tigrato commented Oct 30, 2025

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

Changelog: Enabled summarization and metadata generation for encrypted session recordings, storing metadata and summaries in encrypted form.

@tigrato tigrato requested review from eriktate and ryanclark October 30, 2025 17:17
@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log size/md labels Oct 30, 2025
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>
@tigrato tigrato force-pushed the tigrato/supportsummariesmetadataencrypted branch from d669043 to 56e1fbf Compare October 30, 2025 18:05
Comment thread lib/events/auditlog.go
Comment thread lib/events/complete.go
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

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?

Comment thread lib/auth/recordingencryption/recordingencryptionv1/service.go
Comment thread lib/auth/recordingencryption/recordingencryptionv1/service.go Outdated
if err := summarizer.SummarizeSSH(ctx, o); err != nil {
s.logger.WarnContext(ctx, "failed to summarize upload", "error", err)
}
metadataSvc := s.recordingMetadataProvider.Service()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if recordingMetadataProvider is nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nothing. Nothing will fail because it will return a no-op service

Comment thread lib/auth/recordingmetadata/recordingmetadatav1/recordingmetadata.go Outdated
Comment thread lib/auth/recordingmetadata/recordingmetadatav1/service.go Outdated
Comment thread lib/events/auditlog.go Outdated
Comment on lines +684 to +718
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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment on lines +18 to +32
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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Thanks Tiago!

ServerID: "testcluster",
PrintData: []string{"net", "stat"},
})
returnChan <- events[len(events)-1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we stream at least the last two events to make sure earlier events are discarded?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is already tested in sessionend_test.go.

@tigrato tigrato enabled auto-merge November 3, 2025 11:53
@tigrato tigrato added this pull request to the merge queue Nov 3, 2025
Merged via the queue into master with commit ebc3543 Nov 3, 2025
41 checks passed
@tigrato tigrato deleted the tigrato/supportsummariesmetadataencrypted branch November 3, 2025 12:33
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@tigrato See the table below for backport results.

Branch Result
branch/v18 Failed

tigrato added a commit that referenced this pull request Nov 3, 2025
* 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>
tigrato added a commit that referenced this pull request Nov 3, 2025
* 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>
github-merge-queue bot pushed a commit that referenced this pull request Nov 3, 2025
…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>
mmcallister pushed a commit that referenced this pull request Nov 19, 2025
* 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>
mmcallister pushed a commit that referenced this pull request Nov 20, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-log Issues related to Teleports Audit Log backport/branch/v18 size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants