Skip to content

update handling of GitHub auth for local, interactive use - #172

Merged
jameslamb merged 3 commits into
mainfrom
gh-artifacts/local-repro
May 8, 2025
Merged

update handling of GitHub auth for local, interactive use#172
jameslamb merged 3 commits into
mainfrom
gh-artifacts/local-repro

Conversation

@jameslamb

@jameslamb jameslamb commented May 8, 2025

Copy link
Copy Markdown
Member

Closes #171

Contributes to https://github.com/rapidsai/build-infra/issues/237

Replaces #168

Some of the scripts in this project use the GitHub CLI. Those require authentication with GitHub.

In CI jobs, that authentication is provided by setting environment variable GH_TOKEN. When using the scripts interactively (e.g., when reproducing CI), it'd be helpful to prompt for an interactive login flow if the local environment isn't already authenticated.

This does that, via that following:

  • in rapids-prompt-local-github-auth, prompts for interactive authentication if not currently auth'd with GitHub (determined via gh auth status)
  • invokes rapids-prompt-local-github-auth in every script that uses the GitHub CLI and which might be called interactively (so excludes rapids-upload-to-anaconda-github, for example)

Notes for Reviewers

How I tested this

Logged out of GitHub locally.

unset GH_TOKEN
gh auth logout

gh auth status
# You are not logged into any GitHub hosts. To log in, run: gh auth login

Tried to download some rmm conda packages.

RAPIDS_BUILD_WORKFLOW_NAME="build.yaml" \
RAPIDS_BUILD_TYPE="branch" \
RAPIDS_REPOSITORY="rapidsai/rmm" \
RAPIDS_REF_NAME="branch-25.06" \
RAPIDS_SHA="dbd8cc7a5f2230a21551670106d4bcd5e507441e" \
rapids-download-from-github \
    rmm_conda_python_cuda12_py312_aarch64

Got an interactive prompt to login:

Screenshot from 2025-05-08 16-15-21

Followed that flow, then was logged in and saw packages download successfully.

Ran that same rapids-download-from-github command again, saw the downloads work and NOT re-prompt for auth.

Logged out again, then set the GH_TOKEN environment variable to a GitHub "classic" token (docs) that only had the repo scope.

 export GH_TOKEN=<redacted>
gh auth status

Confirming that it only had the repo scope:

  ✓ Logged in to github.com account jameslamb (GH_TOKEN)
  - Active account: true
  - Git operations protocol: https
  - Token: ghp_************************************
  - Token scopes: 'repo'
  ! Missing required token scopes: 'read:org'
  - To request missing scopes, run: gh auth refresh -h github.com

Running the same rapids-download-from-github command as above worked, without re-prompting for auth.

Also tested this in an rmm PR:

@bdice bdice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know this isn't ready for review yet - just noting that you already solved one of my questions elsewhere, so no need to respond on that issue.

So far you're doing exactly what I think is needed here.

exit 1
fi

source rapids-prompt-local-github-auth

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes! I came to this conclusion too: #171 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah! Everywhere that we invoke gh in a tool that might be used interactively, this should be called.

The if gh auth status makes it idempotent (ensures you aren't put through the interactive login workflow multiple times).

export RAPIDS_SCRIPT_NAME="rapids-download-from-github"

if [ -z "$1" ]; then
if [ -z "${1:-}" ]; then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The use of set -u a few lines up means that if you fail to pass any arguments to this script, it never gets through this if and emits the informative error message. Defaulting back to null if ${1} is undefined fixes that.

rapids-download-from-github
# tools/rapids-download-from-github: line 9: $1: unbound variable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I observed this too and didn’t realize it was a bug. 🥲

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ha yup! Same thing as conda-forge/arrow-cpp-feedstock#1696, it's easy to trip over stuff like this with set -u.

export RAPIDS_SCRIPT_NAME="rapids-download-conda-from-github"

source rapids-prompt-local-repo-config
source rapids-prompt-local-github-auth

@jameslamb jameslamb May 8, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removing this because this script doesn't directly call the gh CLI. These rapids-prompt-local-github-auth calls should only be placed in scripts that directly need GitHub auth, to minimize unnecessary calls.

Found those like this:

git grep 'gh '

@jameslamb jameslamb changed the title WIP: [NOT READY FOR REVIEW] update handling of GitHub auth for local, interactive use update handling of GitHub auth for local, interactive use May 8, 2025
@jameslamb
jameslamb marked this pull request as ready for review May 8, 2025 21:50
@jameslamb
jameslamb requested a review from a team as a code owner May 8, 2025 21:50
@jameslamb
jameslamb requested review from bdice and msarahan and removed request for a team May 8, 2025 21:50
@jameslamb

Copy link
Copy Markdown
Member Author

Ok this one's ready for review whenever you have time @bdice

export RAPIDS_SCRIPT_NAME="rapids-download-from-github"

if [ -z "$1" ]; then
if [ -z "${1:-}" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I observed this too and didn’t realize it was a bug. 🥲

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.

rapids-prompt-local-github-auth should check gh auth status as well as environment variables.

2 participants