-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow extra manually added pull secrets to managed SA (#418)
* feat: add annotation on SA to keep track of pull secrets Add an annotation to keep track of managed pullsecrets on the created service account * feat: use actual pull secret comparision instead of annotations * feat: tidy current e2e tests and add cleanups * fix: add banner * feat: add e2e service account tests * fix: yq syntax fix * fix: yq eval environment variable * fix: e2e scripts base_dir reference * Revert "fix: e2e scripts base_dir reference" This reverts commit e070403. * fix: copy missing tests folder into e2e container * feat: bump rok8s to @13 and ci-images to v13
- Loading branch information
Showing
15 changed files
with
300 additions
and
46 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
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
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,2 @@ | ||
kubectl delete clusterrole test-rbac-manager --ignore-not-found | ||
kubectl delete RBACDefinition rbac-manager-definition --ignore-not-found |
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,21 @@ | ||
BASE_DIR=$(dirname $BASH_SOURCE) | ||
|
||
printf "\n\n" | ||
echo "********************************************************************" | ||
echo "** Test clusterrolebindings **" | ||
echo "********************************************************************" | ||
printf "\n\n" | ||
|
||
# Execute the setup, then execute the tests just if the setup contains no errors. | ||
# Finally always execute the cleanup and return the whole error of the steps | ||
error=$((0)) | ||
bash "$BASE_DIR/setup.sh" | ||
error=$(( error | $? )) | ||
|
||
if [ $error -eq 0 ]; then | ||
bash "$BASE_DIR/tests.sh" | ||
error=$(( error | $? )) | ||
fi | ||
|
||
bash "$BASE_DIR/cleanup.sh" | ||
exit $(( error | $? )) |
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,16 @@ | ||
kubectl create clusterrole test-rbac-manager --verb="create" --resource=deployment | ||
|
||
cat <<EOF | kubectl create -f - | ||
apiVersion: rbacmanager.reactiveops.io/v1beta1 | ||
kind: RBACDefinition | ||
metadata: | ||
name: rbac-manager-definition | ||
rbacBindings: | ||
- name: admins | ||
subjects: | ||
- kind: ServiceAccount | ||
name: test-rbac-manager | ||
namespace: rbac-manager | ||
clusterRoleBindings: | ||
- clusterRole: test-rbac-manager | ||
EOF |
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,10 @@ | ||
# wait up to 2 minutes for rbac-manager to create the binding | ||
counter=0 | ||
until kubectl get clusterrolebinding/rbac-manager-definition-admins-test-rbac-manager; do | ||
let "counter=counter+1" | ||
sleep 10 | ||
if [ $counter -gt 11 ]; then | ||
break | ||
fi | ||
done | ||
kubectl auth can-i create deployments --as=system:serviceaccount:rbac-manager:test-rbac-manager |
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,18 @@ | ||
BASE_DIR=$(dirname $BASH_SOURCE) | ||
|
||
printf "\n\n" | ||
echo "********************************************************************" | ||
echo "** Test rbacDefinition **" | ||
echo "********************************************************************" | ||
printf "\n\n" | ||
|
||
|
||
bash "$BASE_DIR/cluterrolebindings/main.sh" | ||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
bash "$BASE_DIR/serviceaccounts/main.sh" | ||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi |
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,2 @@ | ||
kubectl delete clusterrole test-rbac-manager --ignore-not-found | ||
kubectl delete RBACDefinition rbac-manager-definition-1 --ignore-not-found |
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,21 @@ | ||
BASE_DIR=$(dirname $BASH_SOURCE) | ||
|
||
printf "\n\n" | ||
echo "********************************************************************" | ||
echo "** Test serviceaccounts **" | ||
echo "********************************************************************" | ||
printf "\n\n" | ||
|
||
# Execute the setup, then execute the tests just if the setup contains no errors. | ||
# Finally always execute the cleanup and return the whole error of the steps | ||
error=$((0)) | ||
bash "$BASE_DIR/setup.sh" | ||
error=$(( error | $? )) | ||
|
||
if [ $error -eq 0 ]; then | ||
bash "$BASE_DIR/tests.sh" | ||
error=$(( error | $? )) | ||
fi | ||
|
||
bash "$BASE_DIR/cleanup.sh" | ||
exit $(( error | $? )) |
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,18 @@ | ||
kubectl create clusterrole test-rbac-manager --verb="create" --resource=deployment | ||
|
||
cat <<EOF | kubectl create -f - | ||
apiVersion: rbacmanager.reactiveops.io/v1beta1 | ||
kind: RBACDefinition | ||
metadata: | ||
name: rbac-manager-definition-1 | ||
rbacBindings: | ||
- name: admins | ||
subjects: | ||
- kind: ServiceAccount | ||
name: test-rbac-manager | ||
namespace: rbac-manager | ||
imagePullSecrets: | ||
- robot-secret | ||
clusterRoleBindings: | ||
- clusterRole: test-rbac-manager | ||
EOF |
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,68 @@ | ||
# wait up to 2 minutes for rbac-manager to create the binding | ||
counter=0 | ||
error=$((0)) | ||
until kubectl get -n rbac-manager serviceaccount/test-rbac-manager; do | ||
let "counter=counter+1" | ||
sleep 10 | ||
if [ $counter -gt 11 ]; then | ||
break | ||
fi | ||
done | ||
|
||
kubectl get -n rbac-manager serviceaccount/test-rbac-manager | ||
error=$(( error | $? )) | ||
if [ "$error" -eq 1 ]; then | ||
>&2 echo "error: The Service account must exists" | ||
fi | ||
kubectl delete -n rbac-manager serviceaccount/test-rbac-manager | ||
kubectl get -n rbac-manager serviceaccount/test-rbac-manager | ||
error=$(( error | $? )) | ||
if [ "$error" -eq 1 ]; then | ||
>&2 echo "error: The Service account must be recreated" | ||
fi | ||
|
||
# ImagePullSecret is created | ||
contents=$(kubectl get -n rbac-manager serviceaccount/test-rbac-manager -oyaml | yq 'select(.imagePullSecrets[] | .name == "robot-secret")') | ||
if [ -z "$contents" ]; then | ||
error=$(( error | 1 )) | ||
fi | ||
if [ "$error" -eq 1 ]; then | ||
>&2 echo "error: ImagePullSecret \"robot-secret\" must exists" | ||
fi | ||
|
||
# ImagePullSecret is re-created if deleted | ||
cat <<EOF | kubectl patch -n rbac-manager serviceaccount/test-rbac-manager --type=merge -p "$(cat -)" | ||
{ | ||
"imagePullSecrets": [] | ||
} | ||
EOF | ||
contents=$(kubectl get -n rbac-manager serviceaccount/test-rbac-manager -oyaml | yq 'select(.imagePullSecrets[] | .name == "robot-secret")') | ||
if [ -z "$contents" ]; then | ||
error=$(( error | 1 )) | ||
fi | ||
if [ "$error" -eq 1 ]; then | ||
>&2 echo "error: ImagePullSecret \"robot-secret\" must be re-created" | ||
fi | ||
|
||
# If ImagePullSecret is added it should not be removed | ||
|
||
cat <<EOF | kubectl patch -n rbac-manager serviceaccount/test-rbac-manager --type=json -p "$(cat -)" | ||
[ | ||
{ | ||
"op": "add", | ||
"path": "/imagePullSecrets/-", | ||
"value": { | ||
"name": "new-secret-name" | ||
} | ||
} | ||
] | ||
EOF | ||
contents=$(kubectl get -n rbac-manager serviceaccount/test-rbac-manager -oyaml | yq 'select(.imagePullSecrets[] | .name == "new-secret-name")') | ||
if [ -z "$contents" ]; then | ||
error=$(( error | 1 )) | ||
fi | ||
if [ "$error" -eq 1 ]; then | ||
>&2 echo "error: ImagePullSecret \"new-secret-name\" must be kept" | ||
fi | ||
|
||
exit $error |
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
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
Oops, something went wrong.