Skip to content

Commit

Permalink
Merge branch 'master' into bernard/datadog-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardjkim authored Oct 1, 2024
2 parents 011f816 + 685dd44 commit a04413d
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 53 deletions.
2 changes: 1 addition & 1 deletion build.assets/tooling/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gravitational/teleport/build.assets/tooling

go 1.23.1
go 1.23.2

require (
github.com/Masterminds/sprig/v3 v3.3.0
Expand Down
2 changes: 1 addition & 1 deletion build.assets/versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Keep versions in sync with devbox.json, when applicable.

# Sync with devbox.json.
GOLANG_VERSION ?= go1.23.1
GOLANG_VERSION ?= go1.23.2
GOLANGCI_LINT_VERSION ?= v1.61.0

NODE_VERSION ?= 20.14.0
Expand Down
3 changes: 3 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ const (
// ComponentSession is an active session.
ComponentSession = "session"

// ComponentHostUsers represents host user management.
ComponentHostUsers = "hostusers"

// ComponentDynamoDB represents dynamodb clients
ComponentDynamoDB = "dynamodb"

Expand Down
2 changes: 1 addition & 1 deletion e
Submodule e updated from 3abd3a to c2ed83
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gravitational/teleport

go 1.23.1
go 1.23.2

require (
cloud.google.com/go/cloudsqlconn v1.12.1
Expand Down
2 changes: 1 addition & 1 deletion integration/hostuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestRootHostUsersBackend(t *testing.T) {
t.Cleanup(func() {
os.RemoveAll(testHome)
})
require.NoError(t, err)
require.ErrorIs(t, err, os.ErrExist)
require.NoFileExists(t, "/tmp/ignoreme")
})
}
Expand Down
2 changes: 1 addition & 1 deletion integrations/event-handler/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gravitational/teleport/integrations/event-handler

go 1.23.1
go 1.23.2

require (
github.com/alecthomas/kong v1.2.1
Expand Down
2 changes: 1 addition & 1 deletion integrations/terraform/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gravitational/teleport/integrations/terraform

go 1.23.1
go 1.23.2

// Doc generation tooling
require github.com/hashicorp/terraform-plugin-docs v0.0.0 // replaced
Expand Down
18 changes: 14 additions & 4 deletions lib/srv/sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"os"
"os/user"
"path"
Expand Down Expand Up @@ -103,9 +104,12 @@ func MsgParticipantCtrls(w io.Writer, m types.SessionParticipantMode) error {
type SessionRegistry struct {
SessionRegistryConfig

// log holds the structured logger
// deprecated: log holds the legacy logrus structured logger
log *log.Entry

// logger holds the structured logger
logger *slog.Logger

// sessions holds a map between session ID and the session object. Used to
// find active sessions as well as close all sessions when the registry
// is closing.
Expand Down Expand Up @@ -185,6 +189,7 @@ func NewSessionRegistry(cfg SessionRegistryConfig) (*SessionRegistry, error) {
log: log.WithFields(log.Fields{
teleport.ComponentKey: teleport.Component(teleport.ComponentSession, cfg.Srv.Component()),
}),
logger: slog.With(teleport.ComponentKey, teleport.Component(teleport.ComponentSession, cfg.Srv.Component())),
sessions: make(map[rsession.ID]*session),
users: cfg.Srv.GetHostUsers(),
sudoers: cfg.Srv.GetHostSudoers(),
Expand Down Expand Up @@ -289,15 +294,19 @@ func (s *SessionRegistry) WriteSudoersFile(identityContext IdentityContext) (io.
// If the returned closer is not nil, it must be called at the end of the session to
// clean up the local user.
func (s *SessionRegistry) UpsertHostUser(identityContext IdentityContext) (bool, io.Closer, error) {
ctx := s.Srv.Context()
log := s.logger.With("host_username", identityContext.Login)

if identityContext.Login == teleport.SSHSessionJoinPrincipal {
return false, nil, nil
}

if !s.Srv.GetCreateHostUser() || s.users == nil {
s.log.Debug("Not creating host user: node has disabled host user creation.")
log.DebugContext(ctx, "Not creating host user: node has disabled host user creation.")
return false, nil, nil // not an error to not be able to create host users
}

log.DebugContext(ctx, "Attempting to upsert host user")
ui, accessErr := identityContext.AccessChecker.HostUsers(s.Srv.GetInfo())
if trace.IsAccessDenied(accessErr) {
existsErr := s.users.UserExists(identityContext.Login)
Expand All @@ -316,16 +325,17 @@ func (s *SessionRegistry) UpsertHostUser(identityContext IdentityContext) (bool,

userCloser, err := s.users.UpsertUser(identityContext.Login, *ui)
if err != nil {
log.Debugf("Error creating user %s: %s", identityContext.Login, err)
log.DebugContext(ctx, "Error creating user", "error", err)

if errors.Is(err, unmanagedUserErr) {
log.Warnf("User %q is not managed by teleport. Either manually delete the user from this machine or update the host_groups defined in their role to include %q. https://goteleport.com/docs/enroll-resources/server-access/guides/host-user-creation/#migrating-unmanaged-users", identityContext.Login, types.TeleportKeepGroup)
log.WarnContext(ctx, "User is not managed by teleport. Either manually delete the user from this machine or update the host_groups defined in their role to include 'teleport-keep'. https://goteleport.com/docs/enroll-resources/server-access/guides/host-user-creation/#migrating-unmanaged-users")
return false, nil, nil
}

if !trace.IsAlreadyExists(err) {
return false, nil, trace.Wrap(err)
}
log.DebugContext(ctx, "Host user already exists")
}

return true, userCloser, nil
Expand Down
12 changes: 12 additions & 0 deletions lib/srv/sess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func TestSession_newRecorder(t *testing.T) {
id: "test",
log: logger,
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &mockServer{
component: teleport.ComponentNode,
Expand All @@ -279,6 +280,7 @@ func TestSession_newRecorder(t *testing.T) {
id: "test",
log: logger,
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &mockServer{
component: teleport.ComponentNode,
Expand All @@ -299,6 +301,7 @@ func TestSession_newRecorder(t *testing.T) {
id: "test",
log: logger,
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &mockServer{
component: teleport.ComponentNode,
Expand Down Expand Up @@ -338,6 +341,7 @@ func TestSession_newRecorder(t *testing.T) {
id: "test",
log: logger,
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &mockServer{
component: teleport.ComponentNode,
Expand Down Expand Up @@ -384,6 +388,7 @@ func TestSession_newRecorder(t *testing.T) {
id: "test",
log: logger,
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &mockServer{
component: teleport.ComponentNode,
Expand Down Expand Up @@ -1122,6 +1127,7 @@ func TestTrackingSession(t *testing.T) {
id: rsession.NewID(),
log: utils.NewLoggerForTests().WithField(teleport.ComponentKey, "test-session"),
registry: &SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: srv,
SessionTrackerService: trackingService,
Expand Down Expand Up @@ -1527,6 +1533,7 @@ func TestUpsertHostUser(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
registry := SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &fakeServer{createHostUser: c.createHostUser},
},
Expand Down Expand Up @@ -1600,6 +1607,7 @@ func TestWriteSudoersFile(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
registry := SessionRegistry{
logger: utils.NewSlogLoggerForTests(),
SessionRegistryConfig: SessionRegistryConfig{
Srv: &fakeServer{hostSudoers: c.hostSudoers},
},
Expand Down Expand Up @@ -1650,6 +1658,10 @@ func (f *fakeServer) GetInfo() types.Server {
return nil
}

func (f *fakeServer) Context() context.Context {
return context.Background()
}

type fakeAccessChecker struct {
services.AccessChecker
err error
Expand Down
Loading

0 comments on commit a04413d

Please sign in to comment.