Skip to content

RUM-10224: GitHub app migration for PAT#2726

Merged
aleksandr-gringauz merged 2 commits into
developfrom
aleksandr-gringauz/RUM-10224/github-app-migration-for-pat
Jun 17, 2025
Merged

RUM-10224: GitHub app migration for PAT#2726
aleksandr-gringauz merged 2 commits into
developfrom
aleksandr-gringauz/RUM-10224/github-app-migration-for-pat

Conversation

@aleksandr-gringauz

@aleksandr-gringauz aleksandr-gringauz commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Migrate from a classical PAT to GitHub app installation token for using GitHub api to create PRs in datadog-android, shopist-android, dd-sdk-android-gradle-plugin.

I tested that it works (although I had to modify gitlab-ci.yaml a bit, these changes are not in the pr):

  1. https://github.com/DataDog/datadog-android/pull/7366
  2. Update Datadog SDK to version 3.12.0 dd-sdk-android-gradle-plugin#382
  3. For shopist I couldn't test, because there we use SNAPSHOT version and our current job (without my changes) actually doesn't do anything.

Here is the app we now use.

RFC link.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/RUM-10224/github-app-migration-for-pat branch from 9a3acdd to d04bc1c Compare June 13, 2025 10:18
jwt_token="${header_payload}"."${signature}"

# Fetch installation token
installation_token=$(curl \

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.

copied this from the docs

# Copyright 2016-Present Datadog, Inc.
#

set -o pipefail

@aleksandr-gringauz aleksandr-gringauz Jun 13, 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.

copied from the docs

Comment thread .gitlab-ci.yml Outdated
- 'MESSAGE_TEXT=":status_alert: $CI_PROJECT_NAME $CI_COMMIT_TAG publish pipeline <$BUILD_URL|$COMMIT_MESSAGE> failed."'
- postmessage "#mobile-sdk-ops" "$MESSAGE_TEXT"

notify:prepare-github-token:

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.

Created a separate job that creates the installation token so that other jobs can reuse it.

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.

what is the benefit of doing this in a dedicated job and passing secret in env variable to another job (what is discouraged it seems, so we need to put access field) instead of simply doing these steps in every job where installation token is needed?

These steps can be put to the .snippets section and then referenced.

@aleksandr-gringauz aleksandr-gringauz Jun 13, 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.

The point is just not to do something multiple times if it can be done only once.

In order to obtain the installation token you need to use github rest api https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token. Now we do it once and reuse the token.

I don't know the specific ratelimit of the endpoint, the docs don't give a direct answer for the one I am using https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28. Maybe this, but not sure.

For now we use it only during release process. I tried obtaining multiple tokens one after another, it worked.

So ratelimit for now will not be a problem.

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.

If you have concern about security, I can do it the way you suggest.

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.

done

Comment thread .gitlab-ci.yml Outdated
- echo "GITHUB_TOKEN=$(bash ./create_github_installation_token.sh)" >> github.env
artifacts:
reports:
dotenv: github.env

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.

read these docs about the dotenv feature

basically we put environment variables in a special file and they are passed to dependent jobs

Comment thread .gitlab-ci.yml Outdated
artifacts:
reports:
dotenv: github.env
access: none

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.

Read:

  1. this
  2. this

I hope this is enough security.

Comment thread .gitlab-ci.yml Outdated
Comment on lines +982 to +983
- export GITHUB_APP_CLIENT_ID=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gh_app_client_id --with-decryption --query "Parameter.Value" --out text)
- export GITHUB_APP_INSTALLATION_ID=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gh_app_installation_id --with-decryption --query "Parameter.Value" --out text)

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.

client_id and installation_id aren't actually considered secrets https://datadoghq.atlassian.net/wiki/spaces/ITENG/pages/1014726683/Creating+a+new+Github+App+for+API+Access (see info at the bottom)

but I still decided to put them in aws ssm

@codecov-commenter

codecov-commenter commented Jun 13, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.83%. Comparing base (04534ae) to head (2632f5f).
⚠️ Report is 1992 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2726      +/-   ##
===========================================
+ Coverage    69.74%   69.83%   +0.08%     
===========================================
  Files          824      824              
  Lines        30774    30774              
  Branches      5173     5173              
===========================================
+ Hits         21463    21489      +26     
+ Misses        7846     7828      -18     
+ Partials      1465     1457       -8     

see 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aleksandr-gringauz
aleksandr-gringauz marked this pull request as ready for review June 13, 2025 10:47
@aleksandr-gringauz
aleksandr-gringauz requested review from a team as code owners June 13, 2025 10:47
Comment thread dogfood.py
def git_clone_repository(repo_name: str, gh_token: str, temp_dir_path: str) -> Tuple[Repo, str]:
print("Cloning repository " + repo_name)
url = "https://" + gh_token + ":x-oauth-basic@github.com/DataDog/" + repo_name
url = "https://x-access-token:" + gh_token + "@github.com/DataDog/" + repo_name

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.

copied from the docs

Comment thread .gitlab-ci.yml Outdated
- 'MESSAGE_TEXT=":status_alert: $CI_PROJECT_NAME $CI_COMMIT_TAG publish pipeline <$BUILD_URL|$COMMIT_MESSAGE> failed."'
- postmessage "#mobile-sdk-ops" "$MESSAGE_TEXT"

notify:prepare-github-token:

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.

what is the benefit of doing this in a dedicated job and passing secret in env variable to another job (what is discouraged it seems, so we need to put access field) instead of simply doing these steps in every job where installation token is needed?

These steps can be put to the .snippets section and then referenced.

Comment thread .gitlab-ci.yml Outdated
stage: notify
when: on_success
script:
- aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gh_app_private_key --with-decryption --query "Parameter.Value" --out text >> ./gh_private_key.pem

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.

is it safer to pipe it to the create_github_installation_token.sh instead of creating a file? or it doesn't matter since the runner is destroyed after?

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.

now I pipe the key to create_github_installation_token and then without creating a file straight to openssl link

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/RUM-10224/github-app-migration-for-pat branch from 5039790 to 2632f5f Compare June 13, 2025 15:57

@0xnm 0xnm left a comment

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.

nice!

having another pair of eyes for this PR will be beneficial, given it is handling credentials topic

@aleksandr-gringauz
aleksandr-gringauz merged commit d5cf727 into develop Jun 17, 2025
25 checks passed
@aleksandr-gringauz
aleksandr-gringauz deleted the aleksandr-gringauz/RUM-10224/github-app-migration-for-pat branch June 17, 2025 08:09
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.

4 participants