-
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 view aggregate role for inspecting Shipwright Build objects - Add edit aggregate role for managing Builds, BuildRuns, and BuildStrategies. - Ensure aggregated user roles are installed in e2e testing - Document the default cluster roles in the "configuration" markdown doc.
- Loading branch information
1 parent
204731d
commit 5754773
Showing
4 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
labels: | ||
rbac.authorization.k8s.io/aggregate-to-edit: "true" | ||
rbac.authorization.k8s.io/aggregate-to-admin: "true" | ||
name: shipwright-build-aggregate-edit | ||
rules: | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['clusterbuildstrategies'] | ||
verbs: ['get', 'list', 'watch'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['buildstrategies'] | ||
verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['builds'] | ||
verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['buildruns'] | ||
verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete'] |
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,19 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
labels: | ||
rbac.authorization.k8s.io/aggregate-to-view: "true" | ||
name: shipwright-build-aggregate-view | ||
rules: | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['clusterbuildstrategies'] | ||
verbs: ['get', 'list', 'watch'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['buildstrategies'] | ||
verbs: ['get', 'list', 'watch'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['builds'] | ||
verbs: ['get', 'list', 'watch'] | ||
- apiGroups: ['shipwright.io'] | ||
resources: ['buildruns'] | ||
verbs: ['get', 'list', 'watch'] |
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,75 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("User RBAC for Shipwright", func() { | ||
|
||
var ctx context.Context | ||
|
||
BeforeEach(func() { | ||
ctx = context.Background() | ||
}) | ||
|
||
It("should install an aggregated edit role for developers", func() { | ||
editRole, err := testBuild.Clientset.RbacV1().ClusterRoles().Get(ctx, "shipwright-build-aggregate-edit", metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
expectedAggregates := []string{ | ||
"rbac.authorization.k8s.io/aggregate-to-edit", | ||
"rbac.authorization.k8s.io/aggregate-to-admin", | ||
} | ||
for _, aggregate := range expectedAggregates { | ||
aggregateValue, exists := editRole.Labels[aggregate] | ||
Expect(exists).To(BeTrue()) | ||
Expect(aggregateValue).To(Equal("true")) | ||
} | ||
// We should have at least two rules - one for ClusterBuildStrategy, another for all else | ||
// More than two rules is acceptable. | ||
Expect(len(editRole.Rules)).To(BeNumerically(">=", 2)) | ||
for _, rule := range editRole.Rules { | ||
Expect(rule.APIGroups).To(ContainElement("shipwright.io")) | ||
for _, resource := range rule.Resources { | ||
if resource == "clusterbuildstrategies" { | ||
Expect(rule.Verbs).To(ContainElements("get", "list", "watch")) | ||
Expect(rule.Verbs).NotTo(ContainElement("create")) | ||
Expect(rule.Verbs).NotTo(ContainElement("update")) | ||
Expect(rule.Verbs).NotTo(ContainElement("patch")) | ||
Expect(rule.Verbs).NotTo(ContainElement("delete")) | ||
} else { | ||
Expect(rule.Verbs).To(ContainElements("get", "list", "watch", "create", "update", "patch", "delete")) | ||
} | ||
} | ||
} | ||
}) | ||