Conversation
| name: Secrets Demo | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| JOB_NAME: "secrets" | ||
| steps: | ||
| - name: Echo environment variable | ||
| run: echo "The value of $JOB_NAME is $API_CSPROJ_PATH" | ||
|
|
||
| new_job: |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 months ago
To fix the problem, explicitly declare the permissions block at the workflow level, setting the minimal required permissions for the jobs. Since the two jobs in this workflow ("secrets" and "new_job") do not interact with repository contents, issues, or pull requests, the safest, least-privilege choice is contents: read. This denies write access, reducing attack surface. The change should occur at the root of the workflow file—immediately following the name: and on: keys but before the env: or jobs: definitions. No changes to functionality are induced; the jobs will retain required access to environment variables and run steps as before.
| @@ -4,6 +4,9 @@ | ||
| pull_request: | ||
| branches: ["main"] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| API_CSPROJ_PATH: "./src/GithubActionsDotnet.Api/GithubActionsDotnet.Api.csproj" | ||
|
|
| name: Secrets Demo | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| JOB_NAME: "new_job" | ||
| steps: | ||
| - name: Echo environment variable | ||
| run: echo "The value of $JOB_NAME is $API_CSPROJ_PATH" |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 months ago
To fix this issue, add a permissions block at the workflow root or job level, specifying the least required privileges. In this workflow, the jobs simply echo environment variables and use curl, so neither requires any write access to the repository. The best practice is to add the following block at the top level (applies to all jobs unless individually overridden):
permissions:
contents: readThis should be placed just below the name field and prior to on. Alternatively, you could add it within each job, but for conciseness and maintainability, the root-level block is preferred. No new imports or definitions are needed.
| @@ -1,4 +1,6 @@ | ||
| name: Secrets workflow | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: |
No description provided.