Skip to content

feat: add flexible bot access control with allowed_bots option - #117

Merged
ashwin-ant merged 9 commits into
anthropics:mainfrom
yuku-contrib:support-bot-user
Aug 8, 2025
Merged

ashwin-ant merged 9 commits into
anthropics:mainfrom
yuku-contrib:support-bot-user

Conversation

@yukukotani

@yukukotani yukukotani commented Jun 3, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Changes

  1. New allowed_bots input parameter:

    • Empty string (default): no bots allowed - secure by default
    • "*": allow all bots
    • "dependabot,renovate": allow specific bots only (comma-separated)
    • Case-insensitive bot name matching
  2. Enhanced bot permission handling:

    • GitHub App bot users (ending with [bot]) automatically granted write permissions
    • Modified checkHumanActor to accept and process allowedBots parameter
    • Improved error messages for bot access denials
  3. Comprehensive test coverage:

    • Added test/actor.test.ts with full coverage of bot scenarios
    • Enhanced permission tests for bot users
    • All scenarios tested: human users, specific bots, wildcard, blocked bots

Usage Examples

# Allow specific trusted bots (recommended)
- uses: anthropics/claude-code-action@main
  with:
    allowed_bots: "dependabot,renovate"

# Allow all bots (use with caution in trusted environments)
- uses: anthropics/claude-code-action@main
  with:
    allowed_bots: "*"

# No bots allowed (default, most secure)
- uses: anthropics/claude-code-action@main
  # No allowed_bots parameter needed

Use Cases

  • Dependabot integration: Allow Dependabot to trigger Claude for dependency updates
  • Renovate workflows: Enable Renovate bot to request code reviews
  • GitHub Apps: Support custom GitHub Apps in organization workflows
  • Trusted automation: Selective bot access in private/internal repositories

Security Considerations

  • Secure by default: no bots allowed unless explicitly configured
  • Granular control: specify exact bot usernames rather than blanket approval
  • Clear error messages guide users toward proper configuration

Test Plan

  • Human users continue to work without changes
  • Bots are blocked by default (empty allowed_bots)
  • Specific bots work when explicitly allowed
  • Wildcard "*" allows all bots
  • Case-insensitive bot name matching works
  • GitHub App bot users get automatic write permissions
  • Comprehensive error messages for blocked bots
  • All existing functionality preserved

🤖 Generated with Claude Code

@yukukotani yukukotani changed the title Add allow_bot_users option to prevent prompt injection attacks Add allow_bot_users option for flexible workflow automation Jun 3, 2025
@yukukotani

Copy link
Copy Markdown
Contributor Author

@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.

@sshh12

sshh12 commented Jul 2, 2025

Copy link
Copy Markdown

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.

@ashwin-ant

Copy link
Copy Markdown
Collaborator

@sshh12 I left a suggestion on @tomoish's PR here: #194. I think if we can make it a bit more configurable in the way I described this should be fine.

lroolle pushed a commit to thevibeworks/claude-code-docs that referenced this pull request Jul 3, 2025
- 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]>
lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Jul 3, 2025
- 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
lroolle pushed a commit to thevibeworks/claude-code-docs that referenced this pull request Jul 3, 2025
- 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]>
lroolle pushed a commit to thevibeworks/claude-code-docs that referenced this pull request Jul 3, 2025
- 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]>
@yukukotani yukukotani changed the title Add allow_bot_users option for flexible workflow automation Replace allow_bot_users with flexible allowed_bots option Jul 5, 2025
@yukukotani yukukotani changed the title Replace allow_bot_users with flexible allowed_bots option feat: add flexible bot access control with allowed_bots option Jul 5, 2025
@yukukotani

yukukotani commented Jul 5, 2025 •

Copy link
Copy Markdown
Contributor Author

@ashwin-ant Thanks for reviewing! I've updated this PR based on your feedback!

