mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
* Convert auth_with_roles to use slog * allow benchmark tests to log * remove last use of logrus in github.go * remove last use of logrus in rotate.go * remove auth package logrus logger * convert auth.go to exclusively use slog * convert db.go to exclusively use slog * convert methods.go to exclusively use slog * convert password.go to exclusively use slog * convert join_ec2.go to exclusively use slog * convert join_iam.go to exclusively use slog * convert kube.go to exclusively use slog * convert oidc.go to exclusively use slog * convert saml.go to exclusively use slog * convert sso_diag_context.go to exclusively use slog * convert transport_credentials.go to exclusively use slog * convert trustedcluster.go to exclusively use slog * convert usertoken.go to exclusively use slog * convert user.go to exclusively use slog * remove logrus import * fix: pass in context * fix: remove new use of package logrus logger
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
/*
|
|
* Teleport
|
|
* Copyright (C) 2023 Gravitational, Inc.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
// Package auth implements certificate signing authority and access control server
|
|
// Authority server is composed of several parts:
|
|
//
|
|
// * Authority server itself that implements signing and acl logic
|
|
// * HTTP server wrapper for authority server
|
|
// * HTTP client wrapper
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gravitational/trace"
|
|
|
|
"github.com/gravitational/teleport/api/constants"
|
|
"github.com/gravitational/teleport/api/types"
|
|
apievents "github.com/gravitational/teleport/api/types/events"
|
|
"github.com/gravitational/teleport/lib/authz"
|
|
"github.com/gravitational/teleport/lib/events"
|
|
usagereporter "github.com/gravitational/teleport/lib/usagereporter/teleport"
|
|
)
|
|
|
|
// CompareAndSwapUser updates a user but fails if the value on the backend does
|
|
// not match the expected value.
|
|
func (a *Server) CompareAndSwapUser(ctx context.Context, new, existing types.User) error {
|
|
err := a.Services.CompareAndSwapUser(ctx, new, existing)
|
|
if err != nil {
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
var connectorName string
|
|
if new.GetCreatedBy().Connector == nil {
|
|
connectorName = constants.LocalConnector
|
|
} else {
|
|
connectorName = new.GetCreatedBy().Connector.ID
|
|
}
|
|
|
|
if err := a.emitter.EmitAuditEvent(ctx, &apievents.UserUpdate{
|
|
Metadata: apievents.Metadata{
|
|
Type: events.UserUpdatedEvent,
|
|
Code: events.UserUpdateCode,
|
|
},
|
|
UserMetadata: authz.ClientUserMetadata(ctx),
|
|
ResourceMetadata: apievents.ResourceMetadata{
|
|
Name: new.GetName(),
|
|
Expires: new.Expiry(),
|
|
},
|
|
Connector: connectorName,
|
|
Roles: new.GetRoles(),
|
|
}); err != nil {
|
|
a.logger.WarnContext(ctx, "Failed to emit user update event", "error", err)
|
|
}
|
|
|
|
usagereporter.EmitEditorChangeEvent(new.GetName(), existing.GetRoles(), new.GetRoles(), a.AnonymizeAndSubmit)
|
|
|
|
return nil
|
|
}
|