Skip to content

Commit

Permalink
Merge pull request #1133 from rbaturov/narrow-service-permissions
Browse files Browse the repository at this point in the history
OCPBUGS-47456: Narrow RBAC Service Permissions
  • Loading branch information
openshift-merge-bot[bot] authored Jan 2, 2025
2 parents 3d606e1 + 04fd7e4 commit 11961f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: numaresources-manager-role
rules:
- apiGroups:
- ""
resources:
- services
verbs:
- '*'
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ metadata:
}
]
capabilities: Basic Install
createdAt: "2024-12-19T08:31:49Z"
createdAt: "2025-01-01T17:56:52Z"
olm.skipRange: '>=4.18.0 <4.19.0'
operatorframework.io/cluster-monitoring: "true"
operators.operatorframework.io/builder: operator-sdk-v1.36.1
Expand Down Expand Up @@ -359,7 +359,6 @@ spec:
resources:
- configmaps
- serviceaccounts
- services
verbs:
- '*'
- apiGroups:
Expand Down Expand Up @@ -600,6 +599,12 @@ spec:
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- services
verbs:
- '*'
serviceAccountName: numaresources-controller-manager
strategy: deployment
installModes:
Expand Down
14 changes: 13 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ rules:
resources:
- configmaps
- serviceaccounts
- services
verbs:
- '*'
- apiGroups:
Expand Down Expand Up @@ -132,3 +131,16 @@ rules:
- get
- list
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: manager-role
namespace: numaresources
rules:
- apiGroups:
- ""
resources:
- services
verbs:
- '*'
13 changes: 13 additions & 0 deletions config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
3 changes: 1 addition & 2 deletions controllers/numaresourcesoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type NUMAResourcesOperatorReconciler struct {
// TODO: narrow down

// Namespace Scoped
// TODO
//+kubebuilder:rbac:groups="",resources=services,verbs=*,namespace="numaresources"

// Cluster Scoped
//+kubebuilder:rbac:groups=topology.node.k8s.io,resources=noderesourcetopologies,verbs=get;list;create;update
Expand All @@ -122,7 +122,6 @@ type NUMAResourcesOperatorReconciler struct {
//+kubebuilder:rbac:groups=nodetopology.openshift.io,resources=numaresourcesoperators,verbs=*
//+kubebuilder:rbac:groups=nodetopology.openshift.io,resources=numaresourcesoperators/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=nodetopology.openshift.io,resources=numaresourcesoperators/finalizers,verbs=update
//+kubebuilder:rbac:groups="",resources=services,verbs=*

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
securityv1 "github.com/openshift/api/security/v1"
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -235,7 +236,12 @@ func main() {
klog.InfoS("metrics server", "enabled", params.enableMetrics, "addr", params.metricsAddr)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Cache: cache.Options{}, // TODO: restrict namespace here?
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{
namespace: {},
metav1.NamespaceNone: {},
},
},
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: params.metricsAddr,
Expand Down

0 comments on commit 11961f9

Please sign in to comment.