Conversation
# Conflicts: # packaging/build_packages.sh # packaging/debian_files/changelog # pg_documentdb/src/commands/users.c
| name: Test | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 15 | ||
|
|
||
| # Do not run this job in parallel for any PR change or branch push. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} | ||
| cancel-in-progress: true | ||
|
|
||
| if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready') | ||
|
|
||
| steps: | ||
| # TODO https://github.com/FerretDB/github-actions/issues/211 | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Go | ||
| uses: FerretDB/github-actions/setup-go@main | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| cd ferretdb_packaging | ||
| go mod tidy | ||
| go mod verify | ||
| go test ./... | ||
|
|
||
| - name: Check dirty | ||
| if: always() | ||
| run: | | ||
| git status --untracked-files --ignored | ||
| git status | ||
| git diff --exit-code |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, we need to add a permissions block to the workflow or job to explicitly limit the permissions of the GITHUB_TOKEN. Since the workflow only requires read access to repository contents, we can set contents: read at the job level. This ensures the workflow has the minimal permissions necessary to complete its tasks.
The changes will be made in the .github/workflows/ferretdb_go_tests.yml file:
- Add a
permissionsblock under thetestjob. - Set
contents: readas the permission.
| @@ -30,2 +30,4 @@ | ||
| timeout-minutes: 15 | ||
| permissions: | ||
| contents: read | ||
|
|
| with: | ||
| name: ${{ matrix.os }}-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging/*.deb | ||
| retention-days: 1 | ||
| if-no-files-found: error |
Check failure
Code scanning / CodeQL
Cache Poisoning via execution of untrusted code High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, the workflow should avoid executing untrusted code in the context of the default branch. This can be achieved by replacing the pull_request_target event with the pull_request event, which scopes the workflow to the pull request branch instead of the default branch. Additionally, any steps that rely on untrusted code should be isolated or validated to ensure they do not introduce security vulnerabilities. Specifically:
- Replace
pull_request_targetwithpull_requestin theonsection. - Remove or adjust steps that directly use untrusted code (e.g., checkout pull request code).
- Validate any inputs derived from untrusted sources before using them in critical operations.
| @@ -25,3 +25,3 @@ | ||
| on: | ||
| pull_request_target: | ||
| pull_request: | ||
| types: | ||
| @@ -85,3 +85,3 @@ | ||
| - name: Checkout pull request code | ||
| if: github.event_name == 'pull_request_target' | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/checkout@v4 |
| - name: Initialize Docker builder | ||
| run: make -C ferretdb_packaging docker-init | ||
|
|
||
| - name: Build local development Docker image |
Check failure
Code scanning / CodeQL
Checkout of untrusted code in a privileged context Critical
| path: packaging | ||
|
|
||
| - name: Initialize Docker builder | ||
| run: make -C ferretdb_packaging docker-init |
Check failure
Code scanning / CodeQL
Artifact poisoning Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, the artifact should be extracted into a temporary directory instead of the packaging directory. This ensures that the artifact cannot override existing files. Additionally, the contents of the artifact should be verified before they are used. For example, if specific files are expected, their presence and integrity should be checked. This approach mitigates the risk of artifact poisoning.
| @@ -197,3 +197,12 @@ | ||
| name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging | ||
| path: ${{ runner.temp }}/artifacts | ||
|
|
||
| - name: Verify artifact contents | ||
| run: | | ||
| mkdir -p packaging | ||
| if [ ! -f "${{ runner.temp }}/artifacts/expected_file" ]; then | ||
| echo "Expected file not found in artifact" >&2 | ||
| exit 1 | ||
| fi | ||
| cp -r ${{ runner.temp }}/artifacts/* packaging/ | ||
|
|
| run: > | ||
| make -C ferretdb_packaging docker-build | ||
| POSTGRES_VERSION=${{ matrix.pg }} | ||
| DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }} | ||
| FILE=development | ||
| OUTPUT='type=docker' | ||
| TAGS='${{ steps.version.outputs.docker_development_tag_flags }}' |
Check failure
Code scanning / CodeQL
Artifact poisoning Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the artifact poisoning issue, the workflow should treat the downloaded artifact as untrusted and verify its contents before using it. Specifically:
- Extract the artifact to a temporary directory to prevent it from overwriting existing files.
- Verify the contents of the artifact to ensure they match the expected format or values.
- Use the verified contents in subsequent steps.
The changes will involve modifying the artifact download step to specify a temporary directory and adding a verification step before using the artifact.
| @@ -193,2 +193,5 @@ | ||
|
|
||
| - name: Create temporary directory for artifact | ||
| run: mkdir -p ${{ runner.temp }}/artifacts/ | ||
|
|
||
| - name: Download deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| @@ -197,3 +200,3 @@ | ||
| name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging | ||
| path: ${{ runner.temp }}/artifacts/ | ||
|
|
||
| @@ -205,2 +208,7 @@ | ||
| run: > | ||
| # Verify artifact contents | ||
| if [ ! -f ${{ runner.temp }}/artifacts/deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} ]; then | ||
| echo "Artifact verification failed: File not found" | ||
| exit 1 | ||
| fi | ||
| make -C ferretdb_packaging docker-build |
| run: > | ||
| make -C ferretdb_packaging docker-build | ||
| POSTGRES_VERSION=${{ matrix.pg }} | ||
| DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }} | ||
| FILE=production | ||
| OUTPUT='type=docker' | ||
| TAGS='${{ steps.version.outputs.docker_production_tag_flags }}' |
Check failure
Code scanning / CodeQL
Artifact poisoning Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, the workflow should treat the artifact as untrusted and follow best practices for handling artifacts:
- Extract the artifact into a temporary directory to prevent overwriting existing files.
- Validate the contents of the artifact before using it in any commands.
Specifically:
- Modify the
actions/download-artifactstep to extract the artifact into a temporary directory. - Add a validation step to ensure the artifact contents are as expected before proceeding with the
makecommand.
| @@ -193,2 +193,5 @@ | ||
|
|
||
| - name: Create temporary directory for artifact | ||
| run: mkdir -p ${{ runner.temp }}/packaging | ||
|
|
||
| - name: Download deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| @@ -197,3 +200,3 @@ | ||
| name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging | ||
| path: ${{ runner.temp }}/packaging | ||
|
|
||
| @@ -214,3 +217,10 @@ | ||
| if: steps.version.outputs.docker_production_tag_flags != '' | ||
| run: > | ||
| run: | | ||
| # Validate artifact contents | ||
| if [ ! -f ${{ runner.temp }}/packaging/expected_file ]; then | ||
| echo "Artifact validation failed: expected_file not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Proceed with build | ||
| make -C ferretdb_packaging docker-build |
| OUTPUT='type=docker' | ||
| TAGS='${{ steps.version.outputs.docker_production_tag_flags }}' | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ferretdbbot | ||
| password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 |
Check failure
Code scanning / CodeQL
Checkout of untrusted code in a privileged context Critical
| run: > | ||
| make -C ferretdb_packaging docker-build | ||
| POSTGRES_VERSION=${{ matrix.pg }} | ||
| DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }} | ||
| FILE=development | ||
| OUTPUT='type=image,push=true' | ||
| TAGS='${{ steps.version.outputs.docker_development_tag_flags }}' |
Check failure
Code scanning / CodeQL
Artifact poisoning Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, the workflow should treat the artifact as untrusted and isolate its contents in a temporary directory. Additionally, the contents of the artifact should be verified before use. This involves:
- Creating a temporary directory for artifact extraction.
- Modifying the
actions/download-artifactstep to extract the artifact into the temporary directory. - Adding a verification step to ensure the artifact's contents are as expected before proceeding with the Docker build.
| @@ -193,2 +193,5 @@ | ||
|
|
||
| - name: Create temporary directory for artifact | ||
| run: mkdir -p ${{ runner.temp }}/artifacts | ||
|
|
||
| - name: Download deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| @@ -197,3 +200,3 @@ | ||
| name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging | ||
| path: ${{ runner.temp }}/artifacts | ||
|
|
||
| @@ -245,2 +248,8 @@ | ||
| run: > | ||
| # Verify artifact contents | ||
| if [ ! -f ${{ runner.temp }}/artifacts/deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} ]; then | ||
| echo "Artifact verification failed: File not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| make -C ferretdb_packaging docker-build |
| run: > | ||
| make -C ferretdb_packaging docker-build | ||
| POSTGRES_VERSION=${{ matrix.pg }} | ||
| DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }} | ||
| FILE=production | ||
| OUTPUT='type=image,push=true' | ||
| TAGS='${{ steps.version.outputs.docker_production_tag_flags }}' |
Check failure
Code scanning / CodeQL
Artifact poisoning Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the artifact poisoning issue, the workflow should treat the downloaded artifact as untrusted and isolate its contents. Specifically:
- Extract the artifact to a temporary directory to prevent overwriting existing files.
- Verify the contents of the artifact before using them in subsequent steps.
- Ensure that any untrusted inputs (e.g.,
matrix.pgandsteps.version.outputs.debian_version) are sanitized or validated.
The changes will involve modifying the artifact download step to specify a temporary directory and adding a verification step to check the artifact's contents before proceeding.
| @@ -197,3 +197,11 @@ | ||
| name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }} | ||
| path: packaging | ||
| path: ${{ runner.temp }}/packaging | ||
|
|
||
| - name: Verify artifact contents | ||
| run: | | ||
| if [ ! -f "${{ runner.temp }}/packaging/expected_file" ]; then | ||
| echo "Artifact verification failed: expected file not found." | ||
| exit 1 | ||
| fi | ||
| # Additional verification logic can be added here | ||
|
|
||
| @@ -261,2 +269,4 @@ | ||
| TAGS='${{ steps.version.outputs.docker_production_tag_flags }}' | ||
| ARTIFACT_DIR=${{ runner.temp }}/packaging | ||
| # Ensure the artifact directory is used securely | ||
|
|
| make -C ferretdb_packaging docker-build | ||
| POSTGRES_VERSION=${{ matrix.pg }} | ||
| DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }} | ||
| FILE=production | ||
| OUTPUT='type=image,push=true' | ||
| TAGS='${{ steps.version.outputs.docker_production_tag_flags }}' | ||
|
|
||
| - name: Check dirty | ||
| run: | | ||
| git status | ||
| git diff --exit-code |
Check failure
Code scanning / CodeQL
Checkout of untrusted code in a privileged context Critical
|
@AlekSi this pull request has merge conflicts. |
No description provided.