forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make ClusterWorkflowTemplate optional for namespaced Installation (
- Loading branch information
1 parent
25c6246
commit 06c4bd6
Showing
8 changed files
with
144 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package auth | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
auth "k8s.io/api/authorization/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
func CanI(kubeclientset kubernetes.Interface, verb, resource, namespace, name string) (bool, error) { | ||
logCtx := log.WithFields(log.Fields{"verb": verb, "resource": resource, "namespace": namespace, "name": name}) | ||
logCtx.Debug("CanI") | ||
|
||
review, err := kubeclientset.AuthorizationV1().SelfSubjectAccessReviews().Create(&auth.SelfSubjectAccessReview{ | ||
Spec: auth.SelfSubjectAccessReviewSpec{ | ||
ResourceAttributes: &auth.ResourceAttributes{ | ||
Namespace: namespace, | ||
Verb: verb, | ||
Group: "argoproj.io", | ||
Resource: resource, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
logCtx.WithField("status", review.Status).Debug("CanI") | ||
return review.Status.Allowed, nil | ||
} |
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,35 @@ | ||
package auth | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
authorizationv1 "k8s.io/api/authorization/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
kubefake "k8s.io/client-go/kubernetes/fake" | ||
k8stesting "k8s.io/client-go/testing" | ||
) | ||
|
||
func TestCanI(t *testing.T) { | ||
kubeClient := &kubefake.Clientset{} | ||
|
||
kubeClient.AddReactor("create", "selfsubjectaccessreviews", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) { | ||
selfSubjectAccessReview := reflect.ValueOf(action).FieldByName("Object").Elem().Elem().Field(2).Field(0).Elem() | ||
resource := selfSubjectAccessReview.FieldByName("Resource").String() | ||
verb := selfSubjectAccessReview.FieldByName("Verb").String() | ||
allowed := resource == "workflow" && verb == "get" | ||
return true, &authorizationv1.SelfSubjectAccessReview{ | ||
Status: authorizationv1.SubjectAccessReviewStatus{Allowed: allowed}, | ||
}, nil | ||
}) | ||
|
||
allowed, err := CanI(kubeClient, "get", "workflow", "", "") | ||
if assert.NoError(t, err) { | ||
assert.True(t, allowed) | ||
} | ||
notAllowed, err := CanI(kubeClient, "list", "workflow", "", "") | ||
if assert.NoError(t, err) { | ||
assert.False(t, notAllowed) | ||
} | ||
} |
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