Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added securityContext profile to cronjob in istio-system and remove PSS workflow warnings #2848

Merged
merged 19 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/kserve_m2m_test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Deploy and test KServe with m2m auth in KinD
on:

Check warning on line 2 in .github/workflows/kserve_m2m_test.yaml

View workflow job for this annotation

GitHub Actions / format_YAML_files

2:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- tests/gh-actions/install_KinD_create_KinD_cluster_install_kustomize.sh
- .github/workflows/kserve_m2m_test.yaml
- contrib/kserve/**
- common/oidc-client/oauth2-proxy/**
- common/oauth2-proxy/**
- common/istio*/**
- tests/gh-actions/install_istio_with_ext_auth.sh*
- tests/gh-actions/install_cert_manager.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notebook_controller_m2m_test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Test Notebook Controller with m2m auth manifests in KinD
on:

Check warning on line 2 in .github/workflows/notebook_controller_m2m_test.yaml

View workflow job for this annotation

GitHub Actions / format_YAML_files

2:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- tests/gh-actions/install_KinD_create_KinD_cluster_install_kustomize.sh
- .github/workflows/notebook_controller_m2m_test.yaml
- apps/jupyter/**
- common/oidc-client/oauth2-proxy/**
- common/oauth2-proxy/**
- common/istio*/**
- tests/gh-actions/install_istio_with_ext_auth.sh*
- tests/gh-actions/install_multi_tenancy.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pipeline_run_from_notebook.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Create Pipeline Run from Kubeflow Notebook
on:

Check warning on line 2 in .github/workflows/pipeline_run_from_notebook.yaml

View workflow job for this annotation

GitHub Actions / format_YAML_files

2:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- tests/gh-actions/install_KinD_create_KinD_cluster_install_kustomize.sh
Expand All @@ -11,7 +11,7 @@
- common/cert-manager/**
- common/oauth2-proxy/**
- common/istio*/**
- common/oidc-client/**
- common/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is probably too much. Let's revisit it in your follow up PR

- apps/jupyter/**

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pipeline_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Deploy and test Kubeflow Pipelines manifests with m2m auth in KinD
on:

Check warning on line 2 in .github/workflows/pipeline_test.yaml

View workflow job for this annotation

GitHub Actions / format_YAML_files

2:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- tests/gh-actions/install_KinD_create_KinD_cluster_install_kustomize.sh
Expand All @@ -8,7 +8,7 @@
- tests/gh-actions/install_istio.sh
- tests/gh-actions/install_cert_manager.sh
- common/cert-manager/**
- common/oidc-client/oauth2-proxy/**
- common/oauth2-proxy/**
- common/istio*/**
- tests/gh-actions/install_istio_with_ext_auth.sh

Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/pss_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Apply PSS labels to namespaces
on:

Check warning on line 2 in .github/workflows/pss_test.yaml

View workflow job for this annotation

GitHub Actions / format_YAML_files

2:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- tests/gh-actions/install_KinD_create_KinD_cluster_install_kustomize.sh
Expand Down Expand Up @@ -44,10 +44,10 @@
- name: Install KF Pipelines
run: ./tests/gh-actions/install_pipelines.sh

- name: Applying Pod Security Standards baseline levels for static namespaces
- name: Apply Pod Security Standards baseline levels for static namespaces
run: ./tests/gh-actions/enable_baseline_PSS.sh

- name: Applying Pod Security Standards baseline levels for dynamic namespaces
- name: Apply Pod Security Standards baseline levels for dynamic namespaces
run: |
cat << EOF > ./kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
Expand All @@ -61,14 +61,32 @@
rm ./kustomization.yaml
kubectl -n kubeflow wait --for=condition=Ready pods -l kustomize.component=profiles --timeout 180s

- name: Unapplying applied baseline values
- name: Unapply applied baseline values
run: |
NAMESPACES=("istio-system" "auth" "cert-manager" "oauth2-proxy" "kubeflow")
for NAMESPACE in "${NAMESPACES[@]}"; do
if kubectl get namespace "$NAMESPACE" >/dev/null 2>&1; then
kubectl label namespace $NAMESPACE pod-security.kubernetes.io/enforce-
fi
done
sleep 10

