Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Controller/GitHubSyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ private function outcomeResponse(array $result, int $okStatus): JSONResponse
GitHubAppSyncService::OUTCOME_NOT_LINKED, 'version_not_found' => Http::STATUS_BAD_REQUEST,
GitHubAppSyncService::OUTCOME_PUSH_CONFLICT => Http::STATUS_CONFLICT,
GitHubAppSyncService::OUTCOME_BROKER_UNAVAILABLE, GitHubAppSyncService::OUTCOME_BROKER_DENIED => Http::STATUS_FORBIDDEN,
// GitHub refused on permissions grounds — a 403 answer, not a 502
// transport failure. Reporting it as a gateway error is what sends
// the reader at the network instead of at the token's scopes.
GitHubAppSyncService::OUTCOME_FORBIDDEN => Http::STATUS_FORBIDDEN,
default => Http::STATUS_BAD_GATEWAY,
};

Expand Down
38 changes: 37 additions & 1 deletion lib/Service/GitHubAppSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class GitHubAppSyncService
*/
public const OUTCOME_UNREACHABLE = 'github_unreachable';

/**
* Outcome: GitHub refused the call on permissions grounds (HTTP 403).
*
* Distinct from a transport failure. Publishing a generated app needs a
* credential carrying the `workflow` permission, because the scaffold always
* emits `.github/workflows/*` and GitHub rejects a tree containing those
* without it.
*/
public const OUTCOME_FORBIDDEN = 'github_forbidden';

/**
* Constructor.
*
Expand Down Expand Up @@ -1199,7 +1209,13 @@ private function brokerJson(string $method, string $path, ?array $body, string $
$actingUserId
);
} catch (Throwable $e) {
$this->logger->debug('OpenBuild GitHub sync: broker call denied/failed for '.$method.' '.$path);
// At `debug` this is invisible on any instance running a normal
// loglevel, which leaves an operator with a bare 502 and nothing to
// go on. The exception message is the whole diagnosis; log it.
$this->logger->warning(
'OpenBuild GitHub sync: broker call failed for '.$method.' '.$path
.' — '.get_class($e).': '.$e->getMessage()
);
return ['ok' => false, 'denied' => true, 'status' => 0, 'data' => []];
}

Expand All @@ -1209,6 +1225,17 @@ private function brokerJson(string $method, string $path, ?array $body, string $
$decoded = [];
}

if ($status < 200 || $status >= 300) {
// GitHub's own message is precise and actionable ("Resource not
// accessible by personal access token", "Not Found", a rate-limit
// notice); discarding it and reporting only `github_unreachable`
// sends the reader at the network instead of the real cause.
$this->logger->warning(
'OpenBuild GitHub sync: '.$method.' '.$path.' returned '.$status
.' — '.substr((string) ($response['body'] ?? ''), 0, 300)
);
}

return [
'ok' => ($status >= 200 && $status < 300),
'denied' => false,
Expand All @@ -1230,6 +1257,15 @@ private function brokerFailureOutcome(array $result): string
return self::OUTCOME_BROKER_DENIED;
}

// A 403 from GitHub is a permissions answer, not a transport failure.
// The common case is a token without the `workflow` permission: the
// generated scaffold ships `.github/workflows/*`, and GitHub refuses the
// whole tree with "Resource not accessible by personal access token".
// Reporting that as "unreachable" is what makes it hard to diagnose.
if ($result['status'] === 403) {
return self::OUTCOME_FORBIDDEN;
}

return self::OUTCOME_UNREACHABLE;
}//end brokerFailureOutcome()

Expand Down
Loading