Skip to content

Commit 8b03a98

Browse files
feat(github-cli): support private extension installs (#1705)
Co-authored-by: Kaniska <kaniska244@github.com>
1 parent c6f2fbd commit 8b03a98

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/github-cli/NOTES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ This Feature should work on recent versions of Debian/Ubuntu-based distributions
66

77
## Extensions
88

9-
If you set the `extensions` option, the feature will run `gh extension install` for each entry (comma-separated). Extensions are installed for the most appropriate non-root user (based on `USERNAME` / `_REMOTE_USER`), with a fallback to `root`.
9+
If you set the `extensions` option, the feature will install each comma-separated entry. Extensions are installed for the most appropriate non-root user (based on `USERNAME` / `_REMOTE_USER`), with a fallback to `root`.
10+
11+
Private extensions can be installed when `GH_TOKEN` or `GITHUB_TOKEN` is available during feature installation. The token is forwarded to the selected non-root user and used through the GitHub CLI Git credential helper.

src/github-cli/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "github-cli",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"name": "GitHub CLI",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/github-cli",
66
"description": "Installs the GitHub CLI. Auto-detects latest version and installs needed dependencies.",

src/github-cli/install.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ if [ -n "${EXTENSIONS}" ]; then
271271
else
272272
EXTENSIONS_ESCAPED="$(printf '%q' "${EXTENSIONS}")"
273273
USERNAME_ESCAPED="$(printf '%q' "${USERNAME}")"
274-
su - "${USERNAME}" -c "EXTENSIONS=${EXTENSIONS_ESCAPED} USERNAME=${USERNAME_ESCAPED} INSTALL_EXTENSIONS=true bash '${EXTENSIONS_SCRIPT}'"
274+
su \
275+
--login \
276+
--whitelist-environment=GH_TOKEN,GITHUB_TOKEN \
277+
--command "EXTENSIONS=${EXTENSIONS_ESCAPED} USERNAME=${USERNAME_ESCAPED} INSTALL_EXTENSIONS=true bash '${EXTENSIONS_SCRIPT}'" \
278+
"${USERNAME}"
275279
INSTALL_EXTENSIONS=false bash "${EXTENSIONS_SCRIPT}"
276280
fi
277281
fi

src/github-cli/scripts/install-extensions.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,32 @@ install_extension() {
2626

2727
mkdir -p "${extensions_root}"
2828
if [ ! -d "${extensions_root}/${repo_name}" ]; then
29-
git clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}"
29+
git \
30+
-c credential.helper= \
31+
-c credential.helper='!gh auth git-credential' \
32+
clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}"
3033
fi
3134
}
3235

3336
ensure_gh_extension_list_wrapper() {
37+
local gh_config_dir
38+
3439
if [ "$(id -u)" -ne 0 ]; then
3540
return
3641
fi
3742

38-
if gh extension list >/dev/null 2>&1; then
43+
gh_config_dir="$(mktemp -d)"
44+
if env \
45+
-u GH_TOKEN \
46+
-u GITHUB_TOKEN \
47+
-u GH_ENTERPRISE_TOKEN \
48+
-u GITHUB_ENTERPRISE_TOKEN \
49+
GH_CONFIG_DIR="${gh_config_dir}" \
50+
gh extension list >/dev/null 2>&1; then
51+
rm -rf "${gh_config_dir}"
3952
return
4053
fi
54+
rm -rf "${gh_config_dir}"
4155

4256
cat > /usr/local/bin/gh <<'EOF'
4357
#!/usr/bin/env bash

0 commit comments

Comments
 (0)