我将 api 密钥推送到 github 中的 public 存储库

I pushed api key to public repository in github

是的,我做到了。 令我惊讶的是,机器人正在扫描 github 以搜索免费的 api 密钥。我能理解,但奇怪的是。他们能够激活不同的 api(计算引擎)主机 3 个虚拟机并用它来挖掘加密货币。 一个问题是,他们可以托管虚拟机并使用不同的 api 不是漏洞吗? 我不得不关闭整个项目。

取决于分配给受感染的角色 service-account - 攻击者可以做任何事情或什么都不做。

有一些基本的“best practices" regarding keys and service accounts应该对你有用。

通常(如果可能)使用不同的服务帐户来管理 VM 的 or/and 每周或每周两次轮换密钥(就像 Google-managed 那样)并避免放置任何 API 密钥进入 can/will 与 public 同步的存储库 :)

是 - 听起来很傻,但 slip-up 确实发生了,这将使未经授权的访问方式不太可能或不可能。

此外,“least privilege”规则可能值得一试 - 那时泄露的凭据将没有多大用处。

请注意,自 2021 年 8 月起:

Secret scanning org-level REST API

GitHub Advanced Security customers can now retrieve private repository secret scanning results at the organization level via the GitHub REST API.
This new endpoint, in beta, supplements the existing repository-level endpoint.

API是:GET /organizations/:organization_id/secret-scanning/alerts.
参见“About secret scanning for private repositories

在您的情况下,查询新的(仍处于测试阶段)API 端点可能是一个很好的做法,在攻击者有时间造成巨大破坏之前收到警报.