Comment on lines +20 to +24
// Check if the actor is a GitHub App (bot user)
if (actor.endsWith("[bot]")) {
core.info(`Actor is a GitHub App: ${actor}`);
return true;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think we should still check to see if it has write access.

@yukukotani yukukotani Jul 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To double-check, I think we should check contents permission to be write.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd prefer to check for the same permission level if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

API: https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#list-app-installations-for-an-organization

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that's fair. I thought the same endpoint would work but it seems it doesn't.

@ashwin-ant ashwin-ant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very excited about this! Left some comments.

Comment thread src/entrypoints/prepare.ts Outdated
Comment on lines +51 to +52
const allowedBots = process.env.ALLOWED_BOTS || "";
await checkHumanActor(octokit.rest, context, allowedBots);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yukukotani and others added 3 commits July 21, 2025 11:06
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]>
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]>
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
yukukotani requested a review from ashwin-ant July 22, 2025 08:56
@km-anthropic

Copy link
Copy Markdown
Collaborator

@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.

@yukukotani

Copy link
Copy Markdown
Contributor Author

@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.

@km-anthropic

Copy link
Copy Markdown
Collaborator

@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.

@cansin

cansin commented Aug 4, 2025

Copy link
Copy Markdown

Without realizing this PR existed I have created #388 and #387. I am trying to handle more security cases there, but that also made the changeset larger (with more tests). I wanted to let this thread know as well.

@ashwin-ant ashwin-ant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

Comment on lines +20 to +24
// Check if the actor is a GitHub App (bot user)
if (actor.endsWith("[bot]")) {
core.info(`Actor is a GitHub App: ${actor}`);
return true;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd prefer to check for the same permission level if possible.

lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Aug 5, 2025
- 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
yukukotani requested a review from ashwin-ant August 5, 2025 10:28
lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Aug 6, 2025
- 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
@ashwin-ant

Copy link
Copy Markdown
Collaborator

@yukukotani I think this looks solid. Can you fix the CI errors (just prettier and typecheck). You can run bun run format and bun typecheck locally. Also you have some conflicts with the readme. Otherwise I'm excited to get this in!

@yukukotani

Copy link
Copy Markdown
Contributor Author

@ashwin-ant Done!

@paaloeye paaloeye left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/usage.md Outdated
# additional_permissions: |
# actions: read
# Optional: allow bot users to trigger the action
# allowed_bots: "dependabot,renovate"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one should be dependabot[bot],renovate[bot]

Comment thread test/actor.test.ts Outdated
test("should throw error for bot actor when not allowed", async () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "test-bot";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test[bot] to follow GitHub convention?

Comment thread test/actor.test.ts
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.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread test/actor.test.ts Outdated
test("should pass for bot actor when all bots allowed", async () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "test-bot";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread test/actor.test.ts Outdated
test("should pass for specific bot when in allowed list", async () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "dependabot";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependabot[bot]

Comment thread test/actor.test.ts
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "dependabot";
context.inputs.allowedBots = "dependabot,renovate";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependabot[bot],renovate[bot]

Comment thread test/actor.test.ts Outdated
test("should throw error for bot not in allowed list", async () => {
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "other-bot";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread test/actor.test.ts
const mockOctokit = createMockOctokit("Bot");
const context = createMockContext();
context.actor = "other-bot";
context.inputs.allowedBots = "dependabot,renovate";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread test/actor.test.ts
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.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other[bot]

yukukotani and others added 2 commits August 6, 2025 14:19
- 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

Copy link
Copy Markdown
Contributor Author

@paaloeye Good catch, thanks! I've applied your suggestion 28cc702 and updated the code to accept the allow_bots option whether or not the bot name ends with [bot] bd0b40e.

@ashwin-ant

Copy link
Copy Markdown
Collaborator

@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).

@cansin

cansin commented Aug 6, 2025

Copy link
Copy Markdown

@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.

@ashwin-ant

Copy link
Copy Markdown
Collaborator

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 ashwin-ant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this out again, works great!

@ashwin-ant

Copy link
Copy Markdown
Collaborator

Thanks for iterating on this @yukukotani!

@ashwin-ant
ashwin-ant merged commit fec554f into anthropics:main Aug 8, 2025
@yukukotani

Copy link
Copy Markdown
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Support triggering @claude from bot users

7 participants