For those that don’t know, I run a self hosted GIT server for all of my personal projects. While there are a lot of advantages to this set up, there are also some drawbacks, namely the fact that it’s not as easy for people to colloborate on my projects. For this reason (and probably some of my own bravery/stupidity) I enable option for people to register accounts.
What’s interesting but not surprising is the volume of spam accounts that get created. I am not exactly sure what they are used for but I imagine it has something to do with SEO purposes. The other day I was looking for a quick way to clean up all of the spam accounts and put together this one-liner:
for i in $(curl "https://git.hackanooga.com/api/v1/admin/users?access_token=$GITEA_API_TOKEN" -H 'accept: application/json' | jq -r '.[] | select(.is_admin==false) | .username'); do curl -X DELETE "https://git.hackanooga.com/api/v1/admin/users/$i?purge=true&access_token=$GITEA_API_TOKEN" -H 'accept: application/json'; doneTheir’s nothing revolutionary here but I wanted a place to stash this script for the next time I need it. Basically we are calling the Gitea API and getting a list of users, piping that through jq filtering out the non-admin users and extracting just their usernames. Then we loop over the list of usernames and call the DELETE users endpoint. ?purge=true tells the API to force remove accounts even if they have repositories created.
In my case all of these spam accounts create a repository so I need to pass this flag to fully remove them. Admitedly dangerous, maybe at some point I will add better filtering but it works well enough for now.
Continue the conversation on LinkedIn ↗