- name: Apply patches to clear warnings
run: |
DIRECTORY="contrib/security/PSS/patches"
for file in "$DIRECTORY"/*.yaml; do
echo "Patching file: $file"

KIND=$(kubectl get -f "$file" -o jsonpath='{.kind}')
NAME=$(kubectl get -f "$file" -o jsonpath='{.metadata.name}')
NAMESPACE=$(kubectl get -f "$file" -o jsonpath='{.metadata.namespace}')

# Apply the patch
kubectl get "$KIND" "$NAME" -n "$NAMESPACE" &> /dev/null
if [ $? -eq 0 ]; then
kubectl patch "$KIND" "$NAME" -n "$NAMESPACE" --patch-file "$file"
fi
done

- name: Applying Pod Security Standards restricted levels for static namespaces
run: ./tests/gh-actions/enable_restricted_PSS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ spec:
name: script
subPath: script.sh
resources: {}
securityContext:
allowPrivilegeEscalation: false
seccompProfile:
type: RuntimeDefault
runAsNonRoot: true
runAsUser: 1000
capabilities:
drop:
- ALL
volumes:
- name: script
configMap:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/cache-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: cache-server
namespace: kubeflow
spec:
template:
spec:
Expand Down
12 changes: 0 additions & 12 deletions contrib/security/PSS/patches/cluster-local-gateway.yaml

This file was deleted.

1 change: 1 addition & 0 deletions contrib/security/PSS/patches/dex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: dex
namespace: auth
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/kfam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: profiles-deployment
namespace: kubeflow
spec:
template:
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: kubeflow-pipelines-profile-controller
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: profiles-deployment
namespace: kubeflow
spec:
template:
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: metadata-envoy-deployment
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/metadata-grpc-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: metadata-grpc-deployment
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/metadata-writer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: metadata-writer
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/minio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: minio
namespace: kubeflow
spec:
template:
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline-persistenceagent
namespace: kubeflow
spec:
template:
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline-scheduledworkflow
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/ml-pipeline-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline-ui
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/ml-pipeline-viewer-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline-viewer-crd
namespace: kubeflow
spec:
template:
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline-visualizationserver
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/ml-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-pipeline
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: kubeflow
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions contrib/security/PSS/patches/oauth2-proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: oauth2-proxy
namespace: oauth2-proxy
spec:
replicas: 2
template:
Expand Down
18 changes: 14 additions & 4 deletions tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

CRONJOB_NAME=kubeflow-m2m-oidc-configurator
NAMESPACE=istio-system
RETRY_INTERVAL=5 # Each loop iterates after 'RETRY_INTERVAL' seconds
MAX_RETRIES=20 # Each loop iterates for a total number of 'MAX_RETRIES'

# Function to get the latest Job created by the CronJob
get_latest_job() {
Expand All @@ -13,19 +15,23 @@ get_latest_job() {

# Wait until a Job is created
echo "Waiting for a Job to be created by the ${CRONJOB_NAME} CronJob..."
while true; do
for ((i=1; i<=MAX_RETRIES; i++)); do
JOB_NAME=$(get_latest_job)
if [[ -n "${JOB_NAME}" ]]; then
echo "Job ${JOB_NAME} created."
break
fi
sleep 5
if [[ $i -eq $MAX_RETRIES ]]; then
echo "Job creation timed out."
exit 1
fi
sleep "${RETRY_INTERVAL}"
echo "Waiting..."
done

# Wait for the Job to complete successfully
echo "Waiting for the Job ${JOB_NAME} to complete..."
while true; do
for ((i=1; i<=MAX_RETRIES; i++)); do
STATUS=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}')
if [[ "${STATUS}" == "True" ]]; then
echo "Job ${JOB_NAME} completed successfully."
Expand All @@ -37,5 +43,9 @@ while true; do
echo "Job ${JOB_NAME} failed."
exit 1
fi
sleep 5
if [[ $i -eq $MAX_RETRIES ]]; then
echo "Job completion timed out."
exit 1
fi
sleep "${RETRY_INTERVAL}"
done
Loading