-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic preflight checks, add permission validation preflight check
Signed-off-by: everettraven <everettraven@gmail.com>
- Loading branch information
1 parent
70eb2c1
commit 91f533f
Showing
30 changed files
with
3,033 additions
and
15 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
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,47 @@ | ||
// Copyright 2024 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package permissions | ||
|
||
import ( | ||
"context" | ||
|
||
ctlres "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/resources" | ||
authv1 "k8s.io/api/authorization/v1" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
authv1client "k8s.io/client-go/kubernetes/typed/authorization/v1" | ||
) | ||
|
||
// BasicValidator is a basic validator useful for | ||
// validating basic CRUD permissions for resources. It has no knowledge | ||
// of how to handle permission evaluation for specific | ||
// GroupVersionKinds | ||
type BasicValidator struct { | ||
ssarClient authv1client.SelfSubjectAccessReviewInterface | ||
mapper meta.RESTMapper | ||
} | ||
|
||
var _ Validator = (*BasicValidator)(nil) | ||
|
||
func NewBasicValidator(ssarClient authv1client.SelfSubjectAccessReviewInterface, mapper meta.RESTMapper) *BasicValidator { | ||
return &BasicValidator{ | ||
ssarClient: ssarClient, | ||
mapper: mapper, | ||
} | ||
} | ||
|
||
func (bv *BasicValidator) Validate(ctx context.Context, res ctlres.Resource, verb string) error { | ||
mapping, err := bv.mapper.RESTMapping(res.GroupKind(), res.GroupVersion().Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ValidatePermissions(ctx, bv.ssarClient, &authv1.ResourceAttributes{ | ||
Group: mapping.Resource.Group, | ||
Version: mapping.Resource.Version, | ||
Resource: mapping.Resource.Resource, | ||
Namespace: res.Namespace(), | ||
Name: res.Name(), | ||
Verb: verb, | ||
}) | ||
} |
Oops, something went wrong.