Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e
Submodule e updated from 4343bd to 53fee2
52 changes: 49 additions & 3 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3511,6 +3511,11 @@ func (a *ServerWithRoles) CreateOIDCAuthRequest(ctx context.Context, req types.O
}
}

// Only the Proxy service can create web sessions via OIDC connector.
if req.CreateWebSession && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}

oidcReq, err := a.authServer.CreateOIDCAuthRequest(ctx, req)
if err != nil {
emitSSOLoginFailureEvent(a.CloseContext(), a.authServer.emitter, events.LoginMethodOIDC, err, req.SSOTestFlow)
Expand All @@ -3531,7 +3536,17 @@ func (a *ServerWithRoles) GetOIDCAuthRequest(ctx context.Context, id string) (*t

func (a *ServerWithRoles) ValidateOIDCAuthCallback(ctx context.Context, q url.Values) (*OIDCAuthResponse, error) {
// auth callback is it's own authz, no need to check extra permissions
return a.authServer.ValidateOIDCAuthCallback(ctx, q)
resp, err := a.authServer.ValidateOIDCAuthCallback(ctx, q)
if err != nil {
return nil, trace.Wrap(err)
}

// Only the Proxy service can create web sessions via OIDC connector.
if resp.Session != nil && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
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 also delete the session? Something like a.WebSession().Delete(ctx, ...)

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.

Good point. I moved the check to CreateXXXAuthRequest so we can check before creating the web session rather than deleting it.

Copy link
Copy Markdown
Contributor Author

@Joerger Joerger Oct 16, 2023

Choose a reason for hiding this comment

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

Actually, I've just put the check in both places for redundancy. The session will automatically expire on its own, and this path should be practically unreachable, so I think it's ok not to delete it explicitly. Ideally we should check before creating the web session but it would require a bit of a refactor.

}

return resp, nil
}

func (a *ServerWithRoles) DeleteOIDCConnector(ctx context.Context, connectorID string) error {
Expand Down Expand Up @@ -3625,6 +3640,11 @@ func (a *ServerWithRoles) CreateSAMLAuthRequest(ctx context.Context, req types.S
}
}

// Only the Proxy service can create web sessions via SAML connector.
if req.CreateWebSession && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}

samlReq, err := a.authServer.CreateSAMLAuthRequest(ctx, req)
if err != nil {
emitSSOLoginFailureEvent(a.CloseContext(), a.authServer.emitter, events.LoginMethodSAML, err, req.SSOTestFlow)
Expand All @@ -3637,7 +3657,17 @@ func (a *ServerWithRoles) CreateSAMLAuthRequest(ctx context.Context, req types.S
// ValidateSAMLResponse validates SAML auth response.
func (a *ServerWithRoles) ValidateSAMLResponse(ctx context.Context, re string, connectorID string) (*SAMLAuthResponse, error) {
// auth callback is it's own authz, no need to check extra permissions
return a.authServer.ValidateSAMLResponse(ctx, re, connectorID)
resp, err := a.authServer.ValidateSAMLResponse(ctx, re, connectorID)
if err != nil {
return nil, trace.Wrap(err)
}

// Only the Proxy service can create web sessions via SAML connector.
if resp.Session != nil && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
Comment thread
Joerger marked this conversation as resolved.
Outdated
}

return resp, nil
}

// GetSAMLAuthRequest returns SAML auth request if found.
Expand Down Expand Up @@ -3785,6 +3815,11 @@ func (a *ServerWithRoles) CreateGithubAuthRequest(ctx context.Context, req types
}
}

// Only the Proxy service can create web sessions via Github connector.
if req.CreateWebSession && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}

githubReq, err := a.authServer.CreateGithubAuthRequest(ctx, req)
if err != nil {
emitSSOLoginFailureEvent(a.authServer.closeCtx, a.authServer.emitter, events.LoginMethodGithub, err, req.SSOTestFlow)
Expand All @@ -3804,7 +3839,18 @@ func (a *ServerWithRoles) GetGithubAuthRequest(ctx context.Context, stateToken s
}

func (a *ServerWithRoles) ValidateGithubAuthCallback(ctx context.Context, q url.Values) (*GithubAuthResponse, error) {
return a.authServer.ValidateGithubAuthCallback(ctx, q)
// auth callback is it's own authz, no need to check extra permissions
resp, err := a.authServer.ValidateGithubAuthCallback(ctx, q)
if err != nil {
return nil, trace.Wrap(err)
}

// Only the Proxy service can create web sessions via Github connector.
if resp.Session != nil && !a.hasBuiltinRole(types.RoleProxy) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}

return resp, nil
}

// EmitAuditEvent emits a single audit event
Expand Down
13 changes: 7 additions & 6 deletions lib/auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,13 @@ func (a *Server) validateGithubAuthCallback(ctx context.Context, diagCtx *SSODia
// If the request is coming from a browser, create a web session.
if req.CreateWebSession {
session, err := a.CreateWebSessionFromReq(ctx, types.NewWebSessionRequest{
User: userState.GetName(),
Roles: userState.GetRoles(),
Traits: userState.GetTraits(),
SessionTTL: params.SessionTTL,
LoginTime: a.clock.Now().UTC(),
LoginIP: req.ClientLoginIP,
User: userState.GetName(),
Roles: userState.GetRoles(),
Traits: userState.GetTraits(),
SessionTTL: params.SessionTTL,
LoginTime: a.clock.Now().UTC(),
LoginIP: req.ClientLoginIP,
AttestWebSession: true,
})
if err != nil {
return nil, trace.Wrap(err, "Failed to create web session.")
Expand Down