Skip to content
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
90 changes: 89 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,95 @@ 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=()
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]/ {
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 < <(git ls-files -- 'projects/static/*/*.yaml')

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
Expand Down
6 changes: 2 additions & 4 deletions base/argo-projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ metadata:
app.kubernetes.io/managed-by: argocd
argocd.instance: mip-team
annotations:
argocd.argoproj.io/note: 'Manages static AppProjects: mip-federations, mip-shared-apps,
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:
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
Expand Down
10 changes: 6 additions & 4 deletions projects/static/mip-common/mip-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 5 additions & 34 deletions projects/static/mip-federations/mip-federations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: '* * * * *'
Expand Down
6 changes: 6 additions & 0 deletions projects/static/mip-security/mip-security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '* * * * *'
Expand Down
4 changes: 0 additions & 4 deletions projects/static/mip-shared-apps/kustomization.yaml

This file was deleted.

91 changes: 0 additions & 91 deletions projects/static/mip-shared-apps/mip-shared-apps.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions projects/static/submariner/submariner-project.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading