- Notifications
You must be signed in to change notification settings - Fork914
chore: avoid depending on rbac in slim builds#17959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
package cli | ||
import ( | ||
"slices" | ||
"strings" | ||
"golang.org/x/xerrors" | ||
"github.com/coder/coder/v2/cli/cliui" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/serpent" | ||
) | ||
func (r *RootCmd) userEditRoles() *serpent.Command { | ||
client := new(codersdk.Client) | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
var givenRoles []string | ||
cmd := &serpent.Command{ | ||
Use: "edit-roles <username|user_id>", | ||
Short: "Edit a user's roles by username or id", | ||
Options: []serpent.Option{ | ||
cliui.SkipPromptOption(), | ||
{ | ||
Name: "roles", | ||
Description: "A list of roles to give to the user. This removes any existing roles the user may have.", | ||
Flag: "roles", | ||
Value: serpent.StringArrayOf(&givenRoles), | ||
}, | ||
@@ -52,13 +39,21 @@ func (r *RootCmd) userEditRoles() *serpent.Command { | ||
if err != nil { | ||
return xerrors.Errorf("fetch user roles: %w", err) | ||
} | ||
siteRoles, err := client.ListSiteRoles(ctx) | ||
MemberAuthor
| ||
if err != nil { | ||
return xerrors.Errorf("fetch site roles: %w", err) | ||
} | ||
siteRoleNames := make([]string, 0, len(siteRoles)) | ||
for _, role := range siteRoles { | ||
siteRoleNames = append(siteRoleNames, role.Name) | ||
} | ||
var selectedRoles []string | ||
if len(givenRoles) > 0 { | ||
// Make sure all of the given roles are valid site roles | ||
for _, givenRole := range givenRoles { | ||
if !slices.Contains(siteRoleNames, givenRole) { | ||
siteRolesPretty := strings.Join(siteRoleNames, ", ") | ||
return xerrors.Errorf("The role %s is not valid. Please use one or more of the following roles: %s\n", givenRole, siteRolesPretty) | ||
} | ||
} | ||
@@ -67,7 +62,7 @@ func (r *RootCmd) userEditRoles() *serpent.Command { | ||
} else { | ||
selectedRoles, err = cliui.MultiSelect(inv, cliui.MultiSelectOptions{ | ||
Message: "Select the roles you'd like to assign to the user", | ||
Options:siteRoleNames, | ||
Defaults: userRoles.Roles, | ||
}) | ||
if err != nil { | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//go:build slim | ||
package database | ||
const ( | ||
// This line fails to compile, preventing this package from being imported | ||
// in slim builds. | ||
_DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS = _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS | ||
) |
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build !slim | ||
package httpapi | ||
import ( | ||
"context" | ||
"net/http" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
) | ||
// This is defined separately in slim builds to avoid importing the rbac | ||
// package, which is a large dependency. | ||
func SetAuthzCheckRecorderHeader(ctx context.Context, rw http.ResponseWriter) { | ||
if rec, ok := rbac.GetAuthzCheckRecorder(ctx); ok { | ||
// If you're here because you saw this header in a response, and you're | ||
// trying to investigate the code, here are a couple of notable things | ||
// for you to know: | ||
// - If any of the checks are `false`, they might not represent the whole | ||
// picture. There could be additional checks that weren't performed, | ||
// because processing stopped after the failure. | ||
// - The checks are recorded by the `authzRecorder` type, which is | ||
// configured on server startup for development and testing builds. | ||
// - If this header is missing from a response, make sure the response is | ||
// being written by calling `httpapi.Write`! | ||
rw.Header().Set("x-authz-checks", rec.String()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build slim | ||
package httpapi | ||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
func SetAuthzCheckRecorderHeader(ctx context.Context, rw http.ResponseWriter) { | ||
// There's no RBAC on the agent API, so this is separately defined to | ||
// avoid importing the RBAC package, which is a large dependency. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !slim | ||
package httpmw | ||
import ( | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build slim | ||
package rbac | ||
const ( | ||
// This line fails to compile, preventing this package from being imported | ||
// in slim builds. | ||
_DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS = _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS | ||
) |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.