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
Add support for enterprise installation tokens (#10)
* Add support for GitHub App enterprise installations
If accountType is enterprise (owner is mandatory ands should be filled with the enterprise slug) returns an installation id for the app installed at the enterprise level so calls can be made at enterprise level.
- Bump axios
- Bump extension and task version
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Tiago Pascoal <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Supports organization-wide, user-level, or enterprise-level tokens
12
12
- Provides multiple authentication options (service connection or direct inputs)
13
13
- Handles proxy configurations through environment variables
14
14
- Secure handling of private keys and credentials
15
15
- Cross-platform compatibility
16
16
17
17
## Prerequisites
18
18
19
-
1. A GitHub App created and installed in your organization
19
+
1. A GitHub App created and installed in your organization, user account, or enterprise
20
20
2. The GitHub App's private key (PEM format)
21
21
3. The GitHub App client ID
22
-
4. The GitHub App must be installed in the organization where you want to generate tokens
22
+
4. The GitHub App must be installed in the organization, user account, or enterprise where you want to generate tokens
23
23
24
24
## Configuration
25
25
@@ -64,9 +64,9 @@ steps:
64
64
| Parameter | Required | Description |
65
65
|-----------|----------|-------------|
66
66
| githubAppConnection | No | The GitHub App connection to use (preferred method) |
67
-
| owner | No | The GitHub organization name or user accountwhere the app is installed. If not provided, it will be automatically fetched from the `Build.Repository.Name` variable. |
68
-
| accountType | No | The type of account to use for the token. Options: `org`(organization) or `user` (user account). Default is `org`. |
69
-
| repositories | No | Comma-separated list of repositories to scope the token to. If empty, token will be scoped to all repositories (in which the app has access to) |
67
+
| owner | No | The GitHub organization name, user account, or enterprise slug where the app is installed. **Required for enterprise account type.** If not provided (for org/user), it will be automatically fetched from the `Build.Repository.Name` variable. |
68
+
| accountType | No | The type of account to use for the token. Options: `org`(organization), `user` (user account), or `enterprise` (enterprise account). Default is `org`. |
69
+
| repositories | No | Comma-separated list of repositories to scope the token to. If empty, token will be scoped to all repositories (in which the app has access to). **Not allowed for enterprise account type.** |
70
70
| appClientId | No* | The GitHub App ID (required if not using service connection) |
71
71
| certificate | No* | The PEM certificate content (required if not using service connection) |
72
72
| certificateFile | No | Alternative to certificate - filename containing the PEM content |
For GitHub Apps installed at the enterprise level:
195
+
196
+
```yaml
197
+
steps:
198
+
- task: create-github-app-token@1
199
+
name: enterpriseToken
200
+
inputs:
201
+
githubAppConnection: 'MyGitHubAppConnection'
202
+
accountType: 'enterprise'
203
+
owner: 'my-enterprise' # Enterprise slug/name (required for enterprise)
204
+
- bash: |
205
+
gh api \
206
+
--method GET -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
207
+
/enterprises/my-enterprise
208
+
displayName: 'Access enterprise using GitHub CLI'
209
+
env:
210
+
GH_TOKEN: $(enterpriseToken.installationToken)
211
+
```
212
+
213
+
### Enterprise with Direct Certificate Input
214
+
215
+
```yaml
216
+
steps:
217
+
- task: create-github-app-token@1
218
+
inputs:
219
+
accountType: 'enterprise'
220
+
owner: 'my-enterprise' # Required for enterprise account type
221
+
appClientId: 'lv2313qqwqeqweqw'
222
+
certificate: '$(githubAppPem)'
223
+
# Note: repositories input not allowed for enterprise account type
224
+
# Note: forceRepoScope not allowed for enterprise account type
225
+
```
226
+
192
227
## Proxy Support
193
228
194
229
The task automatically detects and uses proxy settings from the following environment variables:
@@ -210,6 +245,30 @@ Common issues and solutions:
210
245
- If you are trying to request `admin:read` permission, the app needs to have `admin:read` or `admin:org` in the GitHub App configuration
211
246
- The token can only have equal or lower permissions than what is configured in the GitHub App settings
212
247
248
+
### Enterprise-Specific Issues
249
+
250
+
5. **Enterprise installation not found**:
251
+
- Verify the GitHub App is installed at the enterprise level (not just organization level)
252
+
- Ensure the `owner` parameter contains the correct enterprise slug/name
253
+
- Check that the GitHub App has permissions to access enterprise resources
254
+
6. **Multiple enterprise installations found**: If you have access to multiple enterprises, specify the exact enterprise slug in the `owner` parameter
255
+
7. **Enterprise account type restrictions**:
256
+
- Cannot use `repositories` parameter with enterprise account type (tokens are enterprise-scoped)
257
+
- Cannot use `forceRepoScope` in service connections with enterprise account type
258
+
- The `owner` parameter is mandatory for enterprise account type
259
+
8. **Rate limiting during installation lookup**: Enterprise installations use pagination which may hit rate limits with many installations. The task automatically handles rate limiting by waiting if the reset time is within 5 minutes.
| Direct API lookup | ✅ Yes | ✅ Yes | ❌ Uses pagination workaround |
269
+
270
+
*Owner is optional for org/user if using GitHub repository provider (auto-extracted from Build.Repository.Name)
271
+
213
272
> [!TIP]
214
273
> If you expand the task logs, you can see extra info like the token permissions and repo access. (If you run the pipeline in debug mode it will have extra info as well).
thrownewError(`GitHub API rate limit exceeded. Reset time: ${resetTime}. Please try again later.`);
220
+
}
221
+
222
+
page++;
223
+
}
224
+
225
+
// If we reach here, the enterprise installation was not found
226
+
thrownewError(`GitHub App installation not found for app ID/client ID '${appIdOrClientId}'. Please verify the app ID/client ID and enterprise installation.`);
227
+
228
+
}catch(err: any){
229
+
letmessage='';
230
+
if(err.response&&err.response.status===401){
231
+
message=`GitHub App JWT authentication failed. Please verify the app credentials.`;
232
+
}elseif(err.response&&err.response.status===403){
233
+
message=`GitHub App does not have permission to list installations. Please verify the app permissions.`;
0 commit comments