Skip to content

Pipeline Artifact API provides upload action with external app URL #32554

Closed
@jannispl

Description

@jannispl

Description

My setup is powered by Docker Compose, and I have Gitea and a Gitea Runner instance in the same Docker network. New task containers are also in this network, this is done by setting container.network: "gitea_default" in the runner configuration file.
There is an external reverse proxy pointing at Gitea for requests from outside. Internal requests are supposed to fail because of a IP allowlist - and I cannot allow the internal Gitea network. Thus, I have to rely on LOCAL_ROOT_URL to be used for all internal communication.

Unfortunately, it seems that when using the actions/upload-artifact@v3 action, the runner tries to access Gitea using the external ROOT_URL: (this is with ACTIONS_STEP_DEBUG=true)

followSymbolicLinks '***'
implicitDescendants '***'
omitBrokenSymbolicLinks '***'
excludeHiddenFiles '***'
followSymbolicLinks '***'
implicitDescendants '***'
matchDirectories '***'
omitBrokenSymbolicLinks '***'
excludeHiddenFiles '***'
Search path '/workspace/user/repo/test.txt'
File:/workspace/user/repo/test.txt was found using the provided searchPath
With the provided path, there will be 1 file uploaded
Root artifact directory is /workspace/user/repo
Starting artifact upload
For more detailed logs during the artifact upload process, enable step-debugging: https://docs.github.com/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging
Artifact name is valid!
Artifact Url: http://gitea:3000/api/actions_pipeline/_apis/pipelines/workflows/12/artifacts?api-version=6.0-preview
Upload Resource URL: https://git.example.org/api/actions_pipeline/_apis/pipelines/workflows/12/artifacts/dd18bf3a8e0a2a3e53e2661c7fb53534/upload
Container for artifact "test.txt" successfully created. Starting upload of file(s)
File Concurrency: 2, and Chunk Size: 8388608
/workspace/user/repo/test.txt is less than 64k in size. Creating a gzip file in-memory to potentially reduce the upload size
The gzip file created for /workspace/user/repo/test.txt did not help with reducing the size of the file. The original file will be uploaded as-is
::error::Unexpected response. Unable to upload chunk to https://git.example.org/api/actions_pipeline/_apis/pipelines/workflows/12/artifacts/dd18bf3a8e0a2a3e53e2661c7fb53534/upload?itemPath=test.txt%252Ftest.txt
##### Begin Diagnostic HTTP information #####
Status Code: 403
Status Message: Forbidden
Header Information: {
  "date": "Mon, 18 Nov 2024 21:34:19 GMT",
  "content-length": "9"
}
###### End Diagnostic HTTP information ######
::warning::Aborting upload for /workspace/user/repo/test.txt due to failure
::error::aborting artifact upload
Total size of all the files uploaded is 0 bytes
File upload process has finished. Finalizing the artifact upload
Artifact Url: http://gitea:3000/api/actions_pipeline/_apis/pipelines/workflows/12/artifacts?api-version=6.0-preview
URL is http://gitea:3000/api/actions_pipeline/_apis/pipelines/workflows/12/artifacts?api-version=6.0-preview&artifactName=test.txt
Finalize artifact upload - Attempt 1 of 5 failed with error: Artifact service responded with 500
...

As you can see, Upload Resource URL is resolved based on ROOT_URL rather than LOCAL_ROOT_URL. A similar error appears with (the patched variant of) v4.

I took a look at the source code for actions/upload-artifact@v3 and stumbled upon this: https://github.com/actions/toolkit/blob/%40actions/artifact%401.1.1/packages/artifact/src/internal/artifact-client.ts#L118

Here, it appears the URL is provided by an API endpoint. In Gitea, the fileContainerResourceUrl is computed here: https://github.com/go-gitea/gitea/blob/main/modules/httplib/url.go#L61

It seems to account for the Host header here, but only if the request is coming from a reverse proxy (X-Forwarded-Proto present).
I realized I can workaround this problem by running an additional reverse proxy for internal requests, but I'd rather avoid that.

Gitea Version

1.22.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

docker compose

How are you running Gitea?

I am using official Gitea Docker images on the latest tag.

Database

SQLite

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions