You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
[WIP] Fix check_permissions to handle missing inherited_role field (#50183)
* Initial plan
* Resolve custom repository role base_role from org custom roles API
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
* Resolve custom role base role from GITHUB_TOKEN-readable permission field
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
* Promote repository permission diagnostics from core.debug to core.info
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
* Never let a custom repository role resolve to admin
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
* Tune permission check log levels for signal over noise
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
core.debug?.(`Repository permission API fields for '${actor}': permission='${normalizedPermission}', role='${debugRoleName}', inherited='${debugInheritedRole}'`);
280
-
core.debug?.(`Repository permission computed roles for '${actor}': effective='${effectiveRole}', custom_role=${isCustomRole}, inherited_standard_role='${debugInheritedStandardRole}'`);
281
-
if(isCustomRole&&inheritedStandardRole===""){
282
-
core.debug?.(`Repository permission fallback unavailable for custom role '${normalizedRoleName}' because GitHub did not provide an inherited standard role`);
281
+
constdebugBaseRole=resolvedBaseRole||"<empty>";
282
+
core.debug?.(`Repository permission API fields for '${actor}': permission='${normalizedPermission}', role='${debugRoleName}'`);
283
+
core.debug?.(`Repository permission computed roles for '${actor}': effective='${effectiveRole}', custom_role=${isCustomRole}, base_role='${debugBaseRole}'`);
284
+
if(isCustomRole&&normalizedPermission==="admin"){
285
+
core.warning(`Ignoring 'admin' permission reported for custom repository role '${normalizedRoleName}': custom roles cannot grant admin access`);
286
+
}
287
+
if(isCustomRole&&resolvedBaseRole===""){
288
+
core.info(`Repository permission fallback unavailable for custom role '${normalizedRoleName}' because GitHub did not report a standard permission level`);
283
289
}
284
290
285
291
// Check if user has one of the required permission levels.
286
292
// For standard roles, use role_name (precise: maintain/triage are not collapsed to
287
-
// write/read). For custom org roles, only fall back to the inherited standard role
288
-
// from custom-role metadata; fail closed if GitHub does not provide it.
293
+
// write/read). For custom org roles, fall back to the standard `permission` level that
294
+
// GitHub already computes for the actor (readable with the repository-scoped
295
+
// GITHUB_TOKEN); fail closed if it is not one of the non-admin base roles.
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission API fields for 'testuser': permission='write', role='Security Champions', inherited='write'");
340
-
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission computed roles for 'testuser': effective='Security Champions', custom_role=true, inherited_standard_role='write'");
341
-
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission matched required role 'write' via inherited-standard-role");
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission API fields for 'testuser': permission='write', role='Security Champions', inherited='<empty>'");
441
-
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission computed roles for 'testuser': effective='Security Champions', custom_role=true, inherited_standard_role='<empty>'");
442
-
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission fallback unavailable for custom role 'Security Champions' because GitHub did not provide an inherited standard role");
443
-
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission did not match required roles: write");
504
+
expect(mockCore.debug).toHaveBeenCalledWith("Repository permission computed roles for 'testuser': effective='Security Champions', custom_role=true, base_role='<empty>'");
505
+
expect(mockCore.info).toHaveBeenCalledWith("Repository permission fallback unavailable for custom role 'Security Champions' because GitHub did not report a standard permission level");
444
506
expect(mockCore.warning).toHaveBeenCalledWith("User permission 'Security Champions' does not meet requirements: write");
0 commit comments