From b073fe719252b2b2d4bbfcb4728e5cc667c479d6 Mon Sep 17 00:00:00 2001 From: jdaln <150942337+jdaln@users.noreply.github.com> Date: Fri, 8 May 2026 11:04:49 +0200 Subject: [PATCH 1/3] chore(appprojects): scope AppProjects to least privilege Squashes: - chore(mip-common): explicitly disallow namespace RBAC - chore(mip-federations): scope umbrella project to Application-only - chore(appprojects): remove unused mip-argo-project-shared-apps - chore(appprojects): add explicit RBAC blacklist + drift lint (cherry picked from commit 06bc70ba5455d65ee8c2fe2b257868c03b0dec60) --- .githooks/pre-commit | 50 +++++++++- base/argo-projects.yaml | 4 +- projects/static/mip-common/mip-common.yaml | 10 +- .../mip-federations/mip-federations.yaml | 39 +------- .../static/mip-security/mip-security.yaml | 6 ++ .../static/mip-shared-apps/kustomization.yaml | 4 - .../mip-shared-apps/mip-shared-apps.yaml | 91 ------------------- .../static/submariner/submariner-project.yaml | 7 ++ 8 files changed, 74 insertions(+), 137 deletions(-) delete mode 100644 projects/static/mip-shared-apps/kustomization.yaml delete mode 100644 projects/static/mip-shared-apps/mip-shared-apps.yaml diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 3692634..aee4db5 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -11,7 +11,55 @@ CRITICAL_FILES=( # Get the current branch name CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -# If on main branch, allow commit +# --------------------------------------------------------------------------- +# Drift check (runs on every branch including main): every static AppProject +# must explicitly blacklist Role and RoleBinding via namespaceResourceBlacklist. +# Per-federation AppProjects (rendered from projects/templates/federation/) are +# exempt because their destinations are pinned to a single federation namespace +# and so namespaced RBAC is in-scope. Files can opt out with the marker +# `# rbac-lint: ignore` near the top. +# --------------------------------------------------------------------------- +RBAC_DRIFT=0 +RBAC_PROBLEMS=() +for PROJ_FILE in projects/static/*/*.yaml; do + [[ -f "$PROJ_FILE" ]] || continue + grep -q '^kind: AppProject' "$PROJ_FILE" || continue + grep -q '^# rbac-lint: ignore' "$PROJ_FILE" && continue + if ! awk ' + /^ namespaceResourceBlacklist:/ { in_block = 1; next } + in_block && /^ [A-Za-z]/ { in_block = 0 } + in_block && /kind: Role$/ { has_role = 1 } + in_block && /kind: RoleBinding$/ { has_rb = 1 } + END { exit !(has_role && has_rb) } + ' "$PROJ_FILE"; then + RBAC_DRIFT=1 + RBAC_PROBLEMS+=("$PROJ_FILE") + fi +done + +if [[ "$RBAC_DRIFT" -ne 0 ]]; then + echo "---------------------------------------------------------------------------------" + echo "🛑 COMMIT BLOCKED: static AppProject(s) missing explicit RBAC blacklist" + echo "" + echo "Each static AppProject must declare:" + echo " namespaceResourceBlacklist:" + echo " - group: rbac.authorization.k8s.io" + echo " kind: Role" + echo " - group: rbac.authorization.k8s.io" + echo " kind: RoleBinding" + echo "" + echo "If a project legitimately needs to manage namespaced RBAC, opt out by" + echo "adding a '# rbac-lint: ignore' comment near the top of the file." + echo "" + echo "Affected files:" + for F in "${RBAC_PROBLEMS[@]}"; do + echo " - $F" + done + echo "---------------------------------------------------------------------------------" + exit 1 +fi + +# If on main branch, the remaining branch-pin checks don't apply. if [[ "$CURRENT_BRANCH" == "main" ]]; then exit 0 fi diff --git a/base/argo-projects.yaml b/base/argo-projects.yaml index 95806d8..0f30072 100644 --- a/base/argo-projects.yaml +++ b/base/argo-projects.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/managed-by: argocd argocd.instance: mip-team annotations: - argocd.argoproj.io/note: 'Manages static AppProjects: mip-federations, mip-shared-apps, + argocd.argoproj.io/note: 'Manages static AppProjects: mip-federations, mip-common, mip-monitoring, mip-security, submariner' spec: generators: @@ -17,8 +17,6 @@ spec: elements: - projectName: mip-argo-project-federations fileName: mip-federations - - projectName: mip-argo-project-shared-apps - fileName: mip-shared-apps - projectName: mip-argo-project-common fileName: mip-common - projectName: mip-argo-project-monitoring diff --git a/projects/static/mip-common/mip-common.yaml b/projects/static/mip-common/mip-common.yaml index 57a9db2..22433bb 100644 --- a/projects/static/mip-common/mip-common.yaml +++ b/projects/static/mip-common/mip-common.yaml @@ -44,10 +44,6 @@ spec: kind: ServiceAccount - group: '' kind: Pod - - group: rbac.authorization.k8s.io - kind: Role - - group: rbac.authorization.k8s.io - kind: RoleBinding - group: networking.k8s.io kind: Ingress - group: networking.k8s.io @@ -76,6 +72,12 @@ spec: kind: MutatingWebhookConfiguration - group: apiextensions.k8s.io kind: CustomResourceDefinition + # RBAC is never managed by this project; make it explicit + namespaceResourceBlacklist: + - group: rbac.authorization.k8s.io + kind: Role + - group: rbac.authorization.k8s.io + kind: RoleBinding roles: - name: common-admin description: Full access to common resources diff --git a/projects/static/mip-federations/mip-federations.yaml b/projects/static/mip-federations/mip-federations.yaml index 6816420..561cd9f 100644 --- a/projects/static/mip-federations/mip-federations.yaml +++ b/projects/static/mip-federations/mip-federations.yaml @@ -12,46 +12,12 @@ spec: - https://github.com/madgik/exareme2 - https://github.com/Medical-Informatics-Platform/mip destinations: - - namespace: federation-* - server: https://kubernetes.default.svc - namespace: argocd-mip-team server: https://kubernetes.default.svc clusterResourceWhitelist: [] namespaceResourceWhitelist: - group: argoproj.io kind: Application - - group: apps - kind: Deployment - - group: apps - kind: StatefulSet - - group: apps - kind: DaemonSet - - group: apps - kind: ReplicaSet - - group: '' - kind: Service - - group: '' - kind: ConfigMap - - group: '' - kind: Secret - - group: '' - kind: PersistentVolumeClaim - - group: '' - kind: ServiceAccount - - group: '' - kind: Pod - - group: rbac.authorization.k8s.io - kind: Role - - group: rbac.authorization.k8s.io - kind: RoleBinding - - group: networking.k8s.io - kind: Ingress - - group: networking.k8s.io - kind: NetworkPolicy - - group: batch - kind: Job - - group: batch - kind: CronJob # Explicitly blacklist sensitive resources to be future proof clusterResourceBlacklist: - group: rbac.authorization.k8s.io @@ -64,6 +30,11 @@ spec: kind: MutatingWebhookConfiguration - group: apiextensions.k8s.io kind: CustomResourceDefinition + namespaceResourceBlacklist: + - group: rbac.authorization.k8s.io + kind: Role + - group: rbac.authorization.k8s.io + kind: RoleBinding syncWindows: - kind: allow schedule: '* * * * *' diff --git a/projects/static/mip-security/mip-security.yaml b/projects/static/mip-security/mip-security.yaml index 68ff85f..e15aaa1 100644 --- a/projects/static/mip-security/mip-security.yaml +++ b/projects/static/mip-security/mip-security.yaml @@ -39,6 +39,12 @@ spec: kind: MutatingWebhookConfiguration - group: apiextensions.k8s.io kind: CustomResourceDefinition + # RBAC is never managed by this project; make it explicit + namespaceResourceBlacklist: + - group: rbac.authorization.k8s.io + kind: Role + - group: rbac.authorization.k8s.io + kind: RoleBinding syncWindows: - kind: allow schedule: '* * * * *' diff --git a/projects/static/mip-shared-apps/kustomization.yaml b/projects/static/mip-shared-apps/kustomization.yaml deleted file mode 100644 index 8b85ed4..0000000 --- a/projects/static/mip-shared-apps/kustomization.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: [mip-shared-apps.yaml] diff --git a/projects/static/mip-shared-apps/mip-shared-apps.yaml b/projects/static/mip-shared-apps/mip-shared-apps.yaml deleted file mode 100644 index 818e768..0000000 --- a/projects/static/mip-shared-apps/mip-shared-apps.yaml +++ /dev/null @@ -1,91 +0,0 @@ ---- -apiVersion: argoproj.io/v1alpha1 -kind: AppProject -metadata: - name: mip-argo-project-shared-apps - namespace: argocd-mip-team -spec: - description: Shared applications like exareme2 and mip-stack - sourceRepos: - - https://github.com/Medical-Informatics-Platform/mip-infra.git - - https://github.com/madgik/exareme2 - - https://github.com/Medical-Informatics-Platform/mip - destinations: - - namespace: federation-* - server: https://kubernetes.default.svc - clusterResourceWhitelist: [] - namespaceResourceWhitelist: - - group: argoproj.io - kind: Application - - group: apps - kind: Deployment - - group: apps - kind: StatefulSet - - group: apps - kind: DaemonSet - - group: apps - kind: ReplicaSet - - group: '' - kind: Service - - group: '' - kind: ConfigMap - - group: '' - kind: Secret - - group: '' - kind: PersistentVolumeClaim - - group: '' - kind: ServiceAccount - - group: '' - kind: Pod - - group: rbac.authorization.k8s.io - kind: Role - - group: rbac.authorization.k8s.io - kind: RoleBinding - - group: networking.k8s.io - kind: Ingress - - group: networking.k8s.io - kind: NetworkPolicy - - group: batch - kind: Job - - group: batch - kind: CronJob - # Explicitly blacklist sensitive resources to be future proof - clusterResourceBlacklist: - - group: rbac.authorization.k8s.io - kind: ClusterRole - - group: rbac.authorization.k8s.io - kind: ClusterRoleBinding - - group: admissionregistration.k8s.io - kind: ValidatingWebhookConfiguration - - group: admissionregistration.k8s.io - kind: MutatingWebhookConfiguration - - group: apiextensions.k8s.io - kind: CustomResourceDefinition - syncWindows: - - kind: allow - schedule: '* * * * *' - duration: 24h - applications: ['*'] - roles: - - name: shared-apps-admin - description: Full access to shared applications - policies: - - p, proj:mip-argo-project-shared-apps:shared-apps-admin, applications, get, - mip-argo-project-shared-apps/*, allow - - p, proj:mip-argo-project-shared-apps:shared-apps-admin, applications, create, - mip-argo-project-shared-apps/*, allow - - p, proj:mip-argo-project-shared-apps:shared-apps-admin, applications, update, - mip-argo-project-shared-apps/*, allow - - p, proj:mip-argo-project-shared-apps:shared-apps-admin, applications, delete, - mip-argo-project-shared-apps/*, allow - - p, proj:mip-argo-project-shared-apps:shared-apps-admin, applications, sync, - mip-argo-project-shared-apps/*, allow - groups: [argocd-admins] - - name: shared-apps-developer - description: Limited access to shared applications - policies: - - p, proj:mip-argo-project-shared-apps:shared-apps-developer, applications, - sync, mip-argo-project-shared-apps/*, allow - - p, proj:mip-argo-project-shared-apps:shared-apps-developer, applications, - get, mip-argo-project-shared-apps/*, allow - groups: [argocd-developers] diff --git a/projects/static/submariner/submariner-project.yaml b/projects/static/submariner/submariner-project.yaml index 3cd39cd..3d480d1 100644 --- a/projects/static/submariner/submariner-project.yaml +++ b/projects/static/submariner/submariner-project.yaml @@ -1,4 +1,11 @@ --- +# rbac-lint: ignore +# Submariner ships namespaced Role/RoleBinding for the broker and operator +# (see common/submariner/{broker,operator}/kustomization.yaml). Those RBAC +# resources are scoped to the submariner-k8s-broker and submariner-operator +# namespaces only, so this project legitimately needs Role/RoleBinding in +# its namespaceResourceWhitelist and the global blacklist drift-check is +# explicitly opted out for this file. apiVersion: argoproj.io/v1alpha1 kind: AppProject metadata: From 0ed4f32f95edb529f4596ebc1c2c88bfb004673e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 26 May 2026 13:37:57 +0000 Subject: [PATCH 2/3] =?UTF-8?q?style:=20auto-fix=20YAML=20linting=20issues?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/argo-projects.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/argo-projects.yaml b/base/argo-projects.yaml index 0f30072..f052084 100644 --- a/base/argo-projects.yaml +++ b/base/argo-projects.yaml @@ -9,8 +9,8 @@ metadata: app.kubernetes.io/managed-by: argocd argocd.instance: mip-team annotations: - argocd.argoproj.io/note: 'Manages static AppProjects: mip-federations, - mip-common, mip-monitoring, mip-security, submariner' + argocd.argoproj.io/note: 'Manages static AppProjects: mip-federations, mip-common, + mip-monitoring, mip-security, submariner' spec: generators: - list: From a9eadc2e9f3a4b852ca701cddf6acc67d08aebd6 Mon Sep 17 00:00:00 2001 From: Julien D <150942337+jdaln@users.noreply.github.com> Date: Tue, 26 May 2026 15:56:08 +0000 Subject: [PATCH 3/3] fix(pre-commit): enhance RBAC checks for AppProjects to ensure proper role and binding validation --- .githooks/pre-commit | 60 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index aee4db5..6d74b82 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -21,21 +21,61 @@ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) # --------------------------------------------------------------------------- RBAC_DRIFT=0 RBAC_PROBLEMS=() -for PROJ_FILE in projects/static/*/*.yaml; do - [[ -f "$PROJ_FILE" ]] || continue - grep -q '^kind: AppProject' "$PROJ_FILE" || continue - grep -q '^# rbac-lint: ignore' "$PROJ_FILE" && continue +while IFS= read -r PROJ_FILE; do + [[ -n "$PROJ_FILE" ]] || continue + PROJ_CONTENT=$(git show ":0:$PROJ_FILE" 2>/dev/null || true) + [[ -n "$PROJ_CONTENT" ]] || continue + grep -q '^kind: AppProject' <<< "$PROJ_CONTENT" || continue + grep -q '^# rbac-lint: ignore' <<< "$PROJ_CONTENT" && continue if ! awk ' + function clean(value) { + sub(/[[:space:]]+#.*$/, "", value) + sub(/^[[:space:]]+/, "", value) + sub(/[[:space:]]+$/, "", value) + return value + } + function commit_item() { + if (current_group == "rbac.authorization.k8s.io" && current_kind == "Role") { + has_role = 1 + } + if (current_group == "rbac.authorization.k8s.io" && current_kind == "RoleBinding") { + has_rb = 1 + } + current_group = "" + current_kind = "" + } /^ namespaceResourceBlacklist:/ { in_block = 1; next } - in_block && /^ [A-Za-z]/ { in_block = 0 } - in_block && /kind: Role$/ { has_role = 1 } - in_block && /kind: RoleBinding$/ { has_rb = 1 } - END { exit !(has_role && has_rb) } - ' "$PROJ_FILE"; then + in_block && /^ [A-Za-z]/ { + commit_item() + in_block = 0 + next + } + in_block && /^ - / { + commit_item() + } + in_block && /group:/ { + current_group = $0 + sub(/^.*group:[[:space:]]*/, "", current_group) + current_group = clean(current_group) + next + } + in_block && /kind:/ { + current_kind = $0 + sub(/^.*kind:[[:space:]]*/, "", current_kind) + current_kind = clean(current_kind) + next + } + END { + if (in_block) { + commit_item() + } + exit !(has_role && has_rb) + } + ' <<< "$PROJ_CONTENT"; then RBAC_DRIFT=1 RBAC_PROBLEMS+=("$PROJ_FILE") fi -done +done < <(git ls-files -- 'projects/static/*/*.yaml') if [[ "$RBAC_DRIFT" -ne 0 ]]; then echo "---------------------------------------------------------------------------------"