Skip to content

Commit 0ee23db

Browse files
Review securitycontext in Makefile/CI (#167)
* Review securitycontext for score-compose * securitycontext with score-k8s * automountServiceAccountToken=false * Fix Syntax error: Unterminated quoted string * score-* deployment success in PR comment * Fix comment
1 parent 6c8956e commit 0ee23db

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

.github/workflows/open-pr.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ jobs:
4141
- name: make compose.yaml
4242
run: |
4343
make compose.yaml
44-
cat <<EOF > compose.override.yaml
45-
services:
46-
${{ env.WORKLOAD_NAME }}-${{ env.CONTAINER_NAME }}:
47-
read_only: true
48-
cap_drop:
49-
- ALL
50-
user: "1000"
51-
EOF
5244
- name: make compose-test
5345
run: |
5446
make compose-test
@@ -192,12 +184,22 @@ jobs:
192184
--token ${{ secrets.HUMANITEC_TOKEN }} \
193185
| grep '"status": "Failure"' -B 10 -A 1) \
194186
|| true
187+
188+
echo "#### :white_check_mark: Successfully deployed with score-compose" >> pr_message.txt
189+
echo "" >> pr_message.txt
190+
echo "#### :white_check_mark: Successfully deployed with score-k8s" >> pr_message.txt
191+
echo "" >> pr_message.txt
192+
195193
if [[ "$DEPLOYMENT_ERRORS" = "[]" && -z "$RUNTIME_ERRORS" ]]; then
196194
echo "## Deployment successfully completed for ${{ env.ENVIRONMENT_NAME }}! :tada:" >> pr_message.txt
197195
echo "" >> pr_message.txt
196+
echo "#### :white_check_mark: Successfully deployed with humctl" >> pr_message.txt
197+
echo "" >> pr_message.txt
198198
else
199199
echo "## Deployment failed for ${{ env.ENVIRONMENT_NAME }}! :x:" >> pr_message.txt
200200
echo "" >> pr_message.txt
201+
echo "#### :x: Deployment failed with `humctl`" >> pr_message.txt
202+
echo "" >> pr_message.txt
201203
202204
if [ "$DEPLOYMENT_ERRORS" != "[]" ]; then
203205
echo "### Deployment errors:" >> pr_message.txt

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ compose.yaml: score/score.yaml .score-compose/state.yaml Makefile
2323
score-compose generate score/score.yaml \
2424
--build '${CONTAINER_NAME}={"context":"app/","tags":["${CONTAINER_IMAGE}"]}' \
2525
--override-property containers.${CONTAINER_NAME}.variables.MESSAGE="Hello, Compose!"
26+
echo '{"services":{"${WORKLOAD_NAME}-${CONTAINER_NAME}":{"read_only":"true","user":"65532","cap_drop":["ALL"]}}}' | yq e -P > compose.override.yaml
2627

2728
## Generate a compose.yaml file from the score spec and launch it.
2829
.PHONY: compose-up
@@ -47,7 +48,10 @@ compose-down:
4748
manifests.yaml: score/score.yaml .score-k8s/state.yaml Makefile
4849
score-k8s generate score/score.yaml \
4950
--image ${CONTAINER_IMAGE} \
50-
--override-property containers.${CONTAINER_NAME}.variables.MESSAGE="Hello, Kubernetes!"
51+
--override-property containers.${CONTAINER_NAME}.variables.MESSAGE="Hello, Kubernetes!" \
52+
--patch-manifests 'Deployment/*/spec.template.spec.automountServiceAccountToken=false' \
53+
--patch-manifests 'Deployment/*/spec.template.spec.securityContext={"fsGroup":65532,"runAsGroup":65532,"runAsNonRoot":true,"runAsUser":65532,"seccompProfile":{"type":"RuntimeDefault"}}'
54+
echo '{"spec":{"template":{"spec":{"containers":[{"name":"${CONTAINER_NAME}","securityContext":{"allowPrivilegeEscalation":false,"privileged": false,"readOnlyRootFilesystem": true,"capabilities":{"drop":["ALL"]}}}]}}}}' > deployment-patch.yaml
5155

5256
## Create a local Kind cluster.
5357
.PHONY: kind-create-cluster
@@ -66,6 +70,10 @@ k8s-up: manifests.yaml
6670
kubectl apply \
6771
-f manifests.yaml \
6872
-n ${NAMESPACE}
73+
kubectl patch \
74+
deployment ${WORKLOAD_NAME} \
75+
--patch-file deployment-patch.yaml \
76+
-n ${NAMESPACE}
6977
kubectl wait deployments/${WORKLOAD_NAME} \
7078
-n ${NAMESPACE} \
7179
--for condition=Available \

0 commit comments

Comments
 (0)