The cd builtin checks whether your user ID can read a directory, or whether your actual group ID can read a directory, or whether "others" can read a directory, but it doesn't check the other groups your ID may be a member of.
% id
uid=1001(lmc) gid=1001(lmc) groups=1001(lmc),27(sudo),998(vboxsf)
% ls -ld host
drwxrwx--- 1 root vboxsf 640 Sep 16 03:48 host/
% cd host
=> error 1
The
cd
builtin checks whether your user ID can read a directory, or whether your actual group ID can read a directory, or whether "others" can read a directory, but it doesn't check the other groups your ID may be a member of.It looks like you need to check user.User.GroupIds() (https://pkg.go.dev/os/user#User.GroupIds) too/instead.