Skip to content

Conversation

@laurentC35
Copy link
Collaborator

No description provided.

Comment on lines +11 to +39
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build project
run: pnpm build

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: pearl-jam
path: dist

docker:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 1 day ago

In general, the fix is to explicitly define a permissions: block to restrict the GITHUB_TOKEN to the minimum scopes required. Since this workflow only needs to read the repository contents (for actions/checkout and build context) and does not use GITHUB_TOKEN to perform any write operations, we can safely set contents: read as the only permission. We can define this either at the workflow root (applying to all jobs) or per job. The simplest and clearest is to add a workflow-level permissions: block directly under the name: line.

Concretely, in .github/workflows/early-docker-image.yml, insert:

permissions:
  contents: read

between the existing name: Early Docker image publishing and on: keys. This will apply to both build and docker jobs. No other code, steps, or secrets handling needs to change, and no imports or external dependencies are required.

Suggested changeset 1
.github/workflows/early-docker-image.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/early-docker-image.yml b/.github/workflows/early-docker-image.yml
--- a/.github/workflows/early-docker-image.yml
+++ b/.github/workflows/early-docker-image.yml
@@ -1,5 +1,8 @@
 name: Early Docker image publishing
 
+permissions:
+  contents: read
+
 on:
   push:
     branches-ignore:
EOF
@@ -1,5 +1,8 @@
name: Early Docker image publishing

permissions:
contents: read

on:
push:
branches-ignore:
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +40 to +91
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/') &&
github.ref != 'refs/heads/main' &&
github.ref != 'refs/heads/develop'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: pearl-jam
path: dist

- name: Debug runner filesystem
run: |
ls -al .
echo "Listing root /"
ls -al /
echo "Listing repository checkout directory"
ls -al $GITHUB_WORKSPACE
echo "Listing dist artifact folder"
ls -al dist

- name: Read project version from package.json
id: version
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: '.'
platforms: linux/amd64,linux/arm64
push: true
tags: |
inseefr/pearl-jam:${{ github.ref_name }}-${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max No newline at end of file

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 1 day ago

In general, the fix is to add a permissions block that limits the GITHUB_TOKEN to the minimum required scopes. For workflows that only need to read repository contents (e.g., checkout, builds, and publishing to external registries with secrets), the minimal suitable setting is usually contents: read at the workflow or job level. This documents the intended permissions and prevents unintended write access if repository defaults are broad.

For this specific workflow in .github/workflows/early-docker-image.yml, neither the build nor docker job needs to write to the repository via the GITHUB_TOKEN; they only read source code and use secrets to log in to Docker Hub, plus GitHub’s artifact storage. Therefore, the best fix is to add a top-level permissions section after the name: (or after on:) with contents: read. This will apply to both jobs since they don’t define their own permissions. No additional imports or actions are required, and existing functionality will be unchanged because none of the steps currently rely on write permissions to the repository.

Concretely:

  • Edit .github/workflows/early-docker-image.yml.
  • Insert:
    permissions:
      contents: read
    near the top-level of the workflow (e.g., between name: and on: or between on: and jobs:).
  • Do not modify any steps, actions, or other configuration.
Suggested changeset 1
.github/workflows/early-docker-image.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/early-docker-image.yml b/.github/workflows/early-docker-image.yml
--- a/.github/workflows/early-docker-image.yml
+++ b/.github/workflows/early-docker-image.yml
@@ -1,5 +1,8 @@
 name: Early Docker image publishing
 
+permissions:
+  contents: read
+
 on:
   push:
     branches-ignore:
EOF
@@ -1,5 +1,8 @@
name: Early Docker image publishing

permissions:
contents: read

on:
push:
branches-ignore:
Copilot is powered by AI and may make mistakes. Always verify output.
@sonarqubecloud
Copy link

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.

4 participants