add NET_BIND_SERVICE on ports <1024 (#340)

**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**

- [x] ⚙️ Feature/App addition
- [ ] 🪛 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._
This commit is contained in:
Stavros Kois
2023-03-04 11:49:01 +02:00
committed by GitHub
parent d9d5bf7bcb
commit f992ce2baa
4 changed files with 25 additions and 2 deletions

View File

@@ -136,6 +136,13 @@ tests:
- name: port-name
containerPort: 1234
protocol: TCP
- documentIndex: *deploymentDoc
isNotSubset:
path: spec.template.spec.containers[0].securityContext.capabilities
content:
add:
- NET_BIND_SERVICE
- documentIndex: &otherDeploymentDoc 1
isKind:
of: Deployment
@@ -147,6 +154,12 @@ tests:
- name: port-name
containerPort: 53
protocol: TCP
- documentIndex: *otherDeploymentDoc
isSubset:
path: spec.template.spec.containers[0].securityContext.capabilities
content:
add:
- NET_BIND_SERVICE
- it: should create the correct ports with hostPort
set:

View File

@@ -66,7 +66,7 @@ tests:
data: {}
asserts:
- failedTemplate:
errorMessage: Secret - Expected non-empty <data>
errorMessage: Secret - Expected non-empty <data> or <stringData>
- it: should fail with empty type key
set:

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 12.2.11
version: 12.2.12

View File

@@ -122,6 +122,16 @@ objectData: The object data to be used to render the container.
{{- fail "Container - Expected <securityContext.capabilities> to be defined" -}}
{{- end -}}
{{- $tempObjectData := (dict "shortName" $objectData.podShortName "primary" $objectData.podPrimary) -}}
{{- $portRange := fromJson (include "tc.v1.common.lib.helpers.securityContext.getPortRange" (dict "rootCtx" $rootCtx "objectData" $tempObjectData)) -}}
{{- if and $portRange.low (le (int $portRange.low) 1024) -}} {{/* If a container wants to bind a port <= 1024 add NET_BIND_SERVICE */}}
{{- $addCap := $secContext.capabilities.add -}}
{{- if not (mustHas "NET_BIND_SERIVCE" $addCap) -}}
{{- $addCap = mustAppend $addCap "NET_BIND_SERVICE" -}}
{{- end -}}
{{- $_ := set $secContext.capabilities "add" $addCap -}}
{{- end -}}
{{- range $key := (list "add" "drop") -}}
{{- $item := (get $secContext.capabilities $key) -}}
{{- if not (kindIs "slice" $item) -}}