我有一个API,它是从一个长期运行的github操作中调用的。有一个github令牌,GITHUB_TOKEN
,它可以与请求一起发送到我的API,但是我找不到一种方法来验证令牌来自哪个回购。在操作中设置了环境变量GITHUB_REPOSITORY
,我可以将这些设置到API中,但我不能确定坏的参与者没有使用不同的github操作,只需要注入自己的GITHUB_REPOSITORY
并将其发送到API中。
我试着打电话给https://api.github.com/user
,比如:
curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
https://api.github.com/user
但它的反应是:
{
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
我只能使用错误的回购标记来执行某些github api调用,但其中许多操作都适用于公共github repos。
给定一个GITHUB_TOKEN
,如何在公共和私有回购操作中验证操作令牌来自哪个回购?我宁愿以只读的方式来做这件事。如果我必须这样做,我会用一些愚蠢的书面回购,这只有github-行动的回购可能做,希望之后立即删除我的写作。
发布于 2022-04-15 16:05:15
这不是正式的,可能会改变,但如果您按下collaborators
endpoint,如果您尝试除发布GITHUB_TOKEN
的回购之外的任何回购,则似乎会失败:
curl -vv --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
https://api.github.com/repos/django/django/collaborators?per_page=1
答复:
HTTP/2 403
[...]
{
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/reference/repos#list-repository-collaborators"
}
github支持建议使用https://api.github.com/installation/repositories
,它应该只返回发出令牌的github存储库。
https://stackoverflow.com/questions/71864756
复制相似问题