Skip to content

Commit d42007a

Browse files
authored
support grpc csr approval (#332)
Signed-off-by: Wei Liu <[email protected]>
1 parent 4bae358 commit d42007a

File tree

201 files changed

+4001
-3203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+4001
-3203
lines changed

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/mochi-mqtt/server/v2 v2.6.5
99
github.com/onsi/ginkgo v1.16.5
1010
github.com/onsi/gomega v1.36.1
11-
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
11+
github.com/openshift/build-machinery-go v0.0.0-20250602125535-1b6d00b8c37c
1212
github.com/spf13/cobra v1.9.1
1313
github.com/spf13/pflag v1.0.6
1414
github.com/stretchr/testify v1.10.0
@@ -22,7 +22,7 @@ require (
2222
k8s.io/component-base v0.33.2
2323
k8s.io/klog/v2 v2.130.1
2424
k8s.io/utils v0.0.0-20241210054802-24370beab758
25-
open-cluster-management.io/api v1.0.0
25+
open-cluster-management.io/api v1.0.1-0.20250827024027-f3e5dab96ea1
2626
open-cluster-management.io/sdk-go v1.0.1-0.20250811075710-18b20e146feb
2727
sigs.k8s.io/controller-runtime v0.20.2
2828
)
@@ -52,7 +52,6 @@ require (
5252
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5353
github.com/eclipse/paho.golang v0.21.0 // indirect
5454
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
55-
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
5655
github.com/felixge/httpsnoop v1.0.4 // indirect
5756
github.com/fsnotify/fsnotify v1.7.0 // indirect
5857
github.com/fxamacker/cbor/v2 v2.7.0 // indirect

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ github.com/eclipse/paho.golang v0.21.0 h1:cxxEReu+iFbA5RrHfRGxJOh8tXZKDywuehneoe
7474
github.com/eclipse/paho.golang v0.21.0/go.mod h1:GHF6vy7SvDbDHBguaUpfuBkEB5G6j0zKxMG4gbh6QRQ=
7575
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
7676
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
77-
github.com/evanphx/json-patch v5.9.11+incompatible h1:ixHHqfcGvxhWkniF1tWxBHA0yb4Z+d1UQi45df52xW8=
78-
github.com/evanphx/json-patch v5.9.11+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
7977
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
8078
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
8179
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
@@ -226,8 +224,8 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw
226224
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
227225
github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w=
228226
github.com/opencontainers/runc v1.1.3/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg=
229-
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee h1:+Sp5GGnjHDhT/a/nQ1xdp43UscBMr7G5wxsYotyhzJ4=
230-
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
227+
github.com/openshift/build-machinery-go v0.0.0-20250602125535-1b6d00b8c37c h1:gJvhduWIrpzoUTwrJjjeul+hGETKkhRhEZosBg/X3Hg=
228+
github.com/openshift/build-machinery-go v0.0.0-20250602125535-1b6d00b8c37c/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
231229
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
232230
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
233231
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -448,8 +446,8 @@ k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUy
448446
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8=
449447
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
450448
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
451-
open-cluster-management.io/api v1.0.0 h1:54QllH9DTudCk6VrGt0q8CDsE3MghqJeTaTN4RHZpE0=
452-
open-cluster-management.io/api v1.0.0/go.mod h1:/OeqXycNBZQoe3WG6ghuWsMgsKGuMZrK8ZpsU6gWL0Y=
449+
open-cluster-management.io/api v1.0.1-0.20250827024027-f3e5dab96ea1 h1:X5dL1aKnkLGHItMsEexGhLZsyZJHDlxGD4eRvsD181g=
450+
open-cluster-management.io/api v1.0.1-0.20250827024027-f3e5dab96ea1/go.mod h1:lEc5Wkc9ON5ym/qAtIqNgrE7NW7IEOCOC611iQMlnKM=
453451
open-cluster-management.io/sdk-go v1.0.1-0.20250811075710-18b20e146feb h1:voE6JR6Xi8wNTSkhADHP19FpGICUpqt1/lEREQt7TVU=
454452
open-cluster-management.io/sdk-go v1.0.1-0.20250811075710-18b20e146feb/go.mod h1:sHOVhUgA286ceEq3IjFWqxobt9Lu+VBCAUZByFgN0oM=
455453
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 h1:jpcvIRr3GLoUoEKRkHKSmGjxb6lWwrBlJsXc+eUYQHM=

pkg/utils/csr_helper_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"open-cluster-management.io/addon-framework/pkg/agent"
1717
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
1818
clusterv1 "open-cluster-management.io/api/cluster/v1"
19+
operatorapiv1 "open-cluster-management.io/api/operator/v1"
1920
)
2021

2122
func newCSR(commonName string, clusterName string, orgs ...string) *certificatesv1.CertificateSigningRequest {
@@ -118,6 +119,20 @@ func TestDefaultCSRApprover(t *testing.T) {
118119
addon: newAddon("addon1", "cluster1"),
119120
approved: false,
120121
},
122+
{
123+
name: "approve grpc csr",
124+
csr: func() *certificatesv1.CertificateSigningRequest {
125+
csr := newCSR(agent.DefaultUser("cluster1", "addon1", "test"), "cluster1", agent.DefaultGroups("cluster1", "addon1")...)
126+
csr.Spec.Username = defaultGRPCServiceAccount
127+
csr.Annotations = map[string]string{
128+
operatorapiv1.CSRUsernameAnnotation: "system:open-cluster-management:cluster1",
129+
}
130+
return csr
131+
}(),
132+
cluster: newCluster("cluster1"),
133+
addon: newAddon("addon1", "cluster1"),
134+
approved: true,
135+
},
121136
}
122137

123138
approver := DefaultCSRApprover("test")

pkg/utils/csr_helpers.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ import (
1919
"k8s.io/klog/v2"
2020
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
2121
clusterv1 "open-cluster-management.io/api/cluster/v1"
22+
operatorapiv1 "open-cluster-management.io/api/operator/v1"
2223

2324
"open-cluster-management.io/addon-framework/pkg/agent"
2425
)
2526

27+
const defaultGRPCServiceAccount = "system:serviceaccount:open-cluster-management-hub:grpc-server-sa"
28+
2629
var serialNumberLimit = new(big.Int).Lsh(big.NewInt(1), 128)
2730

2831
// DefaultSignerWithExpiry generates a signer func for addon agent to sign the csr using caKey and caData with expiry date.
@@ -170,13 +173,20 @@ func DefaultCSRApprover(agentName string) agent.CSRApproveFunc {
170173
}
171174

172175
// check user name
173-
if strings.HasPrefix(csr.Spec.Username, "system:open-cluster-management:"+cluster.Name) {
176+
username := csr.Spec.Username
177+
if csr.Spec.Username == defaultGRPCServiceAccount {
178+
// the CSR username is the service account of gRPC server rather than the user of agent.
179+
// use the CSRUsernameAnnotation that identifies the agent user who requested the CSR.
180+
username = csr.Annotations[operatorapiv1.CSRUsernameAnnotation]
181+
}
182+
183+
if strings.HasPrefix(username, "system:open-cluster-management:"+cluster.Name) {
174184
klog.Info("CSR approved")
175185
return true
176-
} else {
177-
klog.Info("CSR not approved due to illegal requester", "requester", csr.Spec.Username)
178-
return false
179186
}
187+
188+
klog.Info("CSR not approved due to illegal requester", "requester", csr.Spec.Username)
189+
return false
180190
}
181191
}
182192

vendor/github.com/evanphx/json-patch/.gitignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

vendor/github.com/evanphx/json-patch/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)