diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 2c7fd072eb8..3f64a944a9d 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -14,7 +14,12 @@ jobs: contents: read steps: - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: diff --git a/.github/workflows/copilot-token-audit.lock.yml b/.github/workflows/copilot-token-audit.lock.yml index 8001a6e9987..ce17fb0d4d1 100644 --- a/.github/workflows/copilot-token-audit.lock.yml +++ b/.github/workflows/copilot-token-audit.lock.yml @@ -452,7 +452,12 @@ jobs: env: GH_TOKEN: ${{ github.token }} - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Install npm dependencies run: cd actions/setup/js && npm ci - name: Install development dependencies @@ -472,7 +477,7 @@ jobs: - env: GH_TOKEN: ${{ secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN || secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }} name: Install gh-aw extension - run: "# Install gh-aw if not already available\nif ! gh aw --version >/dev/null 2>&1; then\n echo \"Installing gh-aw extension...\"\n curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash\nfi\ngh aw --version\n# Copy the gh-aw binary to ${RUNNER_TEMP}/gh-aw for MCP server containerization\nmkdir -p \"${RUNNER_TEMP}/gh-aw\"\nGH_AW_BIN=\"\"\nGH_AW_BIN=$(command -v gh-aw 2>/dev/null) || true\nif [ -z \"$GH_AW_BIN\" ]; then\n GH_AW_BIN=$(find \"${HOME}/.local/share/gh/extensions/gh-aw\" -name 'gh-aw' -type f 2>/dev/null | head -1) || true\nfi\nif [ -n \"$GH_AW_BIN\" ] && [ -f \"$GH_AW_BIN\" ]; then\n cp \"$GH_AW_BIN\" \"${RUNNER_TEMP}/gh-aw/gh-aw\"\n chmod +x \"${RUNNER_TEMP}/gh-aw/gh-aw\"\n echo \"Copied gh-aw binary to ${RUNNER_TEMP}/gh-aw/gh-aw\"\nelse\n echo \"::error::Failed to find gh-aw binary for MCP server\"\n exit 1\nfi\n" + run: "# Install gh-aw if not already available\nif ! gh aw --version >/dev/null 2>&1; then\n echo \"Installing gh-aw extension...\"\n gh extension install github/gh-aw\nfi\ngh aw --version\n# Copy the gh-aw binary to ${RUNNER_TEMP}/gh-aw for MCP server containerization\nmkdir -p \"${RUNNER_TEMP}/gh-aw\"\nGH_AW_BIN=\"\"\nGH_AW_BIN=$(command -v gh-aw 2>/dev/null) || true\nif [ -z \"$GH_AW_BIN\" ]; then\n GH_AW_BIN=$(find \"${HOME}/.local/share/gh/extensions/gh-aw\" -name 'gh-aw' -type f 2>/dev/null | head -1) || true\nfi\nif [ -n \"$GH_AW_BIN\" ] && [ -f \"$GH_AW_BIN\" ]; then\n cp \"$GH_AW_BIN\" \"${RUNNER_TEMP}/gh-aw/gh-aw\"\n chmod +x \"${RUNNER_TEMP}/gh-aw/gh-aw\"\n echo \"Copied gh-aw binary to ${RUNNER_TEMP}/gh-aw/gh-aw\"\nelse\n echo \"::error::Failed to find gh-aw binary for MCP server\"\n exit 1\nfi\n" - name: Setup Python environment run: "# Create working directory for Python scripts\nmkdir -p /tmp/gh-aw/python\nmkdir -p /tmp/gh-aw/python/data\nmkdir -p /tmp/gh-aw/python/charts\nmkdir -p /tmp/gh-aw/python/artifacts\n\necho \"Python environment setup complete\"\necho \"Working directory: /tmp/gh-aw/python\"\necho \"Data directory: /tmp/gh-aw/python/data\"\necho \"Charts directory: /tmp/gh-aw/python/charts\"\necho \"Artifacts directory: /tmp/gh-aw/python/artifacts\"\n" - name: Install Python scientific libraries diff --git a/.github/workflows/copilot-token-optimizer.lock.yml b/.github/workflows/copilot-token-optimizer.lock.yml index 79c927d6e11..f6f2767923f 100644 --- a/.github/workflows/copilot-token-optimizer.lock.yml +++ b/.github/workflows/copilot-token-optimizer.lock.yml @@ -392,7 +392,12 @@ jobs: env: GH_TOKEN: ${{ github.token }} - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Install npm dependencies run: cd actions/setup/js && npm ci - name: Install development dependencies diff --git a/.github/workflows/shared/mcp/gh-aw.md b/.github/workflows/shared/mcp/gh-aw.md index 995d496e4b0..69c6862e96f 100644 --- a/.github/workflows/shared/mcp/gh-aw.md +++ b/.github/workflows/shared/mcp/gh-aw.md @@ -19,7 +19,7 @@ steps: # Install gh-aw if not already available if ! gh aw --version >/dev/null 2>&1; then echo "Installing gh-aw extension..." - curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + gh extension install github/gh-aw fi gh aw --version # Copy the gh-aw binary to ${RUNNER_TEMP}/gh-aw for MCP server containerization diff --git a/create.md b/create.md index e3fee20bbc7..1695fb2de84 100644 --- a/create.md +++ b/create.md @@ -19,7 +19,11 @@ gh extension upgrade aw to upgrade to latest. If it is not installed, run the installation script from the main branch of the gh-aw repository: ```bash -curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh | bash +INSTALL_SCRIPT=$(mktemp) +curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" +chmod +x "$INSTALL_SCRIPT" +"$INSTALL_SCRIPT" +rm -f "$INSTALL_SCRIPT" ``` **What this does**: Downloads and installs the gh-aw binary to `~/.local/share/gh/extensions/gh-aw/` diff --git a/debug.md b/debug.md index 213b7dec376..ce98482c250 100644 --- a/debug.md +++ b/debug.md @@ -45,7 +45,11 @@ gh extension upgrade aw to upgrade to latest. If it is not installed, run the installation script from the main branch of the gh-aw repository: ```bash -curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh | bash +INSTALL_SCRIPT=$(mktemp) +curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" +chmod +x "$INSTALL_SCRIPT" +"$INSTALL_SCRIPT" +rm -f "$INSTALL_SCRIPT" ``` **What this does**: Downloads and installs the gh-aw binary to `~/.local/share/gh/extensions/gh-aw/` diff --git a/install.md b/install.md index 3d4ca9f1b35..bc59eab984e 100644 --- a/install.md +++ b/install.md @@ -15,7 +15,11 @@ Configure this repository to use agentic workflows by: Run the installation script from the main branch of the gh-aw repository: ```bash -curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh | bash +INSTALL_SCRIPT=$(mktemp) +curl -sL https://raw.githubusercontent.com/github/gh-aw/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" +chmod +x "$INSTALL_SCRIPT" +"$INSTALL_SCRIPT" +rm -f "$INSTALL_SCRIPT" ``` **What this does**: Downloads and installs the gh-aw binary to `~/.local/share/gh/extensions/gh-aw/` diff --git a/pkg/cli/copilot_setup.go b/pkg/cli/copilot_setup.go index c7071672cad..12db39cb89b 100644 --- a/pkg/cli/copilot_setup.go +++ b/pkg/cli/copilot_setup.go @@ -81,7 +81,7 @@ jobs: `, actionRepo, actionRef, version) } - // Default (dev/script mode): use curl to download install script + // Default (dev/script mode): download install script to temp file and execute return `name: "Copilot Setup Steps" # This workflow configures the environment for GitHub Copilot Agent with gh-aw MCP server @@ -104,7 +104,11 @@ jobs: steps: - name: Install gh-aw extension run: | - curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" ` } @@ -130,7 +134,11 @@ jobs: steps: - name: Install gh-aw extension run: | - curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" ` // CopilotWorkflowStep represents a GitHub Actions workflow step for Copilot setup scaffolding @@ -287,7 +295,11 @@ func renderCopilotSetupUpdateInstructions(filePath string, actionMode workflow.A } else { fmt.Fprintln(os.Stderr, " - name: Install gh-aw extension") fmt.Fprintln(os.Stderr, " run: |") - fmt.Fprintln(os.Stderr, " curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash") + fmt.Fprintln(os.Stderr, " INSTALL_SCRIPT=$(mktemp)") + fmt.Fprintln(os.Stderr, " curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o \"$INSTALL_SCRIPT\"") + fmt.Fprintln(os.Stderr, " chmod +x \"$INSTALL_SCRIPT\"") + fmt.Fprintln(os.Stderr, " \"$INSTALL_SCRIPT\"") + fmt.Fprintln(os.Stderr, " rm -f \"$INSTALL_SCRIPT\"") } fmt.Fprintln(os.Stderr) } diff --git a/pkg/cli/copilot_setup_test.go b/pkg/cli/copilot_setup_test.go index 84c801d7e88..e4de7547280 100644 --- a/pkg/cli/copilot_setup_test.go +++ b/pkg/cli/copilot_setup_test.go @@ -46,6 +46,9 @@ func TestEnsureCopilotSetupSteps(t *testing.T) { if !strings.Contains(string(content), "curl -fsSL") { t.Error("Expected workflow to contain curl command") } + if strings.Contains(string(content), "install-gh-aw.sh | bash") { + t.Error("Expected workflow to NOT pipe install script directly to bash (use temp file instead)") + } }, }, { @@ -524,6 +527,11 @@ func TestEnsureCopilotSetupSteps_DevMode(t *testing.T) { t.Error("Expected copilot-setup-steps.yml to use install-gh-aw.sh in dev mode") } + // Verify it uses the secure temp-file pattern, not pipe-to-bash + if strings.Contains(contentStr, "install-gh-aw.sh | bash") { + t.Error("Expected copilot-setup-steps.yml to NOT pipe install script directly to bash (use temp file instead)") + } + // Verify it doesn't use actions/setup-cli if strings.Contains(contentStr, "actions/setup-cli") { t.Error("Expected copilot-setup-steps.yml to NOT use actions/setup-cli in dev mode") @@ -604,6 +612,9 @@ func TestEnsureCopilotSetupSteps_CreateWithDevMode(t *testing.T) { if !strings.Contains(contentStr, "install-gh-aw.sh") { t.Errorf("Expected install-gh-aw.sh reference in dev mode") } + if strings.Contains(contentStr, "install-gh-aw.sh | bash") { + t.Errorf("Expected dev mode to NOT pipe install script directly to bash (use temp file instead)") + } if strings.Contains(contentStr, "actions/setup-cli") { t.Errorf("Did not expect actions/setup-cli in dev mode") } diff --git a/pkg/cli/devcontainer.go b/pkg/cli/devcontainer.go index bf2eedfb972..cbad380727f 100644 --- a/pkg/cli/devcontainer.go +++ b/pkg/cli/devcontainer.go @@ -152,7 +152,7 @@ func ensureDevcontainerConfig(verbose bool, additionalRepos []string) error { // Update postCreateCommand if not set or if it doesn't include gh-aw install if config.PostCreateCommand == "" || !strings.Contains(config.PostCreateCommand, "install-gh-aw.sh") { - ghAwInstall := "curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash" + ghAwInstall := "INSTALL_SCRIPT=$(mktemp) && curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o \"$INSTALL_SCRIPT\" && chmod +x \"$INSTALL_SCRIPT\" && \"$INSTALL_SCRIPT\" && rm -f \"$INSTALL_SCRIPT\"" if config.PostCreateCommand == "" { config.PostCreateCommand = ghAwInstall } else { @@ -185,7 +185,7 @@ func ensureDevcontainerConfig(verbose bool, additionalRepos []string) error { "ghcr.io/devcontainers/features/github-cli:1": map[string]any{}, "ghcr.io/devcontainers/features/copilot-cli:latest": map[string]any{}, }, - PostCreateCommand: "curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash", + PostCreateCommand: "INSTALL_SCRIPT=$(mktemp) && curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o \"$INSTALL_SCRIPT\" && chmod +x \"$INSTALL_SCRIPT\" && \"$INSTALL_SCRIPT\" && rm -f \"$INSTALL_SCRIPT\"", } if verbose { diff --git a/pkg/parser/yaml_import_copilot_setup_test.go b/pkg/parser/yaml_import_copilot_setup_test.go index 09e3de88d4a..6f8bc43fc6e 100644 --- a/pkg/parser/yaml_import_copilot_setup_test.go +++ b/pkg/parser/yaml_import_copilot_setup_test.go @@ -67,7 +67,7 @@ func TestExtractStepsFromCopilotSetup(t *testing.T) { "steps": []any{ map[string]any{ "name": "Install gh-aw extension", - "run": "curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash", + "run": "INSTALL_SCRIPT=$(mktemp)\ncurl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o \"$INSTALL_SCRIPT\"\nchmod +x \"$INSTALL_SCRIPT\"\n\"$INSTALL_SCRIPT\"\nrm -f \"$INSTALL_SCRIPT\"\n", }, map[string]any{ "name": "Checkout code", @@ -154,7 +154,7 @@ func TestExtractStepsFromCopilotSetup_StripsCheckoutStep(t *testing.T) { "steps": []any{ map[string]any{ "name": "Install gh-aw extension", - "run": "curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash", + "run": "INSTALL_SCRIPT=$(mktemp)\ncurl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o \"$INSTALL_SCRIPT\"\nchmod +x \"$INSTALL_SCRIPT\"\n\"$INSTALL_SCRIPT\"\nrm -f \"$INSTALL_SCRIPT\"\n", }, map[string]any{ "name": "Checkout code", @@ -318,7 +318,12 @@ jobs: contents: read steps: - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Checkout code uses: actions/checkout@v4 - name: Set up Node.js @@ -411,7 +416,12 @@ jobs: contents: read steps: - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Set up Node.js uses: actions/setup-node@v4 with: diff --git a/pkg/workflow/copilot_setup_import_test.go b/pkg/workflow/copilot_setup_import_test.go index b043489641f..bc51d2f1384 100644 --- a/pkg/workflow/copilot_setup_import_test.go +++ b/pkg/workflow/copilot_setup_import_test.go @@ -33,7 +33,12 @@ jobs: contents: read steps: - name: Install gh-aw extension - run: curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash + run: | + INSTALL_SCRIPT=$(mktemp) + curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh -o "$INSTALL_SCRIPT" + chmod +x "$INSTALL_SCRIPT" + "$INSTALL_SCRIPT" + rm -f "$INSTALL_SCRIPT" - name: Set up Node.js uses: actions/setup-node@v4 with: