I tried every solution posted, in the end none of them worked for my particular case. However, I want to extend my gratitude to the users who pointed me in the direction of the ownership being the real issue regarding multiple accounts, not the mode.
I'm posting this answer for anyone else with a similar setup (M1 + two accounts + /opt/homebrew/share).
Here is my setup:
I have an M1, running macOS Monterey 12.0.1, using Homebrew.
I have two accounts, one admin and one regular user (required split for work).
I only had the insecure directories issue on the regular user, both users use the same homebrew setup, with the following directories and files being affected by the issue:
/opt/homebrew/completions/zsh/_brew
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/share/zsh/site-functions/_brew_services
/opt/homebrew/share/zsh/site-functions/_cargo
/opt/homebrew/share/zsh/site-functions/_gh
/opt/homebrew/share/zsh/site-functions/_git
/opt/homebrew/share/zsh/site-functions/_j
/opt/homebrew/share/zsh/site-functions/_lf
/opt/homebrew/share/zsh/site-functions/_task
/opt/homebrew/share/zsh/site-functions/_tldr
/opt/homebrew/share/zsh/site-functions/_vifm
Changing the mode did nothing, in the end what fixed the issues was changing the ownership of every problem file and dir to root:admin, like so:
sudo chown root:admin /opt/homebrew/share/zsh/site-functions/*
Originally, before the issue presented itself, my admin user owned everything, ownership therefore looked like this: usr:admin
This is what the site-functions dir looks like now, no issues:
lrwxr-xr-x 1 root admin 30 Jul 19 19:41 _brew ->../../../completions/zsh/_brew
lrwxr-xr-x 1 root admin 79 Aug 10 20:26 _brew_services -> ../../../Library/Taps/homebrew/homebrew-services/completions/zsh/_brew_services
lrwxr-xr-x 1 root admin 59 Nov 6 16:28 _cargo -> ../../../Cellar/rust/1.56.1/share/zsh/site-functions/_cargo
lrwxr-xr-x 1 root admin 53 Dec 2 23:37 _gh -> ../../../Cellar/gh/2.3.0/share/zsh/site-functions/_gh
lrwxr-xr-x 1 root admin 56 Nov 30 15:21 _git -> ../../../Cellar/git/2.34.1/share/zsh/site-functions/_git
lrwxr-xr-x 1 root admin 61 Oct 13 11:12 _j -> ../../../Cellar/autojump/22.5.3_3/share/zsh/site-functions/_j
lrwxr-xr-x 1 root admin 50 Oct 23 18:52 _lf -> ../../../Cellar/lf/26/share/zsh/site-functions/_lf
lrwxr-xr-x 1 root admin 57 Nov 6 16:28 _task -> ../../../Cellar/task/2.6.1/share/zsh/site-functions/_task
lrwxr-xr-x 1 root admin 57 Nov 18 01:45 _tldr -> ../../../Cellar/tldr/1.4.2/share/zsh/site-functions/_tldr
lrwxr-xr-x 1 root admin 56 Oct 13 11:11 _vifm -> ../../../Cellar/vifm/0.12/share/zsh/site-functions/_vifm
.zshrc
file and put this line at the beginning of the fileZSH_DISABLE_COMPFIX=true
. – Pneumonia