Skip to content

Allow sudoer files to be created separately from host user creation#31793

Merged
lxea merged 5 commits intomasterfrom
lxea/separated-sudoers
Sep 22, 2023
Merged

Allow sudoer files to be created separately from host user creation#31793
lxea merged 5 commits intomasterfrom
lxea/separated-sudoers

Conversation

@lxea
Copy link
Copy Markdown
Contributor

@lxea lxea commented Sep 13, 2023

This separates host user creation and sudoer file creation so sudoers files can be configured without the requirement that the user was a dynamically created user

#29230

@r0mant r0mant requested review from espadolini and r0mant and removed request for avatus September 13, 2023 15:20
Comment thread lib/services/access_checker.go Outdated
Comment thread lib/srv/regular/sshserver.go Outdated
Comment on lines +371 to +375
// clean up sudoers before starting, in case any were left behind
// due to a crash for example
if err := s.sudoers.CleanupSudoers(); err != nil {
return trace.Wrap(err)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@espadolini can correct me if I'm wrong but I suspect that this might cause us to nuke sudoers for existing connections during graceful restart.

I don't know if we should be doing this sort of cleanup when starting the server. Can we just clean up sudoers for a particular user before their respective connection (unless they're already connected)?

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.

Yes, we will reach this point long before old sessions are guaranteed to be finished.

Do we have to delete old sudoers files? I would very much prefer to be conservative about deleting system-level things.

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.

I think it should be fine to not do the sudoers cleanup at startup time. The current behavior is the clean up the sudoers at session end so i think it makes sense to keep that.

We shouldnt need to remove the sudoers file before connection starts, it gets overwritten anyway with whatever the contents of the current host sudoers permission is

Comment thread lib/srv/regular/sshserver.go Outdated
Comment thread lib/srv/regular/sshserver.go Outdated
Comment thread lib/srv/sess.go Outdated
Comment thread lib/services/access_checker.go Outdated
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.

Unrelated to this change: why do we need a stable sort here? Is it ever legal to have two roles with the same name in a roleset?

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.

No i dont think so, this should just be regular sort actually.

Comment thread lib/srv/usermgmt.go Outdated
Comment thread lib/srv/forward/sshserver.go Outdated
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.

We never check explicitly check the return value of GetHostSudoers() for a nil return value, from what I can tell; should the forwarding server return a no-op implementation of HostSudoers that always returns errors instead?

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.

I think i'd prefer GetHostSudoers to return nil, notimplemented from the forwarder

@lxea lxea force-pushed the lxea/separated-sudoers branch from d32cb79 to ea6ef85 Compare September 18, 2023 14:26
Comment thread lib/srv/sess.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we clean up sudoers entry only upon session exit now? What if Teleport process crashes?

We should clean up before session start as well - was this removed or did I miss it?

@r0mant r0mant requested a review from espadolini September 20, 2023 23:03
Comment thread lib/services/access_checker.go Outdated
Comment on lines 929 to 930
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.

From golang.org/x/exp/slices:

Suggested change
roleSet := make([]types.Role, len(a.RoleSet))
copy(roleSet, a.RoleSet)
roleSet := slices.Clone(a.RoleSet)

Comment thread lib/srv/mock.go Outdated
Comment thread lib/srv/regular/sshserver.go Outdated
@lxea lxea force-pushed the lxea/separated-sudoers branch from 877964c to 17847f0 Compare September 21, 2023 12:39
@lxea lxea force-pushed the lxea/separated-sudoers branch from 17847f0 to c353601 Compare September 21, 2023 14:02
@lxea lxea enabled auto-merge September 22, 2023 14:57
@lxea lxea added this pull request to the merge queue Sep 22, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 22, 2023
@lxea lxea added this pull request to the merge queue Sep 22, 2023
Merged via the queue into master with commit ab80b3d Sep 22, 2023
@lxea lxea deleted the lxea/separated-sudoers branch September 22, 2023 15:19
@public-teleport-github-review-bot
Copy link
Copy Markdown

@lxea See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Create PR

@zmb3
Copy link
Copy Markdown
Collaborator

zmb3 commented Sep 22, 2023

Are there any docs updates necessary to describe this new behavior?

(Also note, the docs still refer to us using useradd, which is no longer true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants