From adb11f62d15d8bdfaebb18a368f134432e5775ec Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:04:24 +0200 Subject: [PATCH] fix(rbac): adds resourceNames (#662) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [x] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [x] ⚠️ My changes generate no new warnings - [x] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [x] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- library/common-test/tests/rbac/data_test.yaml | 4 ++++ .../tests/rbac/validation_test.yaml | 19 +++++++++++++++++++ library/common/Chart.yaml | 2 +- library/common/templates/lib/rbac/_rules.tpl | 12 +++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/library/common-test/tests/rbac/data_test.yaml b/library/common-test/tests/rbac/data_test.yaml index e21141474..289fb4f74 100644 --- a/library/common-test/tests/rbac/data_test.yaml +++ b/library/common-test/tests/rbac/data_test.yaml @@ -35,6 +35,8 @@ tests: - "{{ .Values.some_group }}" resources: - "{{ .Values.some_resource }}" + resourceNames: + - "{{ .Values.some_name }}" verbs: - "{{ .Values.some_verb }}" subjects: @@ -67,6 +69,8 @@ tests: - apps resources: - deployments + resourceNames: + - some-name verbs: - list - documentIndex: &roleBinding 3 diff --git a/library/common-test/tests/rbac/validation_test.yaml b/library/common-test/tests/rbac/validation_test.yaml index b12ff144b..f256e2e8a 100644 --- a/library/common-test/tests/rbac/validation_test.yaml +++ b/library/common-test/tests/rbac/validation_test.yaml @@ -252,6 +252,25 @@ tests: - failedTemplate: errorMessage: RBAC - Expected non-empty [rbac.subjects.apiGroup] + - it: should fail with empty entry in resourceName in rules in rbac + set: + rbac: + my-rbac: + enabled: true + primary: true + rules: + - apiGroups: + - "" + resources: + - pods + resourceNames: + - "" + verbs: + - get + asserts: + - failedTemplate: + errorMessage: RBAC - Expected non-empty entry in [rbac.rules.resourceNames] + - it: should fail with namespace longer than 63 characters set: serviceAccount: diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 1de82eeff..b08284bbb 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 17.1.1 +version: 17.1.2 diff --git a/library/common/templates/lib/rbac/_rules.tpl b/library/common/templates/lib/rbac/_rules.tpl index be32dcc33..44fb9ff2d 100644 --- a/library/common/templates/lib/rbac/_rules.tpl +++ b/library/common/templates/lib/rbac/_rules.tpl @@ -36,7 +36,17 @@ objectData: The object data to be used to render the RBAC. {{- fail "RBAC - Expected non-empty entry in [rbac.rules.resources]" -}} {{- end }} - {{ tpl . $rootCtx | quote }} - {{- end -}} + {{- end -}} + {{- /* resourceNames */}} + {{- if .resourceNames }} + resourceNames: + {{- range .resourceNames -}} + {{- if not . -}} + {{- fail "RBAC - Expected non-empty entry in [rbac.rules.resourceNames]" -}} + {{- end }} + - {{ tpl . $rootCtx | quote }} + {{- end -}} + {{- end -}} {{- /* verbs */}} verbs: {{- range .verbs -}}