Skip to content

Commit 6119202

Browse files
Copilotfelickz
andcommitted
Restructure C# CodeQL troubleshooting doc: Separate Dependencies from Build Failures and add Global Private Registry section
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 parent b68f6ef commit 6119202

1 file changed

Lines changed: 70 additions & 52 deletions

File tree

troubleshooting/codeql-builds/compiled-languages-csharp.md

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
11
Scanning a C# application with CodeQL
22

3+
# Dependencies
4+
5+
## NuGet Error NU1301
6+
This can indicate your custom package server is not configured which may fail the `dotnet restore` command. For private package servers, the follwing guidance shows how to add package sources: [Setting up authentication for nuget feeds](https://github.com/actions/setup-dotnet#setting-up-authentication-for-nuget-feeds)
7+
8+
## NuGet.targets(132,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
9+
10+
The `actions/setup-dotnet` action supports [setting up authentication for nuget feeds](https://github.com/actions/setup-dotnet#setting-up-authentication-for-nuget-feeds). Add this before the `autobuild` / custom build steps in your workflow:
11+
```yml
12+
- uses: actions/setup-dotnet@v3
13+
with:
14+
source-url: https://nuget.pkg.github.com/<owner>/index.json
15+
env:
16+
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
17+
```
18+
19+
If you wish to update exisitng feeds in a `nuget.config` with a credential
20+
```yml
21+
# Updating MY_ADO_FEED credentials
22+
- name: update nuget to add auth
23+
run: dotnet nuget update source MY_ADO_FEED -u NOTUSED -p "${{ secrets.ADO_TOKEN }}" --store-password-in-clear-text
24+
```
25+
26+
Alternatively, consider adding a GitHub Packages hosted NuGet feed using the nuget CLI tooling.
27+
28+
```yml
29+
- name: add nuget auth
30+
run: dotnet nuget add source https://nuget.pkg.github.com/<org-goes-here>/index.json -n "GitHub" -u USERNAME -p "${{ secrets.GH_PACKAGES_READ_ONLY }}" --store-password-in-clear-text
31+
```
32+
33+
## .NET Framework NuGet Authentication
34+
Since you are unable to use the [nuget/setup-nuget](https://github.com/nuget/setup-nuget#basic) action to pass package key/source to nuget exe for restore, instead fallback to the nuget sources commands.
35+
36+
You can update an existing source (by name - these might exist in a `nuget.config`) to include credentials via the `nuget sources Update` command
37+
38+
```yml
39+
- name: NuGet Restore
40+
run: |
41+
nuget sources Update -Name "SourceName" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
42+
nuget restore
43+
```
44+
45+
Alternatively, add a new source with `nuget sources Add`
46+
47+
```yml
48+
- name: NuGet Restore
49+
run: |
50+
nuget sources Add -Name "SourceName" -Source "https://url.to.your/source" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
51+
nuget restore
52+
```
53+
54+
## Global Private Registry
55+
56+
Organization-level configuration of NuGet server credentials can significantly improve the precision of CodeQL default scans, particularly when using `build-mode: none`. When credentials are properly configured at the organization level, CodeQL can access and analyze dependencies from private registries during the scanning process.
57+
58+
For `build-mode: none`, ensure credentials to your private registries listed in your `nuget.config` are available/injected so that the analysis does not attempt to hit a registry that will fail for every dependency. This is especially important for organizations using private NuGet feeds, as proper authentication allows CodeQL to:
59+
60+
- Resolve dependency metadata more accurately
61+
- Analyze the complete dependency graph
62+
- Provide more comprehensive security findings
63+
- Reduce false negatives in vulnerability detection
64+
65+
Configure organization-level credentials through:
66+
- Organization secrets for NuGet authentication tokens
67+
- Properly configured `nuget.config` files in your repositories
68+
- Environment variables for package source authentication
69+
70+
This configuration ensures that default scans have the necessary access to evaluate your complete codebase and its dependencies, leading to more accurate and comprehensive security analysis.
71+
372
# Build Failures
473

574
## [error]We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps.
@@ -52,56 +121,7 @@ If any custom tooling is required, consider pulling into your action via [custom
52121
### DotNet (.NET standard / core )
53122
Using `dotnet` is best documented at: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net. The [actions/setup-dotnet](https://github.com/actions/setup-dotnet) action can assist in configuring proper build tools.
54123
55-
#### NuGet Error NU1301
56-
This can indicate your custom package server is not configured which may fail the `dotnet restore` command. For private package servers, the follwing guidance shows how to add package sources: [Setting up authentication for nuget feeds](https://github.com/actions/setup-dotnet#setting-up-authentication-for-nuget-feeds)
57-
58-
#### NuGet.targets(132,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
59-
60-
The `actions/setup-dotnet` action supports [setting up authentication for nuget feeds](https://github.com/actions/setup-dotnet#setting-up-authentication-for-nuget-feeds). Add this before the `autobuild` / custom build steps in your workflow:
61-
```yml
62-
- uses: actions/setup-dotnet@v3
63-
with:
64-
source-url: https://nuget.pkg.github.com/<owner>/index.json
65-
env:
66-
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
67-
```
68-
69-
If you wish to update exisitng feeds in a `nuget.config` with a credential
70-
```yml
71-
# Updating MY_ADO_FEED credentials
72-
- name: update nuget to add auth
73-
run: dotnet nuget update source MY_ADO_FEED -u NOTUSED -p "${{ secrets.ADO_TOKEN }}" --store-password-in-clear-text
74-
```
75-
76-
Alternatively, consider adding a GitHub Packages hosted NuGet feed using the nuget CLI tooling.
77-
78-
```yml
79-
- name: add nuget auth
80-
run: dotnet nuget add source https://nuget.pkg.github.com/<org-goes-here>/index.json -n "GitHub" -u USERNAME -p "${{ secrets.GH_PACKAGES_READ_ONLY }}" --store-password-in-clear-text
81-
```
82-
83-
### .NET Framework
84-
85-
#### NuGet Authentication
86-
Since you are unable to use the [nuget/setup-nuget](https://github.com/nuget/setup-nuget#basic) action to pass package key/source to nuget exe for restore, instead fallback to the nuget sources commands.
87-
88-
You can update an existing source (by name - these might exist in a `nuget.config`) to include credentials via the `nuget sources Update` command
89-
90-
```yml
91-
- name: NuGet Restore
92-
run: |
93-
nuget sources Update -Name "SourceName" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
94-
nuget restore
95-
```
96-
97-
Alternatively, add a new source with `nuget sources Add`
98-
99-
```yml
100-
- name: NuGet Restore
101-
run: |
102-
nuget sources Add -Name "SourceName" -Source "https://url.to.your/source" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
103-
nuget restore
104-
```
124+
### .NET Framework
105125
106126
#### Manual Build Steps on Windows Runners
107127
NOTE: if you require windows OS to build, ensure you are using a windows runner. Otherwise it will attempt to use Mono [from the ubuntu image](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#language-and-runtime).
@@ -269,8 +289,6 @@ Start here: [CodeQL Docs - The build takes too long](https://docs.github.com/en
269289
- '**/docs/**'
270290
```
271291
272-
Tip: ensure credentials to your private registries listed in your `nuget.config` are available/injected so that `none` mode does not attempt to hit a registry that will fail for every dependency.
273-
274292
Alternatively, you might consider breaking up code into smaller chunks to scan. For example, a monorepo with many microservices would be a prime candidate to scan only the dependent code together. CodeQL has natural boundaries at the network layer - if a direct method call is not invoked then there is reduced value in scanning the code together. Consider specifying services by folder to scan together (vs ignore):
275293
276294
Microservice A config:

0 commit comments

Comments
 (0)