Skip to content

Commit

Permalink
[v13] Fix nil user group entries. (#29326)
Browse files Browse the repository at this point in the history
* Fix nil user group entries.

When user groups are being looked up while listing applications if a user
group is missing from the lookup, the previous logic would inadvertently
leave nil user groups if the lookup failed. This has been corrected to ensure
that no nil entries end up in the user group lookup.

* Adjust unit test to exercise this.
  • Loading branch information
mdwn committed Jul 19, 2023
1 parent a0e928f commit 48351ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/web/apiserver_test.go
Expand Up @@ -4284,7 +4284,7 @@ func TestClusterAppsGet(t *testing.T) {
Spec: types.AppSpecV3{
URI: "https://console.aws.amazon.com", // sets field awsConsole to true
PublicAddr: "publicaddrs",
UserGroups: []string{"ug1"},
UserGroups: []string{"ug1", "ug2"}, // ug2 doesn't exist in the backend, so its lookup will fail.
},
},
},
Expand Down
9 changes: 4 additions & 5 deletions lib/web/apps.go
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/gravitational/trace"
"github.com/julienschmidt/httprouter"

"github.com/gravitational/teleport/api/client"
apiclient "github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/client/proto"
apidefaults "github.com/gravitational/teleport/api/defaults"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (h *Handler) clusterAppsGet(w http.ResponseWriter, r *http.Request, p httpr
return nil, trace.Wrap(err)
}

page, err := client.GetResourcePage[types.AppServer](r.Context(), clt, req)
page, err := apiclient.GetResourcePage[types.AppServer](r.Context(), clt, req)
if err != nil {
return nil, trace.Wrap(err)
}
Expand All @@ -86,15 +85,15 @@ func (h *Handler) clusterAppsGet(w http.ResponseWriter, r *http.Request, p httpr

app := server.GetApp()

ugs := make(types.UserGroups, len(app.GetUserGroups()))
for i, userGroupName := range app.GetUserGroups() {
ugs := types.UserGroups{}
for _, userGroupName := range app.GetUserGroups() {
userGroup := userGroupLookup[userGroupName]
if userGroup == nil {
h.log.Debugf("Unable to find user group %s when creating user groups, skipping", userGroupName)
continue
}

ugs[i] = userGroup
ugs = append(ugs, userGroup)
}
sort.Sort(ugs)
appsToUserGroups[app.GetName()] = ugs
Expand Down

0 comments on commit 48351ec

Please sign in to comment.