Skip to content

Commit dd3323f

Browse files
authored
Merge pull request #51 from advanced-security/copilot/fix-408f76a5-67f5-4574-871d-f5bd8875bc80
Restructure C# CodeQL troubleshooting doc: Separate Dependencies from Build Failures and add Global Private Registry section
2 parents d913f71 + da93c19 commit dd3323f

File tree

1 file changed

+63
-52
lines changed

1 file changed

+63
-52
lines changed

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

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

3+
# Dependencies
4+
5+
## Global Private Registry (with default setup)
6+
7+
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.
8+
9+
For default setup, 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. Even if not listed in a nuget.config, the global private registry server/credentials are injected into a proxy during default setup! Configuring registry auth is especially important for organizations using private NuGet feeds, as proper authentication allows CodeQL (and Dependabot) to:
10+
- Resolve dependency metadata more accurately - leading to a more precise CodeQL database
11+
- Analyze the complete dependency graph - instead of a loose detection on package versions
12+
- Provide more comprehensive security findings - helping to enusre data flows are more fully mapped
13+
- Reduce false positives/false negatives in vulnerability detection - better detection of data types and call targets sourced from dependencies
14+
15+
16+
## NuGet Error NU1301
17+
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)
18+
19+
## 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.
20+
21+
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:
22+
```yml
23+
- uses: actions/setup-dotnet@v3
24+
with:
25+
source-url: https://nuget.pkg.github.com/<owner>/index.json
26+
env:
27+
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
28+
```
29+
30+
If you wish to update exisitng feeds in a `nuget.config` with a credential
31+
```yml
32+
# Updating MY_ADO_FEED credentials
33+
- name: update nuget to add auth
34+
run: dotnet nuget update source MY_ADO_FEED -u NOTUSED -p "${{ secrets.ADO_TOKEN }}" --store-password-in-clear-text
35+
```
36+
37+
Alternatively, consider adding a GitHub Packages hosted NuGet feed using the nuget CLI tooling.
38+
39+
```yml
40+
- name: add nuget auth
41+
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
42+
```
43+
44+
## .NET Framework NuGet Authentication
45+
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.
46+
47+
You can update an existing source (by name - these might exist in a `nuget.config`) to include credentials via the `nuget sources Update` command
48+
49+
```yml
50+
- name: NuGet Restore
51+
run: |
52+
nuget sources Update -Name "SourceName" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
53+
nuget restore
54+
```
55+
56+
Alternatively, add a new source with `nuget sources Add`
57+
58+
```yml
59+
- name: NuGet Restore
60+
run: |
61+
nuget sources Add -Name "SourceName" -Source "https://url.to.your/source" -UserName "any" -Password "${{ secrets.NUGET_PACKAGES_PAT }}"
62+
nuget restore
63+
```
64+
365
# Build Failures
466

567
## [error]We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps.
@@ -52,56 +114,7 @@ If any custom tooling is required, consider pulling into your action via [custom
52114
### DotNet (.NET standard / core )
53115
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.
54116
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-
```
117+
### .NET Framework
105118
106119
#### Manual Build Steps on Windows Runners
107120
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 +282,6 @@ Start here: [CodeQL Docs - The build takes too long](https://docs.github.com/en
269282
- '**/docs/**'
270283
```
271284
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-
274285
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):
275286
276287
Microservice A config:

0 commit comments

Comments
 (0)