actions/checkoutはデフォルトでシークレットをディスクに保存する
actions/checkout の少なくともv7時点ではデフォルトで GITHUB_TOKEN などのシークレットをディスクへ永続化する。具体的にはsrc/git-source-provider.ts:getSourceで行われていて、実装は次のようになっている。以下に一部抜粋する。
export function getSource(settings: IGitSourceSettings): Promise<void> { if (settings.persistCredentials) { core.startGroup('Persisting credentials for submodules') await authHelper.configureSubmoduleAuth() core.endGroup() }}ここでsrc/git-auth-helper.ts:configureSubmoduleAuthが実際の永続化を行う。
async configureSubmoduleAuth(): Promise<void> { if (this.settings.persistCredentials) { // Get the credentials config file path in RUNNER_TEMP const credentialsConfigPath = this.getCredentialsConfigPath() const containerCredentialsPath = path.posix.join( '/github/runner_temp', path.basename(credentialsConfigPath) ) const configPaths = await this.git.getSubmoduleConfigPaths( this.settings.nestedSubmodules ) ... }}どうしてこんなに雑な実装をしているのか分からないが、永続化する場所が RUNNER_TEMP 以下で固定なので、後続に悪意のあるアクションが実行されてしまうとトークンを読み出されて良くないことが起きる。これを回避するため、必要になるまでは persist-credential を設定しておくほうが良い。
- uses: actions/checkout@v7 with: persist-credentials: falseactions/checkoutでRepository not foundエラーになるも近い話だけど、根本的にGitHub Actionsは設計がザルだと思う。