Skip to content

Fix group pruning script to remove all inactive users from groups synced from IdPs - #114

Merged
simu merged 2 commits into
masterfrom
fix/group-prune
May 21, 2026
Merged

simu merged 2 commits into
masterfrom
fix/group-prune

Conversation

@simu

@simu simu commented May 21, 2026

Copy link
Copy Markdown
Member

The previous iteration of the script removed inactive users from all groups on the cluster, which generated unnecessary ArgoCD reconciles for groups managed by some ArgoCD and additionally could incorrectly remove users from manually managed groups.

Additionally, because the previous script's outer loop only iterated over all User resource on the cluster it could incorrectly leave some inactive users in groups in cases where the inactive user's User resource was deleted at some point in the past without removing the corresponding entries from any groups.

The refactored script processes all OpenShift gropus which have annotation oauth.openshift.io/generated=true. It iterates through .users of each of those groups and removes any users who don't have an active oauthaccesstoken on the cluster.

Optionally, groups synced from certain IdPs can be skipped by adding the OpenShift IdP identifier (i.e. value of spec.identityProviders[*].name in the oauth.config.openshift.io/cluster resource) to the environment variable ${EXCLUDED_IDP}. The script expects that this variable is either empty or a valid JSON array.

Note that the script uses kubectl get -ojson | jq -r '...' | while read to process the list of groups and users in each group line by line. Doing so ensures that groups and users which have a space in their .metadata.name are processed correctly.

The script can be tested without actually making any changes by setting environment variable DRY_RUN to a non-empty string. To test the script you must be logged in to the target cluster and you must enable system:admin impersonation.

The second commit in the PR exposes the ability to skip groups synced from certain IdPs by introducing a new component parameter groupPrune.excluded_idps which is passed to the script as environment variable EXCLUDED_IDP.

Fixes #111

Checklist

  • The PR has a meaningful title. It will be used to auto-generate the
    changelog.
    The PR has a meaningful description that sums up the change. It will be
    linked in the changelog.
  • PR contains a single logical change (to build a better changelog).
  • Update the documentation.
  • Categorize the PR by adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency
    as they show up in the changelog.
  • Link this PR to related issues or PRs.

@simu
simu requested a review from a team May 21, 2026 13:38
@simu simu added bug Something isn't working bump:patch labels May 21, 2026
@github-actions

github-actions Bot commented May 21, 2026 •

Copy link
Copy Markdown

🚀 This PR has been released as v4.2.2

Triggering workflows Release

🛠️ Auto tagging enabled with label bump:patch

@appuio appuio deleted a comment from github-actions Bot May 21, 2026
simu added 2 commits May 21, 2026 15:48
…from an IdP

The previous iteration of the script removed inactive users from all
groups on the cluster, which generated unnecessary ArgoCD reconciles for
groups managed by some ArgoCD and additionally could incorrectly remove
users from manually managed groups.

Additionally, because the previous script's outer loop only iterated
over all `User` resource on the cluster it could incorrectly leave some
inactive users in groups in cases where the inactive user's `User`
resource was deleted at some point in the past without removing the
corresponding entries from any groups.

The refactored script processes all OpenShift gropus which have
annotation `oauth.openshift.io/generated=true`. It iterates through
`.users` of each of those groups and removes any users who don't have an
active oauthaccesstoken on the cluster.

Optionally, groups synced from certain IdPs can be skipped by adding the
OpenShift IdP identifier (i.e. value of `spec.identityProviders[*].name`
in the `oauth.config.openshift.io/cluster` resource) to the environment
variable `${EXCLUDED_IDP}`. The script expects that this variable is
either empty or a valid JSON array.

Note that the script uses `kubectl get -ojson | jq -r '...' | while
read` to process the list of groups and users in each group line by
line. Doing so ensures that groups and users which have a space in their
`.metadata.name` are processed correctly.

The script can be tested without actually making any changes by setting
environment variable `DRY_RUN` to a non-empty string. To test the script
you must be logged in to the target cluster and you must enable
system:admin impersonation.
This allows users to configure the prune cronjob to skip groups synced
from certain IdPs.
@simu
simu force-pushed the fix/group-prune branch from 709f8e1 to dfaee66 Compare May 21, 2026 13:48

@bastjan bastjan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

📿

@simu
simu merged commit 1431d5f into master May 21, 2026
9 checks passed
@simu
simu deleted the fix/group-prune branch May 21, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working bump:patch

Development

Successfully merging this pull request may close these issues.

3 participants