Skip to content

Restrict Hackbot triggers to authorized user with editbugs permissions - #6444

Open
ayoubdiourin7 wants to merge 5 commits into
mozilla:masterfrom
ayoubdiourin7:feat/hackbot-editbugs-auth-clean
Open

Restrict Hackbot triggers to authorized user with editbugs permissions#6444
ayoubdiourin7 wants to merge 5 commits into
mozilla:masterfrom
ayoubdiourin7:feat/hackbot-editbugs-auth-clean

Conversation

@ayoubdiourin7

@ayoubdiourin7 ayoubdiourin7 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Changes

  • Check the author of each @hackbot comment.
  • Process comments only from users authorized to edit revisions.
  • Ignore comments from unauthorized users before creating a Hackbot run.
  • Add test coverage for authorized, unauthorized

Resolves #6423

@ayoubdiourin7
ayoubdiourin7 requested a review from a team as a code owner July 31, 2026 14:24
Comment thread services/hackbot-api/app/phabricator_webhook.py Outdated
Comment thread services/hackbot-api/app/phabricator_webhook.py Outdated
Comment thread services/hackbot-api/app/phabricator_webhook.py
@ayoubdiourin7
ayoubdiourin7 force-pushed the feat/hackbot-editbugs-auth-clean branch from 28a08b1 to 1f5820a Compare August 1, 2026 12:14
Comment thread libs/phabricator-client/phabricator_client/client.py Outdated
Comment on lines +28 to +37
EDITBUGS_GROUP_PHID = "PHID-PROJ-njo5uuqyyq3oijbkhy55"
_MEMBERSHIP_CACHE_TTL_SECONDS = 60
_MISSING_MEMBER_REFRESH_COOLDOWN_SECONDS = 30

_editbugs_members_cache: TTLCache[str, frozenset[str]] = TTLCache(
maxsize=1,
ttl=_MEMBERSHIP_CACHE_TTL_SECONDS,
)
_editbugs_members_lock = asyncio.Lock()
_last_editbugs_members_refresh = 0.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can grow to be a bit ugly. I would encapsulate this in a class that exposes a simple method to check if the user is authorized or not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c755905

missing_member_refresh_cooldown_seconds
)

async def is_authorized(self, client: PhabricatorClient, author_phid: str) -> bool:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would pass the client to the constructor instead of here.


def __init__(
self,
group_phid: str,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
group_phid: str,
authorized_group_phid: str,


# Members of this project are authorized to trigger Hackbot.
AUTHORIZED_GROUP_PHID = "PHID-PROJ-njo5uuqyyq3oijbkhy55" # bmo-editbugs-team
phabricator_authorizer = PhabricatorAuthorizer(AUTHORIZED_GROUP_PHID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using it as a singleton here, I would pass it as a dependency to the FastAPI route. The dependency injection with FastAPI makes it easier to avoid singletons.


@dataclass(frozen=True)
class HackbotMention:
raw: str

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The name raw is not clear, I would use something like comment, text, or content.

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.

Control who can trigger Hackbot from a Phabricator comment

2 participants