Open frozen425 opened 1 month ago
We have a Policy Check: "Ensure branch deletions are denied" / github-benchmark-level-1 that fails for Github Repos that should be passing. At first I thought it was the mql in the Check. It appears that protectionRules() is returning nil or not being called
i just tested it and it seems to work. You need to have admin access to the repo to get the protection rules according to a comment in the code. If you run with debug logging, it might say something like note: branch protection can only be accessed by admin users
:
cnquery> github.repository.branches.where(isDefault == true) { * }
DBG starting query execution qrid=iLo+6h9iBuQ=
DBG performing request method=GET url=https://api.github.com/repos/mondoohq/cnspec
DBG oC+yDBQMU1QQAnaCGTD8QAVh0bUOqo8oJENRvwpBjEcqQ4Nfj2KitslRGbh+JSC+DpPFvUm36vSh+d5yV8Zh6g== finished
DBG graph has received all datapoints
DBG finished query execution qrid=iLo+6h9iBuQ=
github.repository.branches.where: [
0: {
protectionRules: github.branchprotection id="cnspec/main"
isProtected: true
headCommit: github.commit sha="52139cdd194287a7950dc70168e47792425f91a6"
owner: github.user login="mondoohq" name="Mondoo Inc" email="hello@mondoo.com" company=""
isDefault: true
name: "main"
repoName: "cnspec"
headCommitSha: "52139cdd194287a7950dc70168e47792425f91a6"
}
]
if the two tokens are the same, there could be something else going on. Maybe the debug output will tell us that
You were correct. The curl token was different from the cnspec token. I've updated my notes re: fine-grained PATs and the need for the Admin Read-Only permission.
And for classic PATs, I needed to make sure the token had repo:public_repo, since the repo in question is public. I'll test with a private repo later.
In any case, the docs are incorrect re: configuration of the PAT. docs
Thank you, @frozen425. I'll update the doc.
Docs updated. Release is going out now. Thanks again!
The Github Repo Branch Protection rules are included in the response from the Github API: