-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor and test RBAC config policies work [CM-530] (#9943)
- Loading branch information
1 parent
2d884b9
commit cedfcfe
Showing
16 changed files
with
310 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package configpolicy | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/determined-ai/determined/master/internal/grpcutil" | ||
"github.com/determined-ai/determined/master/pkg/model" | ||
"github.com/determined-ai/determined/proto/pkg/workspacev1" | ||
) | ||
|
||
// ConfigPolicyAuthZBasic is classic OSS controls. | ||
type ConfigPolicyAuthZBasic struct{} | ||
|
||
// CanModifyWorkspaceConfigPolicies requires curUser to be an admin or workspace owner. | ||
func (a *ConfigPolicyAuthZBasic) CanModifyWorkspaceConfigPolicies( | ||
ctx context.Context, curUser model.User, workspace *workspacev1.Workspace, | ||
) error { | ||
if !curUser.Admin && curUser.ID != model.UserID(workspace.UserId) { | ||
return fmt.Errorf("only admins may set config policies for workspaces") | ||
} | ||
return nil | ||
} | ||
|
||
// CanViewWorkspaceConfigPolicies returns a nil error. | ||
func (a *ConfigPolicyAuthZBasic) CanViewWorkspaceConfigPolicies( | ||
ctx context.Context, curUser model.User, workspace *workspacev1.Workspace, | ||
) error { | ||
return nil | ||
} | ||
|
||
// CanModifyGlobalConfigPolicies requires curUser to be an admin. | ||
func (a *ConfigPolicyAuthZBasic) CanModifyGlobalConfigPolicies(ctx context.Context, curUser *model.User, | ||
) error { | ||
if !curUser.Admin { | ||
return grpcutil.ErrPermissionDenied | ||
} | ||
return nil | ||
} | ||
|
||
// CanViewGlobalConfigPolicies returns a nil error. | ||
func (a *ConfigPolicyAuthZBasic) CanViewGlobalConfigPolicies(ctx context.Context, curUser *model.User, | ||
) error { | ||
return nil | ||
} | ||
|
||
func init() { | ||
AuthZProvider.Register("basic", &ConfigPolicyAuthZBasic{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package configpolicy | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/determined-ai/determined/master/internal/authz" | ||
"github.com/determined-ai/determined/master/pkg/model" | ||
"github.com/determined-ai/determined/proto/pkg/workspacev1" | ||
) | ||
|
||
// ConfigPolicyAuthZ describes authz methods for config policies. | ||
type ConfigPolicyAuthZ interface { | ||
// PUT /api/v1/config-policies/workspaces/:workspace-id/:type | ||
CanModifyWorkspaceConfigPolicies(ctx context.Context, curUser model.User, | ||
workspace *workspacev1.Workspace, | ||
) error | ||
// GET /api/v1/config-policies/workspaces/:workspace-id/:type | ||
CanViewWorkspaceConfigPolicies(ctx context.Context, curUser model.User, | ||
workspace *workspacev1.Workspace, | ||
) error | ||
|
||
// CanModifyGlobalConfigPolicies returns an error if the user is not authorized to | ||
// modify task config policies. | ||
CanModifyGlobalConfigPolicies(ctx context.Context, curUser *model.User, | ||
) error | ||
|
||
// CanViewGlobalConfigPolicies returns a nil error. | ||
CanViewGlobalConfigPolicies(ctx context.Context, curUser *model.User, | ||
) error | ||
} | ||
|
||
// AuthZProvider providers WorkspaceAuthZ implementations. | ||
var AuthZProvider authz.AuthZProviderType[ConfigPolicyAuthZ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package configpolicy | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/determined-ai/determined/master/pkg/model" | ||
"github.com/determined-ai/determined/proto/pkg/workspacev1" | ||
) | ||
|
||
// ConfigPolicyAuthZPermissive is the permission implementation. | ||
type ConfigPolicyAuthZPermissive struct{} | ||
|
||
// CanModifyWorkspaceConfigPolicies calls RBAC authz but enforces basic authz. | ||
func (p *ConfigPolicyAuthZPermissive) CanModifyWorkspaceConfigPolicies( | ||
ctx context.Context, curUser model.User, workspace *workspacev1.Workspace, | ||
) error { | ||
_ = (&ConfigPolicyAuthZRBAC{}).CanModifyWorkspaceConfigPolicies(ctx, curUser, workspace) | ||
return (&ConfigPolicyAuthZBasic{}).CanModifyWorkspaceConfigPolicies(ctx, curUser, workspace) | ||
} | ||
|
||
// CanViewWorkspaceConfigPolicies calls RBAC authz but enforces basic authz. | ||
func (p *ConfigPolicyAuthZPermissive) CanViewWorkspaceConfigPolicies( | ||
ctx context.Context, curUser model.User, workspace *workspacev1.Workspace, | ||
) error { | ||
_ = (&ConfigPolicyAuthZRBAC{}).CanViewWorkspaceConfigPolicies(ctx, curUser, workspace) | ||
return (&ConfigPolicyAuthZBasic{}).CanViewWorkspaceConfigPolicies(ctx, curUser, workspace) | ||
} | ||
|
||
// CanModifyGlobalConfigPolicies calls the RBAC implementation and returns if | ||
// the user has access to modfy global task config policies. | ||
func (p *ConfigPolicyAuthZPermissive) CanModifyGlobalConfigPolicies( | ||
ctx context.Context, curUser *model.User, | ||
) error { | ||
_ = (&ConfigPolicyAuthZRBAC{}).CanModifyGlobalConfigPolicies(ctx, curUser) | ||
return (&ConfigPolicyAuthZBasic{}).CanModifyGlobalConfigPolicies(ctx, curUser) | ||
} | ||
|
||
// CanViewGlobalConfigPolicies calls the RBAC implementation but always allows access. | ||
func (p *ConfigPolicyAuthZPermissive) CanViewGlobalConfigPolicies( | ||
ctx context.Context, curUser *model.User, | ||
) error { | ||
_ = (&ConfigPolicyAuthZRBAC{}).CanViewGlobalConfigPolicies(ctx, curUser) | ||
return (&ConfigPolicyAuthZBasic{}).CanViewGlobalConfigPolicies(ctx, curUser) | ||
} |
Oops, something went wrong.