Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/authorization: don't check for cluster workspace lister. #1265

Merged
merged 1 commit into from
Jun 14, 2022
Merged
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
52 changes: 24 additions & 28 deletions pkg/authorization/workspace_content_authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,31 @@ func (a *workspaceContentAuthorizer) Authorize(ctx context.Context, attr authori
&rbac.ClusterRoleBindingLister{Lister: parentWorkspaceKubeInformer.ClusterRoleBindings().Lister()},
)

// TODO: decide if we want to require workspaces for all kcp variations. For now, only check if the workspace controllers are running,
// as that ensures the ClusterWorkspace CRD is installed, and that our shared informer factory can sync all its caches successfully.
if a.clusterWorkspaceLister != nil {
// check the workspace even exists
// TODO: using scoping when available
if ws, err := a.clusterWorkspaceLister.Get(clusters.ToClusterAwareKey(parentClusterName, clusterWorkspace)); err != nil {
if errors.IsNotFound(err) {
return authorizer.DecisionDeny, fmt.Sprintf("%q workspace access not permitted", cluster.Name), nil
}
return authorizer.DecisionNoOpinion, "", err
} else if len(ws.Status.Initializers) > 0 {
workspaceAttr := authorizer.AttributesRecord{
User: attr.GetUser(),
Verb: attr.GetVerb(),
APIGroup: tenancyv1alpha1.SchemeGroupVersion.Group,
APIVersion: tenancyv1alpha1.SchemeGroupVersion.Version,
Resource: "clusterworkspaces",
Subresource: "initialize",
Name: clusterWorkspace,
ResourceRequest: true,
}
// check the workspace even exists
// TODO: using scoping when available
if ws, err := a.clusterWorkspaceLister.Get(clusters.ToClusterAwareKey(parentClusterName, clusterWorkspace)); err != nil {
if errors.IsNotFound(err) {
return authorizer.DecisionDeny, fmt.Sprintf("%q workspace access not permitted", cluster.Name), nil
}
return authorizer.DecisionNoOpinion, "", err
} else if len(ws.Status.Initializers) > 0 {
workspaceAttr := authorizer.AttributesRecord{
User: attr.GetUser(),
Verb: attr.GetVerb(),
APIGroup: tenancyv1alpha1.SchemeGroupVersion.Group,
APIVersion: tenancyv1alpha1.SchemeGroupVersion.Version,
Resource: "clusterworkspaces",
Subresource: "initialize",
Name: clusterWorkspace,
ResourceRequest: true,
}

dec, reason, err := parentAuthorizer.Authorize(ctx, workspaceAttr)
if err != nil {
return dec, reason, err
}
if dec != authorizer.DecisionAllow {
return dec, fmt.Sprintf("%q workspace access not permitted", cluster.Name), nil
}
dec, reason, err := parentAuthorizer.Authorize(ctx, workspaceAttr)
if err != nil {
return dec, reason, err
}
if dec != authorizer.DecisionAllow {
return dec, fmt.Sprintf("%q workspace access not permitted", cluster.Name), nil
}
}

Expand Down