Repository navigation
feat: add flexible bot access control with allowed_bots option - #117
Conversation
|
@ashwin-ant Just to confirm - is there anything else I should do to get a review, such as starting a discussion on the issue? No rush at all, I just wanted to make sure. |
|
Hey @ashwin-ant wanted to bump on behalf of yukukotani, anything blocking this from being merged? We'd love to hook up the CC GHA via some GH bot automations. |
- Update to actions/create-github-app-token@beta for consistency - Add TODO comment for future allow_bot_users parameter (PR #117) - Keep current conditional token logic until official fix is merged References: anthropics/claude-code-action#117 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add allow_bot_users input parameter to action.yml - Modify checkHumanActor to accept allowBotUsers parameter - Skip human actor validation when bot users are allowed - Enables claude-yolo[bot] and other GitHub Apps to trigger the action Based on anthropics#117
- Update to actions/create-github-app-token@beta for consistency - Add TODO comment for future allow_bot_users parameter (PR #117) - Keep current conditional token logic until official fix is merged References: anthropics/claude-code-action#117 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Update to actions/create-github-app-token@beta for consistency - Add TODO comment for future allow_bot_users parameter (PR #117) - Keep current conditional token logic until official fix is merged References: anthropics/claude-code-action#117 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
2c1dc27 to
84f4d9b
Compare
|
@ashwin-ant Thanks for reviewing! I've updated this PR based on your feedback! |
84f4d9b to
7367515
Compare
| // Check if the actor is a GitHub App (bot user) | ||
| if (actor.endsWith("[bot]")) { | ||
| core.info(`Actor is a GitHub App: ${actor}`); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Hm, I think we should still check to see if it has write access.
There was a problem hiding this comment.
@ashwin-ant
Unlike human actors, who can create PRs or issues from a fork without write access, we can treat bot actors as having write access if they can trigger claude-code-action by creating PRs or issues. So IMO we can skip the check here, but double-checking also makes sense. How do you think?
There was a problem hiding this comment.
To double-check, I think we should check contents permission to be write.
There was a problem hiding this comment.
Yeah I'd prefer to check for the same permission level if possible.
There was a problem hiding this comment.
@ashwin-ant Sorry, but it seems we need to grant admin:read scope permission to the Claude App in order to check the bot actor’s permission. I feel that’s a bit too much to ask.
There was a problem hiding this comment.
I see, that's fair. I thought the same endpoint would work but it seems it doesn't.
ashwin-ant
left a comment
There was a problem hiding this comment.
Very excited about this! Left some comments.
| const allowedBots = process.env.ALLOWED_BOTS || ""; | ||
| await checkHumanActor(octokit.rest, context, allowedBots); |
There was a problem hiding this comment.
Instead of adding another param here, let's move allowedBots into context to match how we manage other inputs: https://github.com/anthropics/claude-code-action/blob/main/src/github/context.ts#L29-L42
GitHub Apps (users ending with [bot]) now bypass permission checks as they have their own authorization mechanism. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add allow_bot_users input parameter (default: false) - Modify checkHumanActor to optionally allow bot users - Add comprehensive tests for bot user handling - Improve security by blocking bot users by default This change prevents potential prompt injection attacks from bot users while providing flexibility for trusted bot integrations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
e8555d5 to
f9b2243
Compare
Move allowedBots from function parameter to context.inputs to maintain consistency with other input handling throughout the codebase. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
f9b2243 to
bf34e22
Compare
Add documentation for the new allowed_bots parameter that enables bot users to trigger Claude actions with granular control. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@yukukotani this functionality should now be solved w/ Agent mode (example here). You can setup an agent automation (as a workflow dispatch) and bot actors should be able to trigger it. |
|
@km-anthropic Hmm, the agent mode seems cool, but it might be too minimum for me. It have no mcp servers while I want claude-code-action to comment to bot PRs in the same way as the tag mode. |
|
@yukukotani Thanks! I added MCPs to agent mode in #379 -- I think we'd want to bring the right functionality to the modes as opposed to having the to reformat the individual ones themselves. @ashwin-ant feel free to weigh in here. |
ashwin-ant
left a comment
There was a problem hiding this comment.
@yukukotani apologies for the delay here, this PR is looking solid. I'd like to still verify that the bot has write access on the repo in the same way that we verify human actors. If we can get that in, this should be good to go!
| // Check if the actor is a GitHub App (bot user) | ||
| if (actor.endsWith("[bot]")) { | ||
| core.info(`Actor is a GitHub App: ${actor}`); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Yeah I'd prefer to check for the same permission level if possible.
- Add allow_bot_actor parameter to enable GitHub bots to trigger Claude Code Action - Implement robust bot write permission validation - Add test coverage for bot scenarios - Update documentation with security considerations This enables automated workflows like documentation updates, CI-triggered code reviews, and scheduled maintenance while maintaining security through explicit opt-in and proper permission validation. Relevant works: anthropics#388 anthropics#280 anthropics#194 anthropics#117
- Add allow_bot_actor parameter to enable GitHub bots to trigger Claude Code Action - Implement robust bot write permission validation - Add test coverage for bot scenarios - Update documentation with security considerations This enables automated workflows like documentation updates, CI-triggered code reviews, and scheduled maintenance while maintaining security through explicit opt-in and proper permission validation. Relevant works: anthropics#388 anthropics#280 anthropics#194 anthropics#117
|
@yukukotani I think this looks solid. Can you fix the CI errors (just |
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@ashwin-ant Done! |
paaloeye
left a comment
There was a problem hiding this comment.
Few minor changes so the PR follows GitHub's name convention for bot users.
| # additional_permissions: | | ||
| # actions: read | ||
| # Optional: allow bot users to trigger the action | ||
| # allowed_bots: "dependabot,renovate" |
There was a problem hiding this comment.
I think this one should be dependabot[bot],renovate[bot]
| test("should throw error for bot actor when not allowed", async () => { | ||
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "test-bot"; |
There was a problem hiding this comment.
test[bot] to follow GitHub convention?
| context.inputs.allowedBots = ""; | ||
|
|
||
| await expect(checkHumanActor(mockOctokit, context)).rejects.toThrow( | ||
| "Workflow initiated by non-human actor: test-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.", |
| test("should pass for bot actor when all bots allowed", async () => { | ||
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "test-bot"; |
| test("should pass for specific bot when in allowed list", async () => { | ||
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "dependabot"; |
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "dependabot"; | ||
| context.inputs.allowedBots = "dependabot,renovate"; |
| test("should throw error for bot not in allowed list", async () => { | ||
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "other-bot"; |
| const mockOctokit = createMockOctokit("Bot"); | ||
| const context = createMockContext(); | ||
| context.actor = "other-bot"; | ||
| context.inputs.allowedBots = "dependabot,renovate"; |
| context.inputs.allowedBots = "dependabot,renovate"; | ||
|
|
||
| await expect(checkHumanActor(mockOctokit, context)).rejects.toThrow( | ||
| "Workflow initiated by non-human actor: other-bot (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.", |
- Update test cases to use correct bot actor names with [bot] suffix - Update documentation example to show correct bot name format - Align with GitHub's actual bot naming convention 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Strip [bot] suffix from both actor names and allowed bot list for comparison - Allow both "dependabot" and "dependabot[bot]" formats in allowed_bots input - Display normalized bot names in error messages for consistency - Add comprehensive test coverage for both naming formats 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@yukukotani have you tested this? I'm getting an error when trying to retrieve the Claude token via OIDC (we'd need to update the checks on our backend). |
In case this PR goes red, #388 is green with a working demo. I'd be happy to reopen it. |
|
I think there's a path forward here, working on this now. But wanted to confirm with @yukukotani that this is working when not using the default claude token. |
ashwin-ant
left a comment
There was a problem hiding this comment.
Tested this out again, works great!
|
Thanks for iterating on this @yukukotani! |
|
@ashwin-ant Apologies for the late reply, and thank you so much for your patience! Yes, I tested this with OIDC token and it works on my end. |
Summary
allowed_botsinput parameter for granular bot access control[bot])Changes
New
allowed_botsinput parameter:"*": allow all bots"dependabot,renovate": allow specific bots only (comma-separated)Enhanced bot permission handling:
[bot]) automatically granted write permissionscheckHumanActorto accept and processallowedBotsparameterComprehensive test coverage:
test/actor.test.tswith full coverage of bot scenariosUsage Examples
Use Cases
Security Considerations
Test Plan
allowed_bots)"*"allows all bots🤖 Generated with Claude Code