From 7adada055aeb3276bc645096981538acecdd7d9a Mon Sep 17 00:00:00 2001 From: Yassine Bounekhla <56373201+rudream@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:09:58 -0500 Subject: [PATCH] include access request metadata in app.session.start events (#48805) --- lib/auth/sessions.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/auth/sessions.go b/lib/auth/sessions.go index e93ac15133d11..3406f72771709 100644 --- a/lib/auth/sessions.go +++ b/lib/auth/sessions.go @@ -609,7 +609,17 @@ func (a *Server) CreateAppSessionFromReq(ctx context.Context, req NewAppSessionR log.Debugf("Generated application web session for %v with TTL %v.", req.User, req.SessionTTL) UserLoginCount.Inc() - userMetadata := req.Identity.GetUserMetadata() + // Extract the identity of the user from the certificate, this will include metadata from any actively assumed access requests. + certificate, err := tlsca.ParseCertificatePEM(session.GetTLSCert()) + if err != nil { + return nil, trace.Wrap(err) + } + identity, err := tlsca.FromSubject(certificate.Subject, certificate.NotAfter) + if err != nil { + return nil, trace.Wrap(err) + } + + userMetadata := identity.GetUserMetadata() userMetadata.User = session.GetUser() userMetadata.AWSRoleARN = req.AWSRoleARN