Skip to content

Commit

Permalink
fix(rbac): adds resourceNames (#662)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ 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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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._
  • Loading branch information
stavros-k authored Dec 26, 2023
1 parent 1e858c3 commit adb11f6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions library/common-test/tests/rbac/data_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ tests:
- "{{ .Values.some_group }}"
resources:
- "{{ .Values.some_resource }}"
resourceNames:
- "{{ .Values.some_name }}"
verbs:
- "{{ .Values.some_verb }}"
subjects:
Expand Down Expand Up @@ -67,6 +69,8 @@ tests:
- apps
resources:
- deployments
resourceNames:
- some-name
verbs:
- list
- documentIndex: &roleBinding 3
Expand Down
19 changes: 19 additions & 0 deletions library/common-test/tests/rbac/validation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 17.1.1
version: 17.1.2
12 changes: 11 additions & 1 deletion library/common/templates/lib/rbac/_rules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down

0 comments on commit adb11f6

Please sign in to comment.