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
10 changes: 10 additions & 0 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,11 @@ func (a *ServerWithRoles) GetTokens(ctx context.Context) ([]types.ProvisionToken
if err := a.action(apidefaults.Namespace, types.KindToken, types.VerbList, types.VerbRead); err != nil {
return nil, trace.Wrap(err)
}

if err := a.context.AuthorizeAdminAction(); err != nil {
return nil, trace.Wrap(err)
}

return a.authServer.GetTokens(ctx)
}

Expand All @@ -2028,6 +2033,11 @@ func (a *ServerWithRoles) GetToken(ctx context.Context, token string) (types.Pro
return nil, trace.Wrap(err)
}
}

if err := a.context.AuthorizeAdminAction(); err != nil {
return nil, trace.Wrap(err)
}

return a.authServer.GetToken(ctx, token)
}

Expand Down
30 changes: 30 additions & 0 deletions tool/tctl/common/admin_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ func (s *adminActionTestSuite) testTokens(t *testing.T) {
cliCommand: &tctl.TokensCommand{},
setup: createToken,
cleanup: deleteToken,
}, {
command: "tokens ls",
cliCommand: &tctl.TokensCommand{},
setup: createToken,
cleanup: deleteToken,
},
} {
t.Run(tc.command, func(t *testing.T) {
Expand All @@ -385,6 +390,7 @@ func (s *adminActionTestSuite) testTokens(t *testing.T) {
resource: token,
resourceCreate: createToken,
resourceCleanup: deleteToken,
testGetList: true,
})
})

Expand Down Expand Up @@ -820,6 +826,10 @@ type resourceCommandTestCase struct {
resource types.Resource
resourceCreate func() error
resourceCleanup func() error

// Tests get/list resource, for privileged resources
// like tokens that should require MFA to be seen.
testGetList bool
}

func (s *adminActionTestSuite) testResourceCommand(t *testing.T, ctx context.Context, tc resourceCommandTestCase) {
Expand Down Expand Up @@ -854,6 +864,26 @@ func (s *adminActionTestSuite) testResourceCommand(t *testing.T, ctx context.Con
cleanup: tc.resourceCleanup,
})
})

if tc.testGetList {
t.Run("tctl get", func(t *testing.T) {
s.testCommand(t, ctx, adminActionTestCase{
command: fmt.Sprintf("get %v", getResourceRef(tc.resource)),
cliCommand: &tctl.ResourceCommand{},
setup: tc.resourceCreate,
cleanup: tc.resourceCleanup,
})
})

t.Run("tctl list", func(t *testing.T) {
s.testCommand(t, ctx, adminActionTestCase{
command: fmt.Sprintf("get %v", tc.resource.GetKind()),
cliCommand: &tctl.ResourceCommand{},
setup: tc.resourceCreate,
cleanup: tc.resourceCleanup,
})
})
}
}

type editCommandTestCase struct {
Expand Down