-
Notifications
You must be signed in to change notification settings - Fork 4
feat(setup-github-token): support invoke-gati-v2 #1660
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
Open
erikburt
wants to merge
6
commits into
main
Choose a base branch
from
feat/setup-github-token-gati-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−9
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c5f7902
feat(setup-github-token): support invoke-gati-v2
erikburt f95e83d
fix: default aws-region
erikburt b6222ba
test: .github-internal
erikburt 80e253b
fix: point at proper repo/tag
erikburt b261e5d
remove temporary validation workflow
erikburt 5654624
Merge branch 'main' into feat/setup-github-token-gati-v2
erikburt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "setup-github-token": minor | ||
| --- | ||
|
|
||
| Support GATI v2 behind a staged rollout. Adds a `profile` input that selects | ||
| GATI v2, a `gati-version` input to force either flow, and a `gati-version` | ||
| output. `aws-role-arn` and `aws-lambda-url` are now optional, and required only | ||
| when `profile` is not set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,90 @@ | ||
| # setup-github-token action | ||
|
|
||
| Gets a GitHub installation access token from GATI, and optionally configures git | ||
| to authenticate with it. | ||
|
|
||
| Requires `id-token: write` on the calling job — v1 uses it to assume the AWS | ||
| role, v2 to authenticate to GATI directly. | ||
|
|
||
| ## Which flow runs | ||
|
|
||
| - **v1** ([`invoke-gati`](../invoke-gati/)) assumes `aws-role-arn`, then calls | ||
| the lambda at `aws-lambda-url`. | ||
| - **v2** ([`invoke-gati-v2`](../invoke-gati-v2/)) requests a `profile` over | ||
| GitHub OIDC, with no AWS credentials. | ||
|
|
||
| Passing `profile` selects v2. Otherwise a staged rollout decides: the repository | ||
| name is hashed into a bucket of 0–99, and uses v2 when that bucket is below the | ||
| rollout percentage. Since the bucket never changes, a repository moves to v2 | ||
| once and stays there. The percentage and the two pin lists that override it are | ||
| the `ROLLOUT_PERCENTAGE`, `FORCE_V2_REPOSITORIES`, and `FORCE_V1_REPOSITORIES` | ||
| env values on the `Resolve GATI version` step in [`action.yml`](./action.yml); | ||
| changing them needs a release. `gati-version` overrides all of the above. | ||
|
|
||
| ## Migrated v1 roles | ||
|
|
||
| GATI v1 role configuration was carried into v2 automatically, keyed by the | ||
| role's IAM ARN and addressable as the profile `v1/<iam-role-arn>`. So v2 needs | ||
| no new configuration to take over from v1: given no `profile`, it derives one | ||
| from the `aws-role-arn` the caller already passes and returns a token with the | ||
| same permissions v1 would have. A caller only needs a real `profile` to get | ||
| scopes its v1 role does not already have. | ||
|
|
||
| ## Inputs | ||
|
|
||
| Either `profile` or the v1 inputs must be provided. | ||
|
|
||
| | Name | Description | Defaulted | | ||
| | ---------------- | --------------------------------------------------------- | -------------- | | ||
| | `set-git-config` | Configure git to use the token for `https://github.com/`. | ✅ - `"false"` | | ||
| | `gati-version` | Force `v1` or `v2`, bypassing the rollout. | | | ||
|
|
||
| ### v2 | ||
|
|
||
| | Name | Description | | ||
| | --------- | ---------------------------------------------- | | ||
| | `profile` | Token profile to request. Selects v2 when set. | | ||
|
|
||
| ### v1 | ||
|
|
||
| Also read by v2 to derive a profile, see | ||
| [Migrated v1 roles](#migrated-v1-roles). Ignored when `profile` is set. | ||
|
|
||
| | Name | Description | Defaulted | | ||
| | --------------------------- | ----------------------------------------------- | -------------------------------- | | ||
| | `aws-role-arn` | ARN of the role that can get a token from GATI. | | | ||
| | `aws-lambda-url` | URL of the GATI lambda function. | | | ||
| | `aws-region` | AWS region. | | | ||
| | `aws-role-duration-seconds` | Duration of the assumed role, in seconds. | ✅ - `"900"` | | ||
| | `role-session-name` | Session name, truncated to 64 characters. | ✅ - run id, run number, and job | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| | -------------- | --------------------------------------------------------------------------------------------------------------- | | ||
| | `access-token` | The token. A v2 token is revoked when its job ends, so request one per job rather than passing it between jobs. | | ||
| | `gati-version` | The GATI version that issued the token, `v1` or `v2`. | | ||
|
|
||
| ## Example | ||
|
|
||
| ```yaml | ||
| jobs: | ||
| example: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - name: Setup GitHub token | ||
| id: setup-github-token | ||
| uses: smartcontractkit/.github/actions/setup-github-token@setup-github-token/v1 | ||
| with: | ||
| aws-role-arn: ${{ secrets.AWS_OIDC_IAM_ROLE_ARN_GATI }} | ||
| aws-lambda-url: ${{ secrets.AWS_LAMBDA_URL_GATI }} | ||
| aws-region: us-west-2 | ||
|
|
||
| - name: Use the token | ||
| env: | ||
| GH_TOKEN: ${{ steps.setup-github-token.outputs.access-token }} | ||
| run: gh repo view smartcontractkit/.github | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
actions/setup-github-token/scripts/resolve-gati-version.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Selects between GATI v1 (assume an AWS role, then call the v1 lambda) and GATI | ||
| # v2 (GitHub OIDC, no AWS credentials), then emits the version and, for v2, the | ||
| # profile to request. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| PROFILE="${PROFILE:-}" | ||
| GATI_VERSION="${GATI_VERSION:-}" | ||
| AWS_ROLE_ARN="${AWS_ROLE_ARN:-}" | ||
| AWS_LAMBDA_URL="${AWS_LAMBDA_URL:-}" | ||
|
|
||
| VERSION="" | ||
| REASON="" | ||
|
|
||
| resolve_version() { | ||
| if [[ -n "${GATI_VERSION}" ]]; then | ||
| if [[ "${GATI_VERSION}" != "v1" && "${GATI_VERSION}" != "v2" ]]; then | ||
| echo "::error::gati-version must be 'v1' or 'v2', got '${GATI_VERSION}'." | ||
| exit 1 | ||
| fi | ||
| VERSION="${GATI_VERSION}" | ||
| REASON="gati-version input" | ||
| return | ||
| fi | ||
|
|
||
| if [[ -n "${PROFILE}" ]]; then | ||
| VERSION="v2" | ||
| REASON="profile input" | ||
| return | ||
| fi | ||
|
|
||
| # A repository pinned to both lists stays on v1, so that pinning a broken | ||
| # repository back to v1 does not require also editing the v2 list. | ||
| if grep -qxF "${GITHUB_REPOSITORY}" <<<"${FORCE_V1_REPOSITORIES}"; then | ||
| VERSION="v1" | ||
| REASON="repository is pinned to v1" | ||
| return | ||
| fi | ||
|
|
||
| if grep -qxF "${GITHUB_REPOSITORY}" <<<"${FORCE_V2_REPOSITORIES}"; then | ||
| VERSION="v2" | ||
| REASON="repository is pinned to v2" | ||
| return | ||
| fi | ||
|
|
||
| local bucket | ||
| bucket=$(($(printf '%s' "${GITHUB_REPOSITORY}" | cksum | cut -d ' ' -f 1) % 100)) | ||
| REASON="bucket ${bucket}, rollout at ${ROLLOUT_PERCENTAGE}%" | ||
| if ((bucket < ROLLOUT_PERCENTAGE)); then | ||
| VERSION="v2" | ||
| else | ||
| VERSION="v1" | ||
| fi | ||
| } | ||
|
|
||
| resolve_version | ||
|
|
||
| if [[ "${VERSION}" == "v1" && -n "${PROFILE}" ]]; then | ||
| echo "::error::profile is only supported by GATI v2, but v1 was selected (${REASON}). Remove the profile input, or set gati-version to 'v2'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "${PROFILE}" ]]; then | ||
| if [[ -z "${AWS_ROLE_ARN}" || -z "${AWS_LAMBDA_URL}" ]]; then | ||
| echo "::error::aws-role-arn and aws-lambda-url are required when profile is not set." | ||
| exit 1 | ||
| fi | ||
| # Only read by the v2 flow, which migrates a v1 role ARN as a v1 profile. | ||
| PROFILE="v1/${AWS_ROLE_ARN}" | ||
| fi | ||
|
|
||
| echo "Using GATI ${VERSION} (${REASON})." | ||
| echo "version=${VERSION}" >>"$GITHUB_OUTPUT" | ||
|
|
||
| if [[ "${VERSION}" == "v2" ]]; then | ||
| # Written without tee: the profile can embed an IAM role ARN. | ||
| echo "profile=${PROFILE}" >>"$GITHUB_OUTPUT" | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIll fix in follow-up