RUM-10224: GitHub app migration for PAT#2726
Conversation
9a3acdd to
d04bc1c
Compare
| jwt_token="${header_payload}"."${signature}" | ||
|
|
||
| # Fetch installation token | ||
| installation_token=$(curl \ |
| # Copyright 2016-Present Datadog, Inc. | ||
| # | ||
|
|
||
| set -o pipefail |
| - '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: |
There was a problem hiding this comment.
Created a separate job that creates the installation token so that other jobs can reuse it.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
If you have concern about security, I can do it the way you suggest.
| - echo "GITHUB_TOKEN=$(bash ./create_github_installation_token.sh)" >> github.env | ||
| artifacts: | ||
| reports: | ||
| dotenv: github.env |
There was a problem hiding this comment.
read these docs about the dotenv feature
basically we put environment variables in a special file and they are passed to dependent jobs
| artifacts: | ||
| reports: | ||
| dotenv: github.env | ||
| access: none |
| - 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) |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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 🚀 New features to boost your workflow:
|
| 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 |
| - '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: |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
now I pipe the key to create_github_installation_token and then without creating a file straight to openssl link
5039790 to
2632f5f
Compare
0xnm
left a comment
There was a problem hiding this comment.
nice!
having another pair of eyes for this PR will be beneficial, given it is handling credentials topic
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.yamla bit, these changes are not in the pr):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)