Skip to content

Commit da46ec5

Browse files
committed
Remove cluster role binding referencing default service account
To ensure the default SA does not have cluster admin permissions. To achieve this, rendering logic needs to be updated as well. During cluster bootstrap, the installer calls rendering commands of specific components required for the bootstrap [1]. These rendered manifests are then applied by the cluster-bootstrap component [2]. The cluster-bootstrap component applies all the non-bootstrap manifests as they are [3]. At no stage is the delete annotation [4] taken into account, and thus the CRB would keep getting applied during installations and getting removed only during cluster upgrades due to the annotation. This would prohibit us from ever removing the manifest file from the repository, as a freshly installed cluster upgrading to a version where manifest does not exist would result in the CRB being applied till manually removed, causing a security concern. Teach the rendering command to respect the delete annotation to allow us to remove such manifests. [1]: https://github.com/openshift/installer/blob/c93ae9fc74d7fa0f478fa250de2ba702f84a0a21/data/data/bootstrap/files/usr/local/bin/bootkube.sh.template [2]: https://github.com/openshift/installer/blob/c93ae9fc74d7fa0f478fa250de2ba702f84a0a21/data/data/bootstrap/files/usr/local/bin/bootkube.sh.template#L576 [3]: https://github.com/openshift/cluster-bootstrap/blob/b23c6ce3df43aed15158e999239694ec75371f18/pkg/start/start.go#L142 [4]: https://github.com/openshift/enhancements/blob/master/enhancements/update/object-removal-manifest-annotation.md
1 parent bb70c3b commit da46ec5

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

cmd/cluster-version-operator/render.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import (
1414
var (
1515
renderCmd = &cobra.Command{
1616
Use: "render",
17-
Short: "Renders the UpdatePayload to disk.",
18-
Long: "",
19-
Run: runRenderCmd,
17+
Short: "Renders and filters release payload manifests for cluster bootstrap.",
18+
Long: `Renders and filters CVO manifests and specific release payload manifests.
19+
20+
Called by the installer as part of cluster bootstrap to generate the initial manifests related to the CVO.`,
21+
Run: runRenderCmd,
2022
}
2123

2224
renderOpts struct {

install/0000_00_cluster-version-operator_03_roles-default.yaml renamed to install/0000_00_cluster-version-operator_90_roles-default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: cluster-version-operator
55
annotations:
66
include.release.openshift.io/self-managed-high-availability: "true"
7+
release.openshift.io/delete: "true"
78
roleRef:
89
kind: ClusterRole
910
name: cluster-admin

pkg/payload/render.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/openshift/api/config"
2222
configv1 "github.com/openshift/api/config/v1"
2323
"github.com/openshift/library-go/pkg/manifest"
24+
25+
"github.com/openshift/cluster-version-operator/lib/resourcedelete"
2426
)
2527

2628
// Render renders critical manifests from /manifests to outputDir.
@@ -148,6 +150,10 @@ func renderDir(renderConfig manifestRenderConfig, idir, odir string, overrides [
148150
klog.Infof("excluding %s because we do not render that group/kind", manifest.String())
149151
} else if err := manifest.Include(nil, requiredFeatureSet, clusterProfile, nil, overrides, enabledFeatureGates, majorVersion); err != nil {
150152
klog.Infof("excluding %s: %v", manifest.String(), err)
153+
} else if found, err := resourcedelete.ValidDeleteAnnotation(manifest.Obj.GetAnnotations()); err != nil {
154+
errs = append(errs, fmt.Errorf("invalid delete annotation in %s from %s: %w", manifest.String(), file.Name(), err))
155+
} else if found {
156+
klog.Infof("excluding %s because we do not render manifests with the delete annotation", manifest.String())
151157
} else {
152158
filteredManifests = append(filteredManifests, string(manifest.Raw))
153159
klog.Infof("including %s", manifest.String())

pkg/payload/render_test.go

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ func TestRenderManifest(t *testing.T) {
6565
}
6666
}
6767

68-
func TestRenderDirWithMajorVersionFiltering(t *testing.T) {
68+
func TestRenderDirFiltering(t *testing.T) {
6969
tests := []struct {
7070
name string
7171
manifests []testManifest
7272
majorVersion *uint64
7373
expectedInclusions []string // Names of manifests that should be included
7474
expectedExclusions []string // Names of manifests that should be excluded
75+
expectError bool // Whether an error is expected
7576
}{
7677
{
7778
name: "major version 4 includes version 4 manifests",
@@ -183,6 +184,49 @@ func TestRenderDirWithMajorVersionFiltering(t *testing.T) {
183184
expectedInclusions: []string{"version4-or-5-manifest", "exclude-version3-manifest"},
184185
expectedExclusions: []string{"version6-only-manifest"},
185186
},
187+
{
188+
name: "delete annotation excludes manifests",
189+
manifests: []testManifest{
190+
{
191+
name: "normal-manifest",
192+
annotations: map[string]string{},
193+
},
194+
{
195+
name: "deleted-manifest",
196+
annotations: map[string]string{
197+
"release.openshift.io/delete": "true",
198+
},
199+
},
200+
{
201+
name: "another-normal-manifest",
202+
annotations: map[string]string{
203+
"some.other.annotation": "value",
204+
},
205+
},
206+
},
207+
majorVersion: ptr.To(uint64(4)),
208+
expectedInclusions: []string{"normal-manifest", "another-normal-manifest"},
209+
expectedExclusions: []string{"deleted-manifest"},
210+
},
211+
{
212+
name: "invalid delete annotation value returns error but continues rendering",
213+
manifests: []testManifest{
214+
{
215+
name: "normal-manifest",
216+
annotations: map[string]string{},
217+
},
218+
{
219+
name: "invalid-delete-manifest",
220+
annotations: map[string]string{
221+
"release.openshift.io/delete": "false",
222+
},
223+
},
224+
},
225+
majorVersion: ptr.To(uint64(4)),
226+
expectedInclusions: []string{"normal-manifest"},
227+
expectedExclusions: []string{"invalid-delete-manifest"},
228+
expectError: true,
229+
},
186230
}
187231

188232
for _, tt := range tests {
@@ -233,8 +277,14 @@ func TestRenderDirWithMajorVersionFiltering(t *testing.T) {
233277
sets.Set[schema.GroupKind]{}, // filterGroupKind
234278
)
235279

236-
if err != nil {
237-
t.Fatalf("renderDir failed: %v", err)
280+
if tt.expectError {
281+
if err == nil {
282+
t.Errorf("expected error but got none")
283+
}
284+
} else {
285+
if err != nil {
286+
t.Fatalf("renderDir failed: %v", err)
287+
}
238288
}
239289

240290
// Check which manifests were included in output

0 commit comments

Comments
 (0)