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

✨ Admission for APIExportEndpointSlice #2560

Merged
merged 1 commit into from
Jan 13, 2023

Conversation

fgiloux
Copy link
Contributor

@fgiloux fgiloux commented Jan 6, 2023

Summary

check for binding authorization against the referenced APIExport.

Signed-off-by: Frederic Giloux [email protected]

Related issue(s)

Contributes to #2332

@openshift-ci openshift-ci bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jan 6, 2023
@fgiloux
Copy link
Contributor Author

fgiloux commented Jan 6, 2023

There are a few checks that seem redundant as the APIExport reference is marked as mandatory and immutable. I would welcome a second opinion on whether they should still be kept (like for APIBinding) or removed.


var oldSlice *apisv1alpha1.APIExportEndpointSlice
if a.GetOperation() == admission.Update {
u, ok := a.GetOldObject().(*unstructured.Unstructured)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the purpose of this block since all it does is to assign value to oldSlice variable

@@ -322,3 +305,23 @@ func (o *apiBindingAdmission) SetKcpInformers(informers kcpinformers.SharedInfor
indexers.ByLogicalClusterPathAndName: indexers.IndexByLogicalClusterPathAndName,
})
}

func CheckAPIExportAccess(ctx context.Context, user user.Info, apiExportName string, authz authorizer.Authorizer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move it to pkg/admission/helpers or maybe even pkg/authorization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would keep it under admission. Due to the user info I am not expecting it to be useful somewhere else. I am not found of "helpers" packages... I am not finding the name helpful :-)
I will put it under pkg/admission/authorization. Let me know if you have concerns with it.

limitations under the License.
*/

package authorization
Copy link
Contributor

Choose a reason for hiding this comment

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

pkg/admission/authorization looks strange, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can rename it to permissions if you prefer but that's basically the same idea

o.apiExportIndexer = informers.Apis().V1alpha1().APIExports().Informer().GetIndexer()

indexers.AddIfNotPresentOrDie(informers.Tenancy().V1alpha1().WorkspaceTypes().Informer().GetIndexer(), cache.Indexers{
indexers.ByLogicalClusterPathAndName: indexers.IndexByLogicalClusterPathAndName,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this indexer?

Copy link
Contributor Author

@fgiloux fgiloux Jan 11, 2023

Choose a reason for hiding this comment

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

Good point. I am removing it. It is also in the apibinding admission and I could not see any use of it there either. It could be fixed there in a subsequent PR

o.SetReadyFunc(func() bool {
return apiExportsReady()
})
o.apiExportLister = informers.Apis().V1alpha1().APIExports().Lister()
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this field used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I am removing it. It is also in the apibinding admission and I could not see any use of it there either. It could be fixed there in a subsequent PR

// ValidateInitialization ensures the required injected fields are set.
func (o *apiExportEndpointSliceAdmission) ValidateInitialization() error {
if o.deepSARClient == nil {
return fmt.Errorf(PluginName + " plugin needs a Kubernetes ClusterInterface")
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong msg ? it needs a DeepSARClient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a DeepSARClient is a Kubernetes ClusterInterface

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but the error is less useful if it's less specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. there is an injector for just the client, and one very specifically for SetDeepSARClient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@fgiloux fgiloux force-pushed the slice-permissions branch 2 times, most recently from 6a37518 to feae98c Compare January 11, 2023 10:37
@p0lyn0mial
Copy link
Contributor

/lgtm

@p0lyn0mial
Copy link
Contributor

/assign @sttts for approval

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 11, 2023

@p0lyn0mial: GitHub didn't allow me to assign the following users: for, approval.

Note that only kcp-dev members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @sttts for approval

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 11, 2023
@sttts
Copy link
Member

sttts commented Jan 11, 2023

/lgtm
/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 11, 2023
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 11, 2023
@fgiloux
Copy link
Contributor Author

fgiloux commented Jan 11, 2023

/retest

1 similar comment
@fgiloux
Copy link
Contributor Author

fgiloux commented Jan 11, 2023

/retest

@sttts
Copy link
Member

sttts commented Jan 12, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2023
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2023
@fgiloux
Copy link
Contributor Author

fgiloux commented Jan 12, 2023

I needed to rebase as the signature of delegated.NewDelegatedAuthorizer had changed. lgtm needed again. Sorry :-(

@stevekuznetsov
Copy link
Contributor

Mind fixing #2560 (comment) while you're at it?

…ainst the referenced APIExport.

Signed-off-by: Frederic Giloux <[email protected]>
@sttts
Copy link
Member

sttts commented Jan 13, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@openshift-merge-robot openshift-merge-robot merged commit f9a3cd8 into kcp-dev:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants