Skip to content

chore(ci): Use GitHub App token for team membership rather than user PAT #17936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/comment-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ jobs:
|| contains(github.event.comment.body, '/ci-run-k8s')
)
steps:
- name: Generate authentication token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}
- name: Get PR comment author
id: comment
uses: tspascoal/get-user-teams-membership@v2
with:
username: ${{ github.actor }}
team: 'Vector'
GITHUB_TOKEN: ${{ secrets.GH_PAT_ORG }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
Comment on lines +62 to +74
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

A potential future enhancement- we could drop this into a re-usable workflow, and have the token be an output of it, since we do it in a few places.
Could even have an optional parameter to that workflow to do the team membership check, which would populate an output as well, so we wouldn't have to repeat these two job steps throughout.


- name: Validate author membership
if: steps.comment.outputs.isTeamMember == 'false'
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/gardener_open_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: Generate authentication token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}
- uses: tspascoal/get-user-teams-membership@v2
id: checkVectorMember
with:
username: ${{ github.actor }}
team: vector
GITHUB_TOKEN: ${{ secrets.GH_PAT_ORG }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
- uses: actions/[email protected]
if: ${{ steps.checkVectorMember.outputs.isTeamMember == 'false' }}
with:
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/integration-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, '/ci-run-integration') || contains(github.event.comment.body, '/ci-run-all')
steps:
- name: Generate authentication token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}
- name: Get PR comment author
id: comment
uses: tspascoal/get-user-teams-membership@v2
with:
username: ${{ github.actor }}
team: 'Vector'
GITHUB_TOKEN: ${{ secrets.GH_PAT_ORG }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

- name: Validate author membership
if: steps.comment.outputs.isTeamMember == 'false'
Expand Down Expand Up @@ -365,13 +371,19 @@ jobs:
needs: integration-tests
if: always() && (contains(github.event.comment.body, '/ci-run-integration') || contains(github.event.comment.body, '/ci-run-all'))
steps:
- name: Generate authentication token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}
- name: Validate issue comment
if: github.event_name == 'issue_comment'
uses: tspascoal/get-user-teams-membership@v2
with:
username: ${{ github.actor }}
team: 'Vector'
GITHUB_TOKEN: ${{ secrets.GH_PAT_ORG }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

- name: (PR comment) Get PR branch
uses: xt0rted/pull-request-comment-branch@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ jobs:
- name: Determine if secrets are defined (PR author is team member).
if: github.event_name == 'pull_request'
env:
GH_PAT_ORG: ${{ secrets.GH_PAT_ORG }}
GH_APP_DATADOG_VECTOR_CI_APP_ID: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 was going to mention this 🙂

run: |
if [[ "$GH_PAT_ORG" != "" ]] ; then
if [[ "$GH_APP_DATADOG_VECTOR_CI_APP_ID" != "" ]] ; then
echo "PR_HAS_ACCESS_TO_SECRETS=true" >> "$GITHUB_ENV"
else
echo "PR_HAS_ACCESS_TO_SECRETS=false" >> "$GITHUB_ENV"
Expand Down