Skip to content

feat(github-cli)!: add runtime authentication and explicit extension modes - #1606

Open
Emilien Escalle (neilime) wants to merge 9 commits into
devcontainers:mainfrom
neilime:feat/add-auto-auth-option
Open

Emilien Escalle (neilime) wants to merge 9 commits into
devcontainers:mainfrom
neilime:feat/add-auto-auth-option

Conversation

@neilime

@neilime Emilien Escalle (neilime) commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Release the GitHub CLI feature as 2.0.0, with optional authentication at shell startup and explicit extension installation modes. Runtime authentication lets extension installation use tokens supplied through settings such as remoteEnv.

Breaking change

A nonempty extensions option now requires at least one of:

  • authOnSetup=true: install through gh extension install after runtime authentication. Supports script and precompiled extensions.
  • installExtensionsFromGit=true: clone script extensions during the container build. Each repository must contain an executable at its root matching the repository name.

Both options default to false. Setting both installs script extensions during the build and enables authentication at shell startup. An extensions-only configuration fails before installing GitHub CLI. The automatic git fallback and the gh extension list compatibility wrapper are removed.

Examples and generated documentation now use ghcr.io/devcontainers/features/github-cli:2.

Authentication and extension behavior

  • Use GH_TOKEN or GITHUB_TOKEN directly, without calling gh auth login --with-token or persisting the environment token. Warn on stderr when authentication fails with a token set.
  • Run interactive gh auth login only when authentication is needed, no environment token is set, and a terminal is available.
  • Call gh extension install without redundant authentication or extension-list checks in the extension installer.
  • Retry failed deferred installs on the next shell startup. Tie completion to the extension configuration so rebuilds with a persistent home install newly requested extensions.
  • Fail explicitly when a git clone has no runnable entry point, while preserving existing user data.

Validation

  • devcontainer features test --project-folder "$PWD" --features github-cli --base-image ubuntu:noble: all 7 tests passed in 287 seconds, including the Debian trixie and Ubuntu resolute scenarios.
  • Updated existing regression tests cover environment-token authentication, failed-install retries, persistent-home rebuilds, and missing git entry points. Both updated regression tests reject the previous implementations.
  • Checked interactive login with an isolated fake gh, configuration rejection, shell syntax, JSON, documentation links/examples, and git diff --check.
  • Validated metadata and regenerated the feature README using the existing devcontainers/action@v1 generator.

@neilime
Emilien Escalle (neilime) force-pushed the feat/add-auto-auth-option branch 3 times, most recently from c219e7c to 2d610ba Compare March 19, 2026 19:34
@neilime
Emilien Escalle (neilime) marked this pull request as ready for review March 19, 2026 19:34
@neilime
Emilien Escalle (neilime) requested a review from a team as a code owner March 19, 2026 19:34
@neilime Emilien Escalle (neilime) changed the title feat: add github-cli auth-on-setup option feat(github-cli): add github-cli auth-on-setup option Mar 19, 2026
@neilime

Copy link
Copy Markdown
Contributor Author

Hi @Kaniska244 any chance to have this PR merged? Thank you :)

@neilime

Copy link
Copy Markdown
Contributor Author

Hi @Kaniska244, here is a kindly reminder, hoping having this PR merged one day :)

Thanks

@abdurriq

Copy link
Copy Markdown
Contributor

Hello Emilien Escalle (@neilime), apologies this is my fault as I've been meaning to look at this but haven't had a chance. I'll try to review this within the week.

@abdurriq

Copy link
Copy Markdown
Contributor

Emilien Escalle (@neilime) Would you be able to break this PR up, as I'm struggling to review it given the size and number of files touched?

@neilime

Copy link
Copy Markdown
Contributor Author

Abdurrahmaan Iqbal (@abdurriq) done: 6 atomic commits (atomic as much as I can) with their own purpose

@abdurriq

Copy link
Copy Markdown
Contributor

I noticed some inconsistencies in double-quotes around params and the logic between src/github-cli/scripts/install-github-cli.sh and src/github-cli/install.sh in (98182e1). I wonder why it wasn't just a 1:1 copy, since we know the old version already works. Either way, the new one seems OK, so it shouldn't be too much of an issue.

@neilime

Copy link
Copy Markdown
Contributor Author

I noticed some inconsistencies in double-quotes around params and the logic between src/github-cli/scripts/install-github-cli.sh and src/github-cli/install.sh in (98182e1). I wonder why it wasn't just a 1:1 copy, since we know the old version already works. Either way, the new one seems OK, so it shouldn't be too much of an issue.

