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
17 changes: 16 additions & 1 deletion lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,15 @@ func (a *ServerWithRoles) ListUnifiedResources(ctx context.Context, req *proto.L
return &proto.ListUnifiedResourcesResponse{}, nil
}
unifiedResources, err = a.authServer.UnifiedResourceCache.GetUnifiedResourcesByIDs(ctx, prefs.ClusterPreferences.PinnedResources.GetResourceIds(), func(resource types.ResourceWithLabels) bool {
if err := resourceChecker.CanAccess(resource); err != nil {
var err error
switch r := resource.(type) {
// TODO (avatus) we should add this type into the `resourceChecker.CanAccess` method
case types.SAMLIdPServiceProvider:
err = a.action(apidefaults.Namespace, types.KindSAMLIdPServiceProvider, types.VerbList)
default:
err = resourceChecker.CanAccess(r)
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.

I'm gonna accept this change as a stop-gap measure, but it sounds really strange and error-prone, especially security-wise, to do it like this. If we have a function that's called CanAccess on something that is called resourceChecker, we shouldn't expect the consumers of this function to understand that in a specific case of types.SAMLIdPServiceProvider, they should call something else. I think that this should be folded into either of these in the long term. Is there something I don't understand?

Copy link
Copy Markdown
Contributor Author

@avatus avatus Oct 13, 2023

Choose a reason for hiding this comment

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

Will add a TODO to fold SAML into this once I figure out why it wasn't there in the first place. Thanks

}
if err != nil {
return false
}
match, _ := services.MatchResourceByFilters(resource, filter, nil)
Expand All @@ -1581,6 +1589,13 @@ func (a *ServerWithRoles) ListUnifiedResources(ctx context.Context, req *proto.L
if err != nil {
return nil, trace.Wrap(err, "getting unified resources by ID")
}

// we need to sort pinned resources manually because they are fetched in the order they were pinned
if req.SortBy.Field != "" {
if err := unifiedResources.SortByCustom(req.SortBy); err != nil {
return nil, trace.Wrap(err, "sorting unified resources")
}
}
} else {
unifiedResources, nextKey, err = a.authServer.UnifiedResourceCache.IterateUnifiedResources(ctx, func(resource types.ResourceWithLabels) (bool, error) {
var err error
Expand Down
7 changes: 5 additions & 2 deletions lib/services/unified_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package services
import (
"bytes"
"context"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -386,8 +387,10 @@ func makeResourceSortKey(resource types.Resource) resourceSortKey {
}

return resourceSortKey{
byName: backend.Key(prefix, name, kind),
byType: backend.Key(prefix, kind, name),
// names should be stored as lowercase to keep items sorted as
// expected, regardless of case
byName: backend.Key(prefix, strings.ToLower(name), kind),
byType: backend.Key(prefix, kind, strings.ToLower(name)),
}
}

Expand Down
6 changes: 3 additions & 3 deletions web/packages/teleport/src/UnifiedResources/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,16 @@ export function resourceName(resource: UnifiedResource) {

function NoPinned() {
return (
<Box p={8} mt={3} mx="auto" maxWidth="720px" textAlign="center">
<TextIcon typography="h3">You have not pinned any resources</TextIcon>
<Box p={8} mt={3} mx="auto" textAlign="center">
<Text typography="h3">You have not pinned any resources</Text>
</Box>
);
}

function PinningNotSupported() {
return (
<Box p={8} mt={3} mx="auto" maxWidth="720px" textAlign="center">
<TextIcon typography="h3">{PINNING_NOT_SUPPORTED_MESSAGE}</TextIcon>
<Text typography="h3">{PINNING_NOT_SUPPORTED_MESSAGE}</Text>
</Box>
);
}
Expand Down