KnpLabs / KnpLabs/php-github-api
Bug Report: downloadLogs() fails with Azure Authentication Error
- Ngôn ngữ chính
- PHP
- Star
- 2.2k
- Fork
- 587
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## Description
The `downloadLogs()` method in the WorkflowJobs and WorkflowRuns API fails when attempting to download GitHub Actions job logs. Instead of returning the log data, it fails with an Azure Blob Storage authentication error.
## Environment
- **Library version**: `knplabs/github-api` 3.16.0
- **PHP version**: 8.x
- **HTTP client**: Guzzle 7.10.0 (via PSR-18 discovery)
## Expected Behavior
Calling `downloadLogs()` should return the ZIP archive containing the job logs as documented in the library's API.
## Actual Behavior
The method throws an exception or returns an XML error response from Azure Blob Storage:
```xml
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
```
## Root Cause
The GitHub API endpoint `/repos/{owner}/{repo}/actions/jobs/{job_id}/logs` returns a **302 redirect** to an Azure Blob Storage URL with a pre-signed SAS token in the query parameters.
The issue occurs because:
1. **HTTPlug's `RedirectPlugin` is used** by default in the library (added in `Client.php`)
2. **The RedirectPlugin preserves ALL headers by default** (`preserve_header: true`)
3. When following the redirect to Azure Blob Storage, the **GitHub `Authorization` header is sent to Azure**
4. Azure Blob Storage doesn't understand GitHub's authentication format and rejects the request
5. Unlike Guzzle's native `RedirectMiddleware` (which strips `Authorization` and `Cookie` headers on cross-origin redirects), HTTPlug's `RedirectPlugin` has no such protection
## Reproduction Steps
1. Set up GitHub API client with valid authentication token
2. Get a valid job ID from a workflow run
3. Call `downloadLogs()` on that job ID
4. Observe the Azure authentication error
## References
- GitHub API docs: https://docs.github.com/en/rest/actions/workflow-jobs#download-job-logs-for-a-workflow-run
- Guzzle's RedirectMiddleware (strips auth headers): https://github.com/guzzle/guzzle/blob/master/src/RedirectMiddleware.php#L174-L177
- HTTPlug RedirectPlugin (preserves all headers): https://github.com/php-http/client-common/blob/master/src/Plugin/RedirectPlugin.php
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Start in Client.php, where the HTTPlug RedirectPlugin is added, and review the linked RedirectPlugin and Guzzle RedirectMiddleware behavior. Reproduce downloadLogs() with a workflow job, then verify that following the Azure redirect no longer sends the GitHub Authorization header and returns the logs archive successfully.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- github-actions, php
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 48/100