Not a strict 1:1 copy on purpose: the top-level script now only orchestrates the install/auth/extensions scopes, so the previous logic was split into dedicated scripts. Your concern about drift was valid though, and I found one real inconsistency in the installExtensionsFromGit path and fixed it. Aside from that, the remaining differences are mostly cleanup, plus one small fallback fix in the GitHub CLI installer.

@neilime

Copy link
Copy Markdown
Contributor Author

Abdurrahmaan Iqbal (@abdurriq) Hi, any news for merging this PR? Thanks

@neilime

Copy link
Copy Markdown
Contributor Author

Hi Abdurrahmaan Iqbal (@abdurriq) this is a kindly reminder for my PR :)

@abdurriq

Copy link
Copy Markdown
Contributor

Emilien Escalle (@neilime) Apologies, this totally slipped my mind. I'll try to prioritise this and review it by mid-next week.

@abdurriq

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

@neilime

Copy link
Copy Markdown
Contributor Author

Emilien Escalle (@neilime) Apologies, this totally slipped my mind. I'll try to prioritise this and review it by mid-next week.

Abdurrahmaan Iqbal (@abdurriq) No problem, I can rebase and fix conflict if it can help

@abdurriq

Copy link
Copy Markdown
Contributor

Emilien Escalle (@neilime) Yes, please.

@neilime

Copy link
Copy Markdown
Contributor Author

Emilien Escalle (@neilime) Yes, please.

Done.

Comment thread src/github-cli/install.sh Outdated
exit 1
validate_configuration() {
if has_unsupported_extensions_configuration; then
die "Unsupported extensions configuration. When 'extensions' is set, enable 'authOnSetup' to install after authentication or set 'installExtensionsFromGit' to true to clone extensions during feature setup."

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.

With both new options defaulting to false, validate_configuration now exits before installing gh, so anyone pinned to :1 of this feature using the existing {"extensions": "..."} configuration, including the README example, will have their config broken. Could the default keep the previous attempt-gh-then-clone behavior when neither option is set?

}

main() {
if is_auth_setup_complete || ! is_gh_available; 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.

This early exit also skips deferred extension installation, not just auth, so a marker left in a persistent home causes extensions added on a rebuild to be ignored. Could the hook process pending extensions.env before honouring the marker, or tie the marker to the current extension config?

Restore default extension installation with a Git fallback, reject clones without runnable entry points, and rerun deferred installs when their configuration changes.

Add regression coverage and regenerate feature documentation. Validated with five container tests, focused regression tests, ShellCheck, and metadata validation.

Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
die "Cannot install extension '${EXTENSION}' with 'gh': GitHub CLI is unavailable."
fi

if ! gh_is_authenticated; 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.

Could we drop the gh auth status check and always attempt gh extension install, keeping the git fallback for when it fails? gh extension install already exits 0 when the extension is already installed, so the extension list pre-check may not be needed either.

Comment thread src/github-cli/scripts/auth-on-setup.sh Outdated

attempt_login() {
if [ -n "${RESOLVED_AUTH_TOKEN}" ]; then
printf '%s' "${RESOLVED_AUTH_TOKEN}" | gh auth login --with-token > /dev/null 2>&1 || true

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.

When GH_TOKEN or GITHUB_TOKEN is set, gh uses it directly and refuses gh auth login --with-token with the error "The value of the GH_TOKEN environment variable is being used for authentication". That means this line only runs when the token is invalid, and will always fails.

Could we skip the --with-token call when the token comes from the environment, and print a warning to stderr when gh auth status fails with a token set?

@abdurriq

Copy link
Copy Markdown
Contributor

Added a couple comments related to auth decisions. Also, backward compatibility is a bit tricky here; what do you think about scrapping that entirely and just bumping up to the next major version? That might simplify things a bit.

Use environment tokens directly, warn on authentication failures, and delegate extension installation checks to gh. Preserve deferred installation retries and configuration-aware completion markers.

BREAKING CHANGE: extensions require authOnSetup or installExtensionsFromGit. Remove the automatic git fallback and gh compatibility wrapper, and release the feature as 2.0.0.
@neilime Emilien Escalle (neilime) changed the title feat(github-cli): add github-cli auth-on-setup option feat(github-cli)!: add runtime authentication and explicit extension modes Dec 4, 2026

This branch has not been deployed

No deployments
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.

3 participants