mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
feat(devcontainer): add credential-helper toggle and token forwarding
Add tooling for testing private repo auth inside the devcontainer: - credential-helper script (on/off/status) with --eval mode to toggle both git credential helper and token env vars in one command - remoteEnv forwards host token env vars (GITHUB_TOKEN, GITLAB_TOKEN, BITBUCKET_TOKEN, BITBUCKET_USERNAME, SKILLSHARE_GIT_TOKEN) - docker-compose env_file for .devcontainer/.env (optional, gitignored) - start-dev.sh auto-detects GITHUB_TOKEN from gh CLI on container start - .env.example template for all supported tokens - docker-sandbox.md documents token sources and private repo testing
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# Copy to .env and fill in your tokens.
|
||||
# .env is gitignored — secrets stay local.
|
||||
#
|
||||
# GITHUB_TOKEN=ghp_...
|
||||
# GITLAB_TOKEN=glpat-...
|
||||
# BITBUCKET_TOKEN=...
|
||||
# BITBUCKET_USERNAME=...
|
||||
# SKILLSHARE_GIT_TOKEN=...
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_FILE="/tmp/.git-credential-helper-backup"
|
||||
TOKEN_BACKUP="/tmp/.git-token-env-backup"
|
||||
TOKEN_VARS=(GITHUB_TOKEN GITLAB_TOKEN BITBUCKET_TOKEN BITBUCKET_USERNAME SKILLSHARE_GIT_TOKEN)
|
||||
|
||||
# When called with --eval, output shell commands for the caller to eval.
|
||||
# Usage: eval "$(credential-helper off)" / eval "$(credential-helper on)"
|
||||
EVAL_MODE=false
|
||||
if [ "${1:-}" = "--eval" ]; then
|
||||
EVAL_MODE=true
|
||||
shift
|
||||
fi
|
||||
|
||||
emit() {
|
||||
if $EVAL_MODE; then
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
off)
|
||||
# Save current credential helper
|
||||
current="$(git config --global credential.helper 2>/dev/null || true)"
|
||||
if [ -n "$current" ] && [ "$current" != "''" ]; then
|
||||
echo "$current" > "$BACKUP_FILE"
|
||||
echo "Saved credential.helper: $current" >&2
|
||||
fi
|
||||
git config --global credential.helper ''
|
||||
echo "credential.helper disabled" >&2
|
||||
|
||||
# Save and unset token env vars
|
||||
: > "$TOKEN_BACKUP"
|
||||
for var in "${TOKEN_VARS[@]}"; do
|
||||
val="${!var:-}"
|
||||
if [ -n "$val" ]; then
|
||||
echo "$var=$val" >> "$TOKEN_BACKUP"
|
||||
emit "unset $var;"
|
||||
echo " unset $var" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
if ! $EVAL_MODE; then
|
||||
# Check if any tokens were active but couldn't be unset
|
||||
has_tokens=false
|
||||
for var in "${TOKEN_VARS[@]}"; do
|
||||
if [ -n "${!var:-}" ]; then has_tokens=true; break; fi
|
||||
done
|
||||
if $has_tokens; then
|
||||
echo "" >&2
|
||||
echo "Token env vars detected but cannot be unset from a script." >&2
|
||||
echo "Run with eval to also clear tokens:" >&2
|
||||
echo " eval \"\$(credential-helper --eval off)\"" >&2
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
on)
|
||||
# Restore credential helper
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
saved="$(cat "$BACKUP_FILE")"
|
||||
git config --global credential.helper "$saved"
|
||||
echo "credential.helper restored: $saved" >&2
|
||||
else
|
||||
git config --global --unset credential.helper 2>/dev/null || true
|
||||
echo "credential.helper unset (system default)" >&2
|
||||
fi
|
||||
|
||||
# Restore token env vars
|
||||
if [ -f "$TOKEN_BACKUP" ]; then
|
||||
while IFS='=' read -r key val; do
|
||||
[ -z "$key" ] && continue
|
||||
emit "export $key='$val';"
|
||||
echo " restored $key" >&2
|
||||
done < "$TOKEN_BACKUP"
|
||||
rm -f "$TOKEN_BACKUP"
|
||||
fi
|
||||
|
||||
if ! $EVAL_MODE; then
|
||||
if [ -f "$TOKEN_BACKUP" ] 2>/dev/null; then
|
||||
echo "" >&2
|
||||
echo "Token backup found. Run with eval to restore tokens:" >&2
|
||||
echo " eval \"\$(credential-helper --eval on)\"" >&2
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
current="$(git config --global credential.helper 2>/dev/null || true)"
|
||||
if [ -z "$current" ]; then
|
||||
echo "credential.helper: (not set, using system default)"
|
||||
elif [ "$current" = "''" ]; then
|
||||
echo "credential.helper: DISABLED"
|
||||
else
|
||||
echo "credential.helper: $current"
|
||||
fi
|
||||
echo ""
|
||||
for var in "${TOKEN_VARS[@]}"; do
|
||||
val="${!var:-}"
|
||||
if [ -n "$val" ]; then
|
||||
# Show first 4 chars + mask
|
||||
masked="${val:0:4}****"
|
||||
echo "$var: $masked"
|
||||
else
|
||||
echo "$var: (not set)"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
*)
|
||||
echo "Usage: eval \"\$(credential-helper --eval <on|off>)\"" >&2
|
||||
echo " credential-helper <on|off|status>" >&2
|
||||
echo "" >&2
|
||||
echo " off Disable all git auth (credential helper + token env vars)" >&2
|
||||
echo " on Restore credential helper and token env vars" >&2
|
||||
echo " status Show current auth state" >&2
|
||||
echo "" >&2
|
||||
echo "Use --eval to also unset/restore token env vars in your shell." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -17,7 +17,12 @@
|
||||
},
|
||||
"remoteEnv": {
|
||||
"PATH": "/workspace/.devcontainer/bin:/workspace/bin:${containerEnv:PATH}",
|
||||
"SKILLSHARE_UI_HOST": "0.0.0.0"
|
||||
"SKILLSHARE_UI_HOST": "0.0.0.0",
|
||||
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",
|
||||
"GITLAB_TOKEN": "${localEnv:GITLAB_TOKEN}",
|
||||
"BITBUCKET_TOKEN": "${localEnv:BITBUCKET_TOKEN}",
|
||||
"BITBUCKET_USERNAME": "${localEnv:BITBUCKET_USERNAME}",
|
||||
"SKILLSHARE_GIT_TOKEN": "${localEnv:SKILLSHARE_GIT_TOKEN}"
|
||||
},
|
||||
"postCreateCommand": ".devcontainer/setup.sh",
|
||||
"postStartCommand": ".devcontainer/start-dev.sh",
|
||||
|
||||
@@ -7,6 +7,9 @@ services:
|
||||
dockerfile: docker/sandbox/Dockerfile
|
||||
working_dir: /workspace
|
||||
command: sleep infinity
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
HOME: /tmp
|
||||
GOCACHE: /go/build-cache
|
||||
|
||||
@@ -60,6 +60,11 @@ echo " ui stop # stop dashboard"
|
||||
echo " docs # documentation site → :3000"
|
||||
echo " docs stop # stop docs"
|
||||
echo ""
|
||||
echo "Private repos:"
|
||||
echo " credential-helper status # check auth state"
|
||||
echo " eval \"\$(credential-helper --eval off)\" # disable all auth"
|
||||
echo " eval \"\$(credential-helper --eval on)\" # restore all auth"
|
||||
echo ""
|
||||
echo "Audit playground:"
|
||||
echo " ss audit # scan all skills, see findings"
|
||||
echo " cd ~/demo-project && ss audit # project-level scan"
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
# Print available commands on container start.
|
||||
# Resolve GITHUB_TOKEN and print available commands on container start.
|
||||
set -euo pipefail
|
||||
|
||||
# Auto-detect GITHUB_TOKEN from gh CLI if not already set
|
||||
# (via .env, remoteEnv, or manual export).
|
||||
if [ -z "${GITHUB_TOKEN:-}" ] && command -v gh &>/dev/null; then
|
||||
token="$(gh auth token 2>/dev/null || true)"
|
||||
if [ -n "$token" ]; then
|
||||
export GITHUB_TOKEN="$token"
|
||||
echo "GITHUB_TOKEN auto-detected from gh CLI"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Dev servers ready:"
|
||||
echo " ui # global-mode dashboard → :5173"
|
||||
echo " ui -p # project-mode dashboard → :5173"
|
||||
|
||||
@@ -30,6 +30,9 @@ docs/plans/
|
||||
|
||||
video/node_modules/
|
||||
|
||||
# Devcontainer secrets
|
||||
.devcontainer/.env
|
||||
|
||||
# Web UI
|
||||
ui/node_modules/
|
||||
ui/dist/
|
||||
|
||||
@@ -317,7 +317,7 @@ skillshare install https://github.com/org/private-skills.git --track
|
||||
|----------|---------|------------|
|
||||
| GitHub | `GITHUB_TOKEN` | Personal access token (`repo` scope) |
|
||||
| GitLab | `GITLAB_TOKEN` | Personal access or CI job token |
|
||||
| Bitbucket | `BITBUCKET_TOKEN` | Repository token, or app password (with `BITBUCKET_USERNAME` or `https://<username>@...`) |
|
||||
| Bitbucket | `BITBUCKET_TOKEN` | Repository token, or app password (with `BITBUCKET_USERNAME`) |
|
||||
| Any host | `SKILLSHARE_GIT_TOKEN` | Generic fallback |
|
||||
|
||||
Platform-specific variables take priority over `SKILLSHARE_GIT_TOKEN`.
|
||||
@@ -364,6 +364,7 @@ install-skills:
|
||||
script:
|
||||
- skillshare install https://bitbucket.org/team/skills.git --track
|
||||
env:
|
||||
BITBUCKET_USERNAME: $BITBUCKET_USERNAME # for app passwords
|
||||
BITBUCKET_TOKEN: $BITBUCKET_TOKEN
|
||||
```
|
||||
|
||||
|
||||
@@ -326,6 +326,38 @@ docs stop # stop Docusaurus
|
||||
|
||||
`ui` starts both the Go API backend (port 19420, background) and Vite dev server (port 5173, HMR). Switching between `ui` and `ui -p` automatically restarts the API in the new mode. VS Code auto-forwards ports to your host browser.
|
||||
|
||||
### Token configuration
|
||||
|
||||
Tokens for private repo access (`GITHUB_TOKEN`, `GITLAB_TOKEN`, etc.) can come from multiple sources. They are checked in this order:
|
||||
|
||||
| Priority | Source | Setup |
|
||||
|----------|--------|-------|
|
||||
| 1 | `.devcontainer/.env` | Copy `.env.example` → `.env`, fill in values (gitignored) |
|
||||
| 2 | Host env vars | Set in `~/.zshrc` — forwarded via `remoteEnv` in `devcontainer.json` |
|
||||
| 3 | `gh auth login` | `GITHUB_TOKEN` auto-detected on container start (GitHub only) |
|
||||
|
||||
All sources are optional. You can also use `export` manually inside the container at any time.
|
||||
|
||||
Check current state:
|
||||
|
||||
```bash
|
||||
credential-helper status
|
||||
```
|
||||
|
||||
### Private repo testing
|
||||
|
||||
VS Code Dev Containers automatically forwards your host git credentials into the container. This means `git clone` of private repos may succeed even without explicit token env vars — the forwarded credential helper handles auth silently.
|
||||
|
||||
To disable **all** authentication (credential helper + token env vars) for testing:
|
||||
|
||||
```bash
|
||||
eval "$(credential-helper --eval off)" # disable everything
|
||||
eval "$(credential-helper --eval on)" # restore everything
|
||||
credential-helper status # check current state
|
||||
```
|
||||
|
||||
Without `--eval`, only the git credential helper is toggled (token env vars remain active).
|
||||
|
||||
### Running tests
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user