forked from CrunchyData/postgres-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Bash to assert on dropped caps in E2E tests
OpenShift appends to the list of dropped capabilities, and KUTTL is unable to assert a subset of that list. Do the assertion ourselves in a script rather than create a copy of the test specifically for OpenShift. Issue: [sc-15297] See: kudobuilder/kuttl#76
- Loading branch information
Showing
2 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
testing/kuttl/e2e/security-context/01--security-context.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
commands: | ||
- script: | | ||
# Check that every container has the correct capabilities. | ||
# Capture every container name alongside its list of dropped capabilities. | ||
CONTAINERS_DROP_CAPS=$( | ||
kubectl --namespace "${NAMESPACE}" get pods --output "jsonpath={\ | ||
range .items[*].spec.containers[*]\ | ||
}{ @.name }{'\t\t'}{ @.securityContext.capabilities.drop }{'\n'}{\ | ||
end\ | ||
}" | ||
) || exit | ||
WRONG=$( ! echo "${CONTAINERS_DROP_CAPS}" | grep -Fv '"ALL"' ) || { | ||
echo 'Not all containers have dropped "ALL" capabilities!' | ||
echo "${WRONG}" | ||
exit 1 | ||
} | ||
- script: | | ||
# Check that every Pod is assigned to the "restricted" SecurityContextConstraint | ||
# in OpenShift. | ||
SCC=$( | ||
kubectl api-resources --cached | | ||
grep -F 'security.openshift.io/v1' | | ||
grep -F 'SecurityContextConstraint' | ||
) | ||
# Skip this check when the API has no notion of SecurityContextConstraint. | ||
[ -z "${SCC}" ] && exit | ||
PODS_SCC=$( | ||
kubectl --namespace "${NAMESPACE}" get pods --no-headers \ | ||
--output "custom-columns=\ | ||
NAME:.metadata.name,\ | ||
SCC:.metadata.annotations['openshift\.io/scc']\ | ||
" | ||
) || exit | ||
WRONG=$( ! echo "${PODS_SCC}" | grep -Ev '\<restricted$' ) || { | ||
echo 'Found pods not assigned to the restricted security context constraint!' | ||
echo "${PODS_SCC}" | ||
exit 1 | ||
} |