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 02aee9 to 1cc62c
52 changes: 49 additions & 3 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3580,6 +3580,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 @@ -3600,7 +3605,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")
}

return resp, nil
}

func (a *ServerWithRoles) DeleteOIDCConnector(ctx context.Context, connectorID string) error {
Expand Down Expand Up @@ -3665,6 +3680,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 @@ -3677,7 +3697,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")
}

return resp, nil
}

// GetSAMLAuthRequest returns SAML auth request if found.
Expand Down Expand Up @@ -3799,6 +3829,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 @@ -3818,7 +3853,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 @@ -646,12 +646,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