Browse Source

fix: try to fix most of the code scanning issues (#5812)

Gergely Bräutigam 2 months ago
parent
commit
c041873b61

+ 8 - 2
.github/workflows/ci.yml

@@ -14,6 +14,9 @@ env:
   # Sonar
   # Sonar
   SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
   SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
 
 
+permissions:
+  contents: read
+
 jobs:
 jobs:
   detect-noop:
   detect-noop:
     permissions:
     permissions:
@@ -37,8 +40,7 @@ jobs:
 
 
   license-check:
   license-check:
     permissions:
     permissions:
-      contents: read  # for actions/checkout to fetch code
-      pull-requests: read  # for golangci/golangci-lint-action to fetch pull requests
+      contents: read
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     needs: detect-noop
     needs: detect-noop
     if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
     if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
@@ -56,6 +58,8 @@ jobs:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     needs: detect-noop
     needs: detect-noop
     if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
     if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
+    permissions:
+      contents: read
 
 
     steps:
     steps:
       - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
       - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
@@ -89,6 +93,8 @@ jobs:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     needs: detect-noop
     needs: detect-noop
     if: needs.detect-noop.outputs.noop != 'true'
     if: needs.detect-noop.outputs.noop != 'true'
+    permissions:
+      contents: read
 
 
     steps:
     steps:
       - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
       - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0

+ 3 - 0
.github/workflows/helm.yml

@@ -7,6 +7,9 @@ on:
   pull_request:
   pull_request:
   workflow_dispatch: {}
   workflow_dispatch: {}
 
 
+permissions:
+  contents: read
+
 jobs:
 jobs:
   lint-and-test:
   lint-and-test:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest

+ 6 - 0
.github/workflows/pull-request-label.yml

@@ -8,6 +8,9 @@ on:
       - synchronize
       - synchronize
       - reopened
       - reopened
 
 
+permissions:
+  contents: read
+
 jobs:
 jobs:
   conventional-commit-labeler:
   conventional-commit-labeler:
     name: Label PR based on Conventional Commit Specification
     name: Label PR based on Conventional Commit Specification
@@ -144,6 +147,9 @@ jobs:
     needs: [labeler, size-labeler, conventional-commit-labeler]
     needs: [labeler, size-labeler, conventional-commit-labeler]
     name: verify labels
     name: verify labels
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      pull-requests: read
     steps:
     steps:
       - name: PRs should have at least one qualifying label
       - name: PRs should have at least one qualifying label
         uses: docker://agilepathway/pull-request-label-checker:latest@sha256:14f5f3dfda922496d07d53494e2d2b42885165f90677a1c03d600059b7706a61
         uses: docker://agilepathway/pull-request-label-checker:latest@sha256:14f5f3dfda922496d07d53494e2d2b42885165f90677a1c03d600059b7706a61

+ 14 - 10
.github/workflows/release.yml

@@ -37,17 +37,19 @@ jobs:
 
 
       - name: Resolve and validate ref
       - name: Resolve and validate ref
         id: resolve_ref
         id: resolve_ref
+        env:
+          SOURCE_REF: ${{ github.event.inputs.source_ref }}
         run: |
         run: |
           set -e
           set -e
           # Try to fetch the ref from remote
           # Try to fetch the ref from remote
-          if git fetch origin "${{ github.event.inputs.source_ref }}"; then
+          if git fetch origin "$SOURCE_REF"; then
             # Remote ref exists, use it
             # Remote ref exists, use it
-            RESOLVED_SHA=$(git rev-parse "origin/${{ github.event.inputs.source_ref }}")
-          elif git rev-parse --verify "${{ github.event.inputs.source_ref }}" >/dev/null 2>&1; then
+            RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
+          elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
             # Local ref exists (e.g., a tag)
             # Local ref exists (e.g., a tag)
-            RESOLVED_SHA=$(git rev-parse "${{ github.event.inputs.source_ref }}")
+            RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
           else
           else
-            echo "Error: ref '${{ github.event.inputs.source_ref }}' not found"
+            echo "Error: ref '$SOURCE_REF' not found"
             exit 1
             exit 1
           fi
           fi
           echo "Resolved to SHA: $RESOLVED_SHA"
           echo "Resolved to SHA: $RESOLVED_SHA"
@@ -78,17 +80,19 @@ jobs:
 
 
       - name: Resolve and validate ref
       - name: Resolve and validate ref
         id: resolve_ref
         id: resolve_ref
+        env:
+          SOURCE_REF: ${{ github.event.inputs.source_ref }}
         run: |
         run: |
           set -e
           set -e
           # Try to fetch the ref from remote
           # Try to fetch the ref from remote
-          if git fetch origin "${{ github.event.inputs.source_ref }}"; then
+          if git fetch origin "$SOURCE_REF"; then
             # Remote ref exists, use it
             # Remote ref exists, use it
-            RESOLVED_SHA=$(git rev-parse "origin/${{ github.event.inputs.source_ref }}")
-          elif git rev-parse --verify "${{ github.event.inputs.source_ref }}" >/dev/null 2>&1; then
+            RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
+          elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
             # Local ref exists (e.g., a tag)
             # Local ref exists (e.g., a tag)
-            RESOLVED_SHA=$(git rev-parse "${{ github.event.inputs.source_ref }}")
+            RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
           else
           else
-            echo "Error: ref '${{ github.event.inputs.source_ref }}' not found"
+            echo "Error: ref '$SOURCE_REF' not found"
             exit 1
             exit 1
           fi
           fi
           echo "Resolved to SHA: $RESOLVED_SHA"
           echo "Resolved to SHA: $RESOLVED_SHA"

+ 7 - 5
.github/workflows/release_esoctl.yml

@@ -34,17 +34,19 @@ jobs:
 
 
       - name: Resolve and validate ref
       - name: Resolve and validate ref
         id: resolve_ref
         id: resolve_ref
+        env:
+          SOURCE_REF: ${{ github.event.inputs.source_ref }}
         run: |
         run: |
           set -e
           set -e
           # Try to fetch the ref from remote
           # Try to fetch the ref from remote
-          if git fetch origin "${{ github.event.inputs.source_ref }}"; then
+          if git fetch origin "$SOURCE_REF"; then
             # Remote ref exists, use it
             # Remote ref exists, use it
-            RESOLVED_SHA=$(git rev-parse "origin/${{ github.event.inputs.source_ref }}")
-          elif git rev-parse --verify "${{ github.event.inputs.source_ref }}" >/dev/null 2>&1; then
+            RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
+          elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
             # Local ref exists (e.g., a tag)
             # Local ref exists (e.g., a tag)
-            RESOLVED_SHA=$(git rev-parse "${{ github.event.inputs.source_ref }}")
+            RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
           else
           else
-            echo "Error: ref '${{ github.event.inputs.source_ref }}' not found"
+            echo "Error: ref '$SOURCE_REF' not found"
             exit 1
             exit 1
           fi
           fi
           echo "Resolved to SHA: $RESOLVED_SHA"
           echo "Resolved to SHA: $RESOLVED_SHA"

+ 3 - 0
.github/workflows/scorecard.yml

@@ -6,6 +6,9 @@ on:
   push:
   push:
     branches: [ "main" ]
     branches: [ "main" ]
 
 
+permissions:
+  contents: read
+
 jobs:
 jobs:
   analysis:
   analysis:
     name: Scorecard analysis
     name: Scorecard analysis

+ 3 - 0
.github/workflows/update-deps.yml

@@ -7,6 +7,9 @@ on:
   workflow_dispatch:
   workflow_dispatch:
     inputs: {}
     inputs: {}
 
 
+permissions:
+  contents: read
+
 jobs:
 jobs:
   branches:
   branches:
     name: get branch data
     name: get branch data