github-actions[bot] commented on code in PR #40561: URL: https://github.com/apache/beam/pull/40561#discussion_r4263945334
########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] Review Comment: **🟡 Medium**: `pull_request_target` with `types: [opened, reopened, ready_for_review]` will trigger even when a PR is opened as a draft, and having both `pull_request` and `pull_request_target` causes duplicate runs when `.github/workflows/gemini_code_review.yml` is modified (plus `pull_request` runs from forks will fail at the `Post PR Review to GitHub` step due to read-only `GITHUB_TOKEN` permissions). Consider filtering out draft PRs in the job `if` condition (e.g., `if: github.repository == 'apache/beam' && !github.event.pull_request.draft`) and removing the redundant `pull_request` trigger once testing is complete. ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", + "run_shell_command(curl)" + ] + } + } + EOF + + cat << 'EOF' > prompt_template.txt + You are an autonomous Apache Beam code review agent running on the Gemini Enterprise Agent Platform. + Review Pull Request: __PR_URL__ + + Respond with ONLY a single valid JSON object matching this exact schema (no markdown prose outside the JSON): + { + "summary": "## 📋 Review Summary\n\n2-3 sentence high-level assessment.\n\n## 🔍 General Feedback\n- Key architectural or cross-file observations.", + "comments": [ + { + "path": "relative/path/to/file.ext", + "line": 123, + "side": "RIGHT", + "severity": "🟠 High", + "body": "Clear explanation of why this is an issue and how to fix it.", + "suggestion": "optional exact replacement line(s) without backticks, or null" + } + ] + } + EOF + sed "s|__PR_URL__|${PR_URL}|g" prompt_template.txt > prompt.txt + + npx --yes @google/gemini-cli@latest \ + --yolo \ + --model "${GEMINI_MODEL}" \ + --prompt "$(cat prompt.txt)" \ + --output-format json \ + < /dev/null \ + > gemini_raw_output.json + + if jq -e . gemini_raw_output.json >/dev/null 2>&1; then + jq -r '.response // ""' gemini_raw_output.json > gemini_response.txt + else + cp gemini_raw_output.json gemini_response.txt + fi + + - name: Post PR Review to GitHub + uses: actions/github-script@v9 Review Comment: **🟡 Medium**: If the `gemini_review` step fails or times out after partially writing `gemini_response.txt` in a previous run on a persistent self-hosted runner workspace, stale files could remain in the working directory. Write intermediate files (`prompt.txt`, `gemini_raw_output.json`, `gemini_response.txt`) to `${RUNNER_TEMP}` or clean them up in an `always()` step. ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", Review Comment: **🟠 High**: Enabling `run_shell_command(curl)` alongside `--yolo` while reviewing untrusted PR contents on a self-hosted runner with GCP credentials exposes a prompt-injection vector where crafted PR descriptions or diffs could instruct the agent to exfiltrate environment/metadata tokens or make arbitrary POST requests via `curl`. Since `web_fetch` is already enabled for reading GitHub PR URLs, remove `run_shell_command(curl)` unless strictly required. ```suggestion "web_fetch" ``` ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", + "run_shell_command(curl)" + ] + } + } + EOF + + cat << 'EOF' > prompt_template.txt + You are an autonomous Apache Beam code review agent running on the Gemini Enterprise Agent Platform. + Review Pull Request: __PR_URL__ + + Respond with ONLY a single valid JSON object matching this exact schema (no markdown prose outside the JSON): + { + "summary": "## 📋 Review Summary\n\n2-3 sentence high-level assessment.\n\n## 🔍 General Feedback\n- Key architectural or cross-file observations.", + "comments": [ + { + "path": "relative/path/to/file.ext", + "line": 123, + "side": "RIGHT", + "severity": "🟠 High", + "body": "Clear explanation of why this is an issue and how to fix it.", + "suggestion": "optional exact replacement line(s) without backticks, or null" + } + ] + } + EOF + sed "s|__PR_URL__|${PR_URL}|g" prompt_template.txt > prompt.txt + + npx --yes @google/gemini-cli@latest \ Review Comment: **🟠 High**: Using `@google/gemini-cli@latest` in a privileged `pull_request_target` workflow on self-hosted runners introduces supply-chain and reproducibility risks if a breaking or compromised version is published to npm. Pin `@google/gemini-cli` to a specific vetted version. ```suggestion npx --yes @google/[email protected] \ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
