-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use token based approach for system-agent
Reduce the footprint of the system-agent RBAC Per each cluster there will be created: - 1 system-agent ServiceAccount Per each plan there will be temporarily created: - 1 Role with access to all plan secrets for each machine - 1 Rolebinging for the role and the cluster system-agent ServiceAccount On plan completion/failure the role and rolebinding will be rewoked Per each machine there will be created: - 1 Secret for the system-agent authentication, with unique JWT bound to the secret existence in the API server, and a namespace/name pointer to the plan secret - 1 Secret for the plan execution Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
- Loading branch information
1 parent
f2d9579
commit d96b0f5
Showing
11 changed files
with
306 additions
and
167 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
101 changes: 101 additions & 0 deletions
101
exp/etcdrestore/controllers/etcdsnapshotrestore_controller_test.go
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,101 @@ | ||
/* | ||
Copyright © 2023 - 2024 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
// . "github.com/onsi/gomega" | ||
bootstrapv1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta1" | ||
// corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
rke2Config *bootstrapv1.RKE2Config | ||
serviceAccountName string | ||
serviceAccountNamespace string | ||
planSecretName string | ||
serverUrl string | ||
pem string | ||
systemAgentVersion string | ||
token []byte | ||
) | ||
|
||
var _ = Describe("RKE2ConfigWebhook tests", func() { | ||
// It("Should create a role with the correct properties", func() { | ||
// role := r.createRole(planSecretName, rke2Config) | ||
|
||
// Expect(role.ObjectMeta.Name).To(Equal(planSecretName)) | ||
// Expect(role.ObjectMeta.Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(role.Rules[0].Verbs).To(Equal([]string{"watch", "get", "update", "list"})) | ||
// Expect(role.Rules[0].APIGroups).To(Equal([]string{""})) | ||
// Expect(role.Rules[0].Resources).To(Equal([]string{"secrets"})) | ||
// Expect(role.Rules[0].ResourceNames).To(Equal([]string{planSecretName})) | ||
// }) | ||
|
||
// It("Should create a role binding with the correct properties", func() { | ||
// roleBinding := r.createRoleBinding(planSecretName, rke2Config) | ||
|
||
// Expect(roleBinding.ObjectMeta.Name).To(Equal(planSecretName)) | ||
// Expect(roleBinding.ObjectMeta.Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(roleBinding.Subjects[0].Kind).To(Equal("ServiceAccount")) | ||
// Expect(roleBinding.Subjects[0].Name).To(Equal(planSecretName)) | ||
// Expect(roleBinding.Subjects[0].Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(roleBinding.RoleRef.APIGroup).To(Equal(rbacv1.GroupName)) | ||
// Expect(roleBinding.RoleRef.Kind).To(Equal("Role")) | ||
// Expect(roleBinding.RoleRef.Name).To(Equal(planSecretName)) | ||
// }) | ||
|
||
// It("Should create a role with the correct properties", func() { | ||
// role := r.createRole(planSecretName, rke2Config) | ||
|
||
// Expect(role.ObjectMeta.Name).To(Equal(planSecretName)) | ||
// Expect(role.ObjectMeta.Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(role.Rules[0].Verbs).To(Equal([]string{"watch", "get", "update", "list"})) | ||
// Expect(role.Rules[0].APIGroups).To(Equal([]string{""})) | ||
// Expect(role.Rules[0].Resources).To(Equal([]string{"secrets"})) | ||
// Expect(role.Rules[0].ResourceNames).To(Equal([]string{planSecretName})) | ||
// }) | ||
|
||
// It("Should create a role binding with the correct properties", func() { | ||
// roleBinding := r.createRoleBinding(planSecretName, rke2Config) | ||
|
||
// Expect(roleBinding.ObjectMeta.Name).To(Equal(planSecretName)) | ||
// Expect(roleBinding.ObjectMeta.Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(roleBinding.Subjects[0].Kind).To(Equal("ServiceAccount")) | ||
// Expect(roleBinding.Subjects[0].Name).To(Equal(planSecretName)) | ||
// Expect(roleBinding.Subjects[0].Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(roleBinding.RoleRef.APIGroup).To(Equal(rbacv1.GroupName)) | ||
// Expect(roleBinding.RoleRef.Kind).To(Equal("Role")) | ||
// Expect(roleBinding.RoleRef.Name).To(Equal(planSecretName)) | ||
// }) | ||
|
||
// It("Should create a service account secret with the correct properties", func() { | ||
// secret := r.createServiceAccountSecret(planSecretName, rke2Config) | ||
|
||
// Expect(secret.ObjectMeta.Name).To(Equal(fmt.Sprintf("%s-token", planSecretName))) | ||
// Expect(secret.ObjectMeta.Namespace).To(Equal(rke2Config.Namespace)) | ||
// Expect(secret.ObjectMeta.Annotations["kubernetes.io/service-account.name"]).To(Equal(planSecretName)) | ||
// Expect(secret.ObjectMeta.Labels[serviceAccountSecretLabel]).To(Equal(planSecretName)) | ||
// Expect(secret.Type).To(Equal(corev1.SecretTypeServiceAccountToken)) | ||
// }) | ||
|
||
// It("Should return service account token when secret is present and populated", func() { | ||
// token, err := r.issueBootstrapToken(ctx, planSecretName) | ||
// Expect(err).ToNot(HaveOccurred()) | ||
// Expect(token).To(Equal([]byte("test-token"))) | ||
// }) | ||
}) |
Oops, something went wrong.