Skip to content

Commit

Permalink
Resolve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex McGrath committed Jun 22, 2023
1 parent eb5cc6e commit 6f604b2
Show file tree
Hide file tree
Showing 8 changed files with 1,336 additions and 1,336 deletions.
4 changes: 2 additions & 2 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2326,10 +2326,10 @@ message RoleSpecV6 {
}

// CreateHostUserMode determines whether host user creation should be
// disabled or if host users should be cleaned up or remain after
// disabled or if host users should be cleaned up or kept after
// sessions end.
enum CreateHostUserMode {
HOST_USER_MODE_UNDEFINED = 0;
HOST_USER_MODE_UNSPECIFIED = 0;
// HOST_USER_MODE_OFF disables host user creation.
HOST_USER_MODE_OFF = 1;
// HOST_USER_MODE_DROP enables host user creation and deletes users at session end.
Expand Down
4 changes: 2 additions & 2 deletions api/types/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ const (

func (h CreateHostUserMode) encode() (string, error) {
switch h {
case CreateHostUserMode_HOST_USER_MODE_UNDEFINED:
case CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED:
return "", nil
case CreateHostUserMode_HOST_USER_MODE_OFF:
return createHostUserModeOffString, nil
Expand Down Expand Up @@ -1793,7 +1793,7 @@ func (h *CreateHostUserMode) decode(val any) error {

switch valS {
case "":
*h = CreateHostUserMode_HOST_USER_MODE_UNDEFINED
*h = CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED
case createHostUserModeOffString:
*h = CreateHostUserMode_HOST_USER_MODE_OFF
case createHostUserModeDropString:
Expand Down
8 changes: 4 additions & 4 deletions api/types/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestMarshallCreateHostUserModeJSON(t *testing.T) {
expected string
}{
{input: CreateHostUserMode_HOST_USER_MODE_OFF, expected: "off"},
{input: CreateHostUserMode_HOST_USER_MODE_UNDEFINED, expected: ""},
{input: CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED, expected: ""},
{input: CreateHostUserMode_HOST_USER_MODE_DROP, expected: "drop"},
{input: CreateHostUserMode_HOST_USER_MODE_KEEP, expected: "keep"},
} {
Expand All @@ -365,7 +365,7 @@ func TestMarshallCreateHostUserModeYAML(t *testing.T) {
expected string
}{
{input: CreateHostUserMode_HOST_USER_MODE_OFF, expected: "\"off\""},
{input: CreateHostUserMode_HOST_USER_MODE_UNDEFINED, expected: "\"\""},
{input: CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED, expected: "\"\""},
{input: CreateHostUserMode_HOST_USER_MODE_DROP, expected: "drop"},
{input: CreateHostUserMode_HOST_USER_MODE_KEEP, expected: "keep"},
} {
Expand All @@ -382,7 +382,7 @@ func TestUnmarshallCreateHostUserModeJSON(t *testing.T) {
input string
}{
{expected: CreateHostUserMode_HOST_USER_MODE_OFF, input: "off"},
{expected: CreateHostUserMode_HOST_USER_MODE_UNDEFINED, input: ""},
{expected: CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED, input: ""},
{expected: CreateHostUserMode_HOST_USER_MODE_DROP, input: "drop"},
{expected: CreateHostUserMode_HOST_USER_MODE_KEEP, input: "keep"},
} {
Expand All @@ -400,7 +400,7 @@ func TestUnmarshallCreateHostUserModeYAML(t *testing.T) {
}{
{expected: CreateHostUserMode_HOST_USER_MODE_OFF, input: "\"off\""},
{expected: CreateHostUserMode_HOST_USER_MODE_OFF, input: "off"},
{expected: CreateHostUserMode_HOST_USER_MODE_UNDEFINED, input: "\"\""},
{expected: CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED, input: "\"\""},
{expected: CreateHostUserMode_HOST_USER_MODE_DROP, input: "drop"},
{expected: CreateHostUserMode_HOST_USER_MODE_KEEP, input: "keep"},
} {
Expand Down
2,638 changes: 1,319 additions & 1,319 deletions api/types/types.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration/hostuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestRootHostUsers(t *testing.T) {
require.NoError(t, err)
}

// this user should not be in the service group as it was created with mode remain.
// this user should not be in the service group as it was created with mode keep.
closer, err := users.CreateUser("teleport-user4", &services.HostUsersInfo{
Mode: types.CreateHostUserMode_HOST_USER_MODE_KEEP,
})
Expand Down
4 changes: 2 additions & 2 deletions lib/services/access_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func (a *accessChecker) HostUsers(s types.Server) (*HostUsersInfo, error) {

createHostUserMode := role.GetOptions().CreateHostUserMode
createHostUser := role.GetOptions().CreateHostUser
if createHostUserMode == types.CreateHostUserMode_HOST_USER_MODE_UNDEFINED {
if createHostUserMode == types.CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED {
createHostUserMode = types.CreateHostUserMode_HOST_USER_MODE_OFF
if createHostUser != nil && createHostUser.Value {
createHostUserMode = types.CreateHostUserMode_HOST_USER_MODE_DROP
Expand All @@ -866,7 +866,7 @@ func (a *accessChecker) HostUsers(s types.Server) (*HostUsersInfo, error) {
return nil, trace.AccessDenied("user is not allowed to create host users")
}

if mode == types.CreateHostUserMode_HOST_USER_MODE_UNDEFINED {
if mode == types.CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED {
mode = createHostUserMode
}
// prefer to use HostUserModeKeep over Drop if mode has already been set.
Expand Down
10 changes: 5 additions & 5 deletions lib/services/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6866,15 +6866,15 @@ func TestHostUsers_HostSudoers(t *testing.T) {
server types.Server
}{
{
test: "test exact match, one sudoer entry, one role",
test: "test exact match, one sudoer entry, one role",
sudoers: []string{"%sudo ALL=(ALL) ALL"},
roles: NewRoleSet(&types.RoleV6{
Spec: types.RoleSpecV6{
Options: types.RoleOptions{
CreateHostUser: types.NewBoolOption(true),
},
Allow: types.RoleConditions{
NodeLabels: types.Labels{"success": []string{"abc"}},
NodeLabels: types.Labels{"success": []string{"abc"}},
HostSudoers: []string{"%sudo ALL=(ALL) ALL"},
},
},
Expand Down Expand Up @@ -6946,7 +6946,7 @@ func TestHostUsers_HostSudoers(t *testing.T) {
CreateHostUser: types.NewBoolOption(true),
},
Allow: types.RoleConditions{
NodeLabels: types.Labels{"success": []string{"abc"}},
NodeLabels: types.Labels{"success": []string{"abc"}},
HostSudoers: []string{"%sudo ALL=(ALL) ALL"},
},
},
Expand All @@ -6971,7 +6971,7 @@ func TestHostUsers_HostSudoers(t *testing.T) {
},
},
{
test: "line deny",
test: "line deny",
sudoers: []string{"%sudo ALL=(ALL) ALL"},
roles: NewRoleSet(&types.RoleV6{
Spec: types.RoleSpecV6{
Expand Down Expand Up @@ -7286,7 +7286,7 @@ func TestHostUsers_CanCreateHostUser(t *testing.T) {
types.CreateHostUserMode_HOST_USER_MODE_DROP,
),
createDefaultTCWithMode(
"test can create when create host user mode is remain",
"test can create when create host user mode is keep",
true,
types.CreateHostUserMode_HOST_USER_MODE_KEEP,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/usermgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func sanitizeSudoersName(username string) string {

// CreateUser creates a temporary Teleport user in the TeleportServiceGroup
func (u *HostUserManagement) CreateUser(name string, ui *services.HostUsersInfo) (io.Closer, error) {
if ui.Mode == types.CreateHostUserMode_HOST_USER_MODE_UNDEFINED {
if ui.Mode == types.CreateHostUserMode_HOST_USER_MODE_UNSPECIFIED {
return nil, trace.BadParameter("Mode is a required argument to CreateUser")
}

Expand Down

0 comments on commit 6f604b2

Please sign in to comment.