Skip to content

Commit

Permalink
Refactor SAML IdP Sessions - Follow up (#41779)
Browse files Browse the repository at this point in the history
* Remove SAML IdP session cookie.

* Add deprecation notes for SAML IdP Session endpoints.

* Address comment.

* Fix lint.

* Update deprecation notes to v18.
  • Loading branch information
Joerger authored Aug 17, 2024
1 parent 275832e commit 6f7156d
Show file tree
Hide file tree
Showing 10 changed files with 987 additions and 1,080 deletions.
13 changes: 13 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,8 @@ func (c *Client) GetSnowflakeSessions(ctx context.Context) ([]types.WebSession,
}

// ListSAMLIdPSessions gets a paginated list of SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) ListSAMLIdPSessions(ctx context.Context, pageSize int, pageToken, user string) ([]types.WebSession, string, error) {
resp, err := c.grpc.ListSAMLIdPSessions(
ctx,
Expand Down Expand Up @@ -1539,6 +1541,8 @@ func (c *Client) CreateSnowflakeSession(ctx context.Context, req types.CreateSno
}

// CreateSAMLIdPSession creates a SAML IdP session.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) CreateSAMLIdPSession(ctx context.Context, req types.CreateSAMLIdPSessionRequest) (types.WebSession, error) {
resp, err := c.grpc.CreateSAMLIdPSession(ctx, &proto.CreateSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand All @@ -1565,6 +1569,8 @@ func (c *Client) GetSnowflakeSession(ctx context.Context, req types.GetSnowflake
}

// GetSAMLIdPSession gets a SAML IdP session.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) GetSAMLIdPSession(ctx context.Context, req types.GetSAMLIdPSessionRequest) (types.WebSession, error) {
resp, err := c.grpc.GetSAMLIdPSession(ctx, &proto.GetSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand Down Expand Up @@ -1593,6 +1599,9 @@ func (c *Client) DeleteSnowflakeSession(ctx context.Context, req types.DeleteSno
}

// DeleteSAMLIdPSession removes a SAML IdP session.
// Deprecated: Do not use. As of v16, the Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead. This endpoint
// will be removed in v17.
func (c *Client) DeleteSAMLIdPSession(ctx context.Context, req types.DeleteSAMLIdPSessionRequest) error {
_, err := c.grpc.DeleteSAMLIdPSession(ctx, &proto.DeleteSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand All @@ -1613,6 +1622,8 @@ func (c *Client) DeleteAllSnowflakeSessions(ctx context.Context) error {
}

// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) DeleteAllSAMLIdPSessions(ctx context.Context) error {
_, err := c.grpc.DeleteAllSAMLIdPSessions(ctx, &emptypb.Empty{})
return trace.Wrap(err)
Expand All @@ -1625,6 +1636,8 @@ func (c *Client) DeleteUserAppSessions(ctx context.Context, req *proto.DeleteUse
}

// DeleteUserSAMLIdPSessions deletes all user’s SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) DeleteUserSAMLIdPSessions(ctx context.Context, username string) error {
req := &proto.DeleteUserSAMLIdPSessionsRequest{
Username: username,
Expand Down
1,865 changes: 936 additions & 929 deletions api/client/proto/authservice.pb.go

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions api/proto/teleport/legacy/client/proto/authservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2933,17 +2933,29 @@ service AuthService {
rpc DeleteAllSnowflakeSessions(google.protobuf.Empty) returns (google.protobuf.Empty);

// CreateSAMLIdPSession creates web session with sub kind saml_idp used by the SAML IdP.
rpc CreateSAMLIdPSession(CreateSAMLIdPSessionRequest) returns (CreateSAMLIdPSessionResponse);
rpc CreateSAMLIdPSession(CreateSAMLIdPSessionRequest) returns (CreateSAMLIdPSessionResponse) {
option deprecated = true;
}
// GetSAMLIdPSession returns a SAML IdP session with sub kind saml_idp.
rpc GetSAMLIdPSession(GetSAMLIdPSessionRequest) returns (GetSAMLIdPSessionResponse);
rpc GetSAMLIdPSession(GetSAMLIdPSessionRequest) returns (GetSAMLIdPSessionResponse) {
option deprecated = true;
}
// ListSAMLIdPSessions gets all SAML IdP sessions.
rpc ListSAMLIdPSessions(ListSAMLIdPSessionsRequest) returns (ListSAMLIdPSessionsResponse);
rpc ListSAMLIdPSessions(ListSAMLIdPSessionsRequest) returns (ListSAMLIdPSessionsResponse) {
option deprecated = true;
}
// DeleteSAMLIdPSession removes a SAML IdP session.
rpc DeleteSAMLIdPSession(DeleteSAMLIdPSessionRequest) returns (google.protobuf.Empty);
rpc DeleteSAMLIdPSession(DeleteSAMLIdPSessionRequest) returns (google.protobuf.Empty) {
option deprecated = true;
}
// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
rpc DeleteAllSAMLIdPSessions(google.protobuf.Empty) returns (google.protobuf.Empty);
rpc DeleteAllSAMLIdPSessions(google.protobuf.Empty) returns (google.protobuf.Empty) {
option deprecated = true;
}
// DeleteUserSAMLIdPSessions deletes all user’s SAML IdP sessions.
rpc DeleteUserSAMLIdPSessions(DeleteUserSAMLIdPSessionsRequest) returns (google.protobuf.Empty);
rpc DeleteUserSAMLIdPSessions(DeleteUserSAMLIdPSessionsRequest) returns (google.protobuf.Empty) {
option deprecated = true;
}

// GetWebSession gets a web session.
rpc GetWebSession(types.GetWebSessionRequest) returns (GetWebSessionResponse);
Expand Down
6 changes: 6 additions & 0 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5611,6 +5611,7 @@ func (a *ServerWithRoles) GetSnowflakeSession(ctx context.Context, req types.Get
}

// GetSAMLIdPSession gets a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) GetSAMLIdPSession(ctx context.Context, req types.GetSAMLIdPSessionRequest) (types.WebSession, error) {
if err := a.action(apidefaults.Namespace, types.KindWebSession, types.VerbRead); err != nil {
return nil, trace.Wrap(err)
Expand Down Expand Up @@ -5653,6 +5654,7 @@ func (a *ServerWithRoles) GetSnowflakeSessions(ctx context.Context) ([]types.Web
}

// ListSAMLIdPSessions gets a paginated list of SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) ListSAMLIdPSessions(ctx context.Context, pageSize int, pageToken, user string) ([]types.WebSession, string, error) {
if err := a.action(apidefaults.Namespace, types.KindWebSession, types.VerbList, types.VerbRead); err != nil {
return nil, "", trace.Wrap(err)
Expand Down Expand Up @@ -5694,6 +5696,7 @@ func (a *ServerWithRoles) CreateSnowflakeSession(ctx context.Context, req types.
}

// CreateSAMLIdPSession creates a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) CreateSAMLIdPSession(ctx context.Context, req types.CreateSAMLIdPSessionRequest) (types.WebSession, error) {
// Check if this a proxy service.
if !a.hasBuiltinRole(types.RoleProxy) {
Expand Down Expand Up @@ -5742,6 +5745,7 @@ func (a *ServerWithRoles) DeleteSnowflakeSession(ctx context.Context, req types.
}

// DeleteSAMLIdPSession removes a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) DeleteSAMLIdPSession(ctx context.Context, req types.DeleteSAMLIdPSessionRequest) error {
samlSession, err := a.authServer.GetSAMLIdPSession(ctx, types.GetSAMLIdPSessionRequest(req))
if err != nil {
Expand Down Expand Up @@ -5798,6 +5802,7 @@ func (a *ServerWithRoles) DeleteUserAppSessions(ctx context.Context, req *proto.
}

// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) DeleteAllSAMLIdPSessions(ctx context.Context) error {
if err := a.action(apidefaults.Namespace, types.KindWebSession, types.VerbList, types.VerbDelete); err != nil {
return trace.Wrap(err)
Expand All @@ -5810,6 +5815,7 @@ func (a *ServerWithRoles) DeleteAllSAMLIdPSessions(ctx context.Context) error {
}

// DeleteUserSAMLIdPSessions deletes all of a user's SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (a *ServerWithRoles) DeleteUserSAMLIdPSessions(ctx context.Context, username string) error {
// First, check if the current user can delete the request user sessions.
if err := a.canDeleteWebSession(username); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,7 @@ func (g *GRPCServer) GetSnowflakeSessions(ctx context.Context, e *emptypb.Empty)
}

// GetSAMLIdPSession gets a SAML IdPsession.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) GetSAMLIdPSession(ctx context.Context, req *authpb.GetSAMLIdPSessionRequest) (*authpb.GetSAMLIdPSessionResponse, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand All @@ -1646,6 +1647,7 @@ func (g *GRPCServer) GetSAMLIdPSession(ctx context.Context, req *authpb.GetSAMLI
}

// ListSAMLIdPSessions gets a paginated list of SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) ListSAMLIdPSessions(ctx context.Context, req *authpb.ListSAMLIdPSessionsRequest) (*authpb.ListSAMLIdPSessionsResponse, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand Down Expand Up @@ -1744,6 +1746,7 @@ func (g *GRPCServer) CreateSnowflakeSession(ctx context.Context, req *authpb.Cre
}

// CreateSAMLIdPSession creates a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) CreateSAMLIdPSession(ctx context.Context, req *authpb.CreateSAMLIdPSessionRequest) (*authpb.CreateSAMLIdPSessionResponse, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand Down Expand Up @@ -1813,6 +1816,7 @@ func (g *GRPCServer) DeleteUserAppSessions(ctx context.Context, req *authpb.Dele
}

// DeleteSAMLIdPSession removes a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) DeleteSAMLIdPSession(ctx context.Context, req *authpb.DeleteSAMLIdPSessionRequest) (*emptypb.Empty, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand All @@ -1829,6 +1833,7 @@ func (g *GRPCServer) DeleteSAMLIdPSession(ctx context.Context, req *authpb.Delet
}

// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) DeleteAllSAMLIdPSessions(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand All @@ -1843,6 +1848,7 @@ func (g *GRPCServer) DeleteAllSAMLIdPSessions(ctx context.Context, _ *emptypb.Em
}

// DeleteUserSAMLIdPSessions removes all of a user's SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (g *GRPCServer) DeleteUserSAMLIdPSessions(ctx context.Context, req *authpb.DeleteUserSAMLIdPSessionsRequest) (*emptypb.Empty, error) {
auth, err := g.authenticate(ctx)
if err != nil {
Expand Down
52 changes: 0 additions & 52 deletions lib/idp/saml/session.go

This file was deleted.

6 changes: 6 additions & 0 deletions lib/services/local/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (s *IdentityService) GetSnowflakeSession(ctx context.Context, req types.Get
}

// GetSAMLIdPSession gets a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) GetSAMLIdPSession(ctx context.Context, req types.GetSAMLIdPSessionRequest) (types.WebSession, error) {
if err := req.Check(); err != nil {
return nil, trace.Wrap(err)
Expand Down Expand Up @@ -98,6 +99,7 @@ func (s *IdentityService) GetSnowflakeSessions(ctx context.Context) ([]types.Web
}

// ListSAMLIdPSessions gets a paginated list of SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) ListSAMLIdPSessions(ctx context.Context, pageSize int, pageToken, user string) ([]types.WebSession, string, error) {
return s.listSessions(ctx, pageSize, pageToken, user, samlIdPPrefix, sessionsPrefix)
}
Expand Down Expand Up @@ -177,6 +179,7 @@ func (s *IdentityService) UpsertSnowflakeSession(ctx context.Context, session ty
}

// UpsertSAMLIdPSession creates a SAMLIdP web session.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) UpsertSAMLIdPSession(ctx context.Context, session types.WebSession) error {
return s.upsertSession(ctx, session, samlIdPPrefix, sessionsPrefix)
}
Expand Down Expand Up @@ -218,6 +221,7 @@ func (s *IdentityService) DeleteSnowflakeSession(ctx context.Context, req types.
}

// DeleteSAMLIdPSession removes a SAML IdP session.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) DeleteSAMLIdPSession(ctx context.Context, req types.DeleteSAMLIdPSessionRequest) error {
if err := s.Delete(ctx, backend.Key(samlIdPPrefix, sessionsPrefix, req.SessionID)); err != nil {
return trace.Wrap(err)
Expand Down Expand Up @@ -253,6 +257,7 @@ func (s *IdentityService) DeleteUserAppSessions(ctx context.Context, req *proto.
}

// DeleteUserSAMLIdPSessions removes all SAML IdP sessions for a particular user.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) DeleteUserSAMLIdPSessions(ctx context.Context, user string) error {
var token string

Expand Down Expand Up @@ -298,6 +303,7 @@ func (s *IdentityService) DeleteAllSnowflakeSessions(ctx context.Context) error
}

// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
// TODO(Joerger): DELETE IN v18.0.0
func (s *IdentityService) DeleteAllSAMLIdPSessions(ctx context.Context) error {
startKey := backend.ExactKey(samlIdPPrefix, sessionsPrefix)
if err := s.DeleteRange(ctx, startKey, backend.RangeEnd(startKey)); err != nil {
Expand Down
18 changes: 1 addition & 17 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import (
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/httplib"
"github.com/gravitational/teleport/lib/httplib/csrf"
samlidp "github.com/gravitational/teleport/lib/idp/saml"
"github.com/gravitational/teleport/lib/jwt"
"github.com/gravitational/teleport/lib/limiter"
"github.com/gravitational/teleport/lib/modules"
Expand Down Expand Up @@ -2271,18 +2270,6 @@ func clientMetaFromReq(r *http.Request) *authclient.ForwardedClientMetadata {
//
// {"message": "ok"}
func (h *Handler) deleteWebSession(w http.ResponseWriter, r *http.Request, _ httprouter.Params, ctx *SessionContext) (interface{}, error) {
// samlSessionCookie will not be set for users who are not authenticated with SAML IdP.
samlSessionCookie, err := r.Cookie(samlidp.SAMLSessionCookieName)
if err == nil && samlSessionCookie != nil && samlSessionCookie.Value != "" {
// TODO(sshah): Websession is not updated with SAML session details after SAML auth so
// it begs to check for a nil value below and then set a session with session ID
// retrieved from samlSessionCookie. We can skip this step below once we have a
// mechanism to update Websession with SAML session value.
if ctx.cfg.Session.GetSAMLSession() == nil {
ctx.cfg.Session.SetSAMLSession(&types.SAMLSessionData{ID: samlSessionCookie.Value})
}
}

clt, err := ctx.GetClient()
if err != nil {
h.log.
Expand All @@ -2301,8 +2288,7 @@ func (h *Handler) deleteWebSession(w http.ResponseWriter, r *http.Request, _ htt
}
}

err = h.logout(r.Context(), w, ctx)
if err != nil {
if err := h.logout(r.Context(), w, ctx); err != nil {
return nil, trace.Wrap(err)
}

Expand Down Expand Up @@ -2340,8 +2326,6 @@ func (h *Handler) logout(ctx context.Context, w http.ResponseWriter, sctx *Sessi
func clearSessionCookies(w http.ResponseWriter) {
// Clear Web UI session cookie
websession.ClearCookie(w)
// Clear SAML IdP session cookie
samlidp.ClearCookie(w)
}

type renewSessionRequest struct {
Expand Down
Loading

0 comments on commit 6f7156d

Please sign in to comment.