Dev

Install .NET 10 on Fedora 45: Minimal API, systemd, SELinux

SELinux doesn’t stop .NET from running on Fedora. It stops systemd from executing files that still carry a home directory label, and that single rule explains most of the “works with dotnet run, dies as a service” reports you’ll find for Fedora.

Original content from computingforgeeks.com - post 199561

The confusion starts with the install method. Fedora builds and ships its own .NET packages, while Microsoft’s install script drops a private copy into ~/.dotnet. Both give you the same runtime, but only one of them is labelled so systemd can launch it. This guide installs the SDK with dnf, builds a small ASP.NET Core minimal API, runs it as a locked-down systemd service under /opt, and puts nginx in front without turning SELinux off.

Every command below was run on a Fedora 45 Cloud VM with SELinux enforcing in November 2026, using SDK 10.0.115 and runtime 10.0.15 from the Fedora updates repository.

Fedora packages its own .NET

You do not need a Microsoft repository on Fedora. Microsoft stopped publishing packages for distributions that build their own, and Fedora is one of them, so the SDK, the runtimes and the AOT toolchain all come from the stock updates repo. List what is there before you pick a version.

dnf list --available "dotnet-sdk-*" "aspnetcore-runtime-*" 2>/dev/null | grep -v -e dbg -e source-built

Two major versions are packaged, the LTS and the newer STS release.

Available packages
aspnetcore-runtime-10.0.x86_64                10.0.15-1.fc45  updates
aspnetcore-runtime-11.0.x86_64                11.0.0-1.fc45   updates
dotnet-sdk-10.0.x86_64                        10.0.115-1.fc45 updates
dotnet-sdk-11.0.x86_64                        11.0.100-1.fc45 updates
dotnet-sdk-aot-10.0.x86_64                    10.0.115-1.fc45 updates
dotnet-sdk-aot-11.0.x86_64                    11.0.100-1.fc45 updates

There are no 8.0 or 9.0 packages because both lines reached end of support on November 10, 2026. LTS no longer buys you a longer window either, because Microsoft’s .NET support policy lists November 14, 2028 as the end date for both .NET 10 and .NET 11. So the choice comes down to your libraries, not the calendar. Pick 10 if your dependencies target it, pick 11 if you want the newer language features, and plan to move both at the same time.

Each package family covers a different job, so pick by what the machine does:

  • dotnet-sdk-10.0 for a machine that builds code
  • aspnetcore-runtime-10.0 for a server that only runs published web apps
  • dotnet-sdk-aot-10.0 on top of the SDK when you publish native AOT binaries

What about the obvious package name? sudo dnf install dotnet resolves to one tiny package and nothing else.

dnf list showing dotnet-sdk-10.0 and dotnet-sdk-11.0 packages on Fedora 45 and dnf install dotnet pulling only dotnet-host

Those 258 KiB are dotnet-host, the muxer binary. It has no SDK and no runtime behind it, so every dotnet command fails until you install a real package, and the error it prints never mentions a missing package. Ask for the SDK by its versioned name instead.

sudo dnf install -y dotnet-sdk-10.0

The transaction pulls in nine dependencies and took about 12 seconds on the lab VM.

Installing:
 dotnet-sdk-10.0                x86_64 0:10.0.115-1.fc45 updates    239.3 MiB
Installing dependencies:
 aspnetcore-runtime-10.0        x86_64 0:10.0.15-1.fc45  updates     23.0 MiB
 aspnetcore-targeting-pack-10.0 x86_64 0:10.0.15-1.fc45  updates     45.2 MiB
 dotnet-apphost-pack-10.0       x86_64 0:10.0.15-1.fc45  updates     11.6 MiB
 dotnet-host                    x86_64 0:11.0.0-1.fc45   updates    258.0 KiB
 dotnet-hostfxr-10.0            x86_64 0:10.0.15-1.fc45  updates    307.9 KiB
 dotnet-runtime-10.0            x86_64 0:10.0.15-1.fc45  updates     71.5 MiB
 dotnet-targeting-pack-10.0     x86_64 0:10.0.15-1.fc45  updates     38.8 MiB
 dotnet-templates-10.0          x86_64 0:10.0.115-1.fc45 updates     10.0 MiB
 openssl3-libs                  x86_64 1:3.5.9-1.fc45    updates      9.2 MiB

Look at the last line. Fedora 45’s default OpenSSL is the 4.x series, and the .NET 10 runtime loads the OpenSSL 3 libraries, so the packages require and dnf installs openssl3-libs next to it. A cleanup that removes it with dnf remove takes the .NET packages with it, so check what depends on it before you prune “duplicate” OpenSSL packages. If dnf5’s syntax still trips you up, the DNF Cheat Sheet that puts DNF 4 and DNF 5 commands side by side covers the history, rollback and repoquery forms you will want when you audit packages like these.

dotnet --info

Three fields in that report matter more than the version numbers: the base path, the RID and the environment block.

dotnet --info on Fedora 45 showing the SDK and runtimes under /usr/lib64/dotnet and RID fedora.45-x64

Everything lives under /usr/lib64/dotnet, the RID is fedora.45-x64, and no DOTNET_ROOT is set. Fedora does not need one, because dotnet-host writes the install path into /etc/dotnet/install_location and install_location_x64, and every app launcher reads them. That matters later, because a published app finds its runtime through that file even when systemd starts it with an empty environment. You should also check the binary’s SELinux label now, since it decides everything in the systemd section, and you will compare it with the script copy’s label in a moment.

readlink -f /usr/bin/dotnet; rpm -q openssl-libs openssl3-libs; ls -Z /usr/lib64/dotnet/dotnet

Packaged binaries carry bin_t, the type every system executable has.

/usr/lib64/dotnet/dotnet
openssl-libs-4.0.3-1.fc45.x86_64
openssl3-libs-3.5.9-1.fc45.x86_64
system_u:object_r:bin_t:s0 /usr/lib64/dotnet/dotnet

Remember that bin_t label, because the script install never gets it.

The script adds a feature band

Many guides reach for dotnet-install.sh because it is “newer”. On Fedora 45 that is only half true, so run it with the 10.0 channel and watch what it actually fetches.

curl -sSL -o dotnet-install.sh https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel 10.0

Microsoft’s build CDN serves the tarball, and the script unpacks it into your home directory.

dotnet-install: Attempting to download using aka.ms link https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.404/dotnet-sdk-10.0.404-linux-x64.tar.gz
dotnet-install: Remote file https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.404/dotnet-sdk-10.0.404-linux-x64.tar.gz size is 243138887 bytes.
dotnet-install: Extracting archive from https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.404/dotnet-sdk-10.0.404-linux-x64.tar.gz
dotnet-install: Downloaded file size is 243138887 bytes.
dotnet-install: The remote and local file sizes are equal.
dotnet-install: Installed version is 10.0.404
dotnet-install: Adding to current process PATH: `/home/kenneth/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
dotnet-install: Installation finished successfully.

The SDK number jumped from the 1xx band to the 4xx band, which looks like a big upgrade. Compare the runtimes that each copy carries, and the disk each one costs.

Microsoft dotnet-install.sh SDK in ~/.dotnet next to the Fedora dnf SDK, both with the same ASP.NET Core runtime

Both copies run the same 10.0.15 runtime. The hundreds digit of an SDK version marks a feature band, which changes the tooling (MSBuild, analyzers, templates) and never the runtime your app executes on. So your app behaves identically on either copy, and only the build tooling differs. Meanwhile the script copy costs 626 MB against 450 MB for the packaged one, and a dnf upgrade never touches it, so its security patches arrive only when you remember to rerun the script.

Your PATH decides which copy answers. In the second command of that capture, the script copy wins once ~/.dotnet comes first, and the packaged SDK answers again as soon as /usr/bin leads. Microsoft’s Fedora install page recommends the dnf packages and keeps the script for previews, and the lab results agree.

Questiondnf dotnet-sdk-10.0dotnet-install.sh --channel 10.0
Runtime version10.0.1510.0.15
SDK band1xx4xx
Location/usr/lib64/dotnet~/.dotnet
Disk used450 MB626 MB
Updatesdnf upgradeRerun the script
systemd can execute itYes (bin_t)No (user_home_t, 203/EXEC)
Telemetry banner on first runNone printedPrinted, opt out with DOTNET_CLI_TELEMETRY_OPTOUT=1

Keep the script for the cases the packages cannot cover:

  • a preview build that Fedora does not package
  • a feature from the 2xx to 4xx SDK bands your build depends on
  • a CI runner where you want the SDK in the job’s own directory

Outside those cases it only adds a second update path you have to track by hand. The rest of this guide uses the packaged SDK.

A minimal API runs from home

Development is the part SELinux leaves alone, because your login shell runs unconfined and can execute anything you own. Create an empty web project.

cd ~ && dotnet new web -o HelloApi

On first use the SDK prints a welcome banner and restores packages in 139 ms. Notice what is missing compared with the script copy, which printed a telemetry section at this point.

Welcome to .NET 10.0!
---------------------
SDK Version: 10.0.115

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, run 'dotnet dev-certs https --trust'
Learn about HTTPS: https://aka.ms/dotnet-https
...
The template "ASP.NET Core Empty" was created successfully.

Processing post-creation actions...
Restoring /home/kenneth/HelloApi/HelloApi.csproj:
  Determining projects to restore...
  Restored /home/kenneth/HelloApi/HelloApi.csproj (in 139 ms).
Restore succeeded.

Replace the template’s single route with three endpoints. The /info route reports the runtime, the OS, the environment and the user, which turns every later step into something you can check with one curl.

vim ~/HelloApi/Program.cs

Paste in the exact file the lab built and ran.

using System.Runtime.InteropServices;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello from ASP.NET Core on Fedora\n");

app.MapGet("/info", () => new
{
    framework = RuntimeInformation.FrameworkDescription,
    os = RuntimeInformation.OSDescription,
    environment = app.Environment.EnvironmentName,
    user = Environment.UserName,
    contentRoot = app.Environment.ContentRootPath
});

app.MapGet("/health", () => Results.Ok(new { status = "ok", time = DateTime.UtcNow }));

app.Run();

Build it once to catch typos, then start it. A clean build took just under 8 seconds on two vCPUs.

cd ~/HelloApi && dotnet build && dotnet run

Kestrel binds the HTTP port from Properties/launchSettings.json, which the template picks at random.

Using launch settings from /home/kenneth/HelloApi/Properties/launchSettings.json...
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5292
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/kenneth/HelloApi

From a second terminal, hit all three routes.

curl -s http://localhost:5292/; curl -s http://localhost:5292/info; echo; curl -s http://localhost:5292/health; echo

You get .NET 10.0.15, the Development environment and your own user back.

curl against the ASP.NET Core minimal API endpoints running with dotnet run on Fedora

Stop it with Ctrl+C. Three of those values change once the app runs as a service, and you will check each one later:

  • environment becomes Production
  • user becomes a dedicated system account
  • contentRoot moves out of your home directory

Publish a Release build into a folder you can copy. The output is framework dependent, so the target machine only needs the ASP.NET Core runtime package and not the SDK.

dotnet publish -c Release -o ~/HelloApi/publish

Your whole deployable is 140K, with a 78 KB native launcher called HelloApi next to the DLL.

-rw-r--r--. 1 kenneth kenneth   119 Nov 29 22:37 appsettings.Development.json
-rw-r--r--. 1 kenneth kenneth   142 Nov 29 22:37 appsettings.json
-rwxr-xr-x. 1 kenneth kenneth 78608 Nov 29 22:39 HelloApi
-rw-r--r--. 1 kenneth kenneth   396 Nov 29 22:39 HelloApi.deps.json
-rw-r--r--. 1 kenneth kenneth  9216 Nov 29 22:39 HelloApi.dll
-rw-r--r--. 1 kenneth kenneth 21352 Nov 29 22:39 HelloApi.pdb
-rw-r--r--. 1 kenneth kenneth   472 Nov 29 22:39 HelloApi.runtimeconfig.json
-rw-r--r--. 1 kenneth kenneth    53 Nov 29 22:39 HelloApi.staticwebassets.endpoints.json
-rw-r--r--. 1 kenneth kenneth   484 Nov 29 22:39 web.config
140K	/home/kenneth/HelloApi/publish

That launcher, the apphost, is what the service will execute, and it is also the file SELinux will refuse if it stays where it is. Every file in this folder carries user_home_t because it was created under /home, so the label travels with the build until something resets it.

systemd cannot execute home labels

What happens when you point a unit straight at the publish folder? The lab tried it with a throwaway unit whose ExecStart was /home/kenneth/HelloApi/publish/HelloApi, and it failed in 13 milliseconds.

systemd 203/EXEC failure and SELinux AVC denying init_t execute on a user_home_t .NET apphost

Status 203/EXEC means systemd could not even start the binary, so no .NET code ran and the journal holds no application log to read. Most people look for a missing runtime at this point, and they lose an hour. The AVC names the real rule instead: the source context is init_t (systemd), the target is user_home_t, and the denied permission is execute. In order, the kernel checks three things when systemd starts a service:

  1. the Unix permission bits (passed, the file is 755)
  2. the SELinux type of the file being executed (denied, user_home_t)
  3. the transition into the service’s domain (never reached)

Only the label of the binary that systemd executes matters, not where the DLL sits. Two transient units started with systemd-run prove it, one per dotnet binary. The packaged /usr/bin/dotnet loading the same home directory DLL starts fine, because systemd executes a bin_t file and the DLL is only read. The script’s ~/.dotnet/dotnet fails the same way the apphost did.

for x in "/usr/bin/dotnet /home/kenneth/HelloApi/publish/HelloApi.dll" "/home/kenneth/.dotnet/dotnet /home/kenneth/HelloApi/publish/HelloApi.dll"; do n=t$RANDOM; sudo systemd-run -q --unit $n -p User=kenneth -E ASPNETCORE_URLS=http://127.0.0.1:5055 $x; sleep 3; echo "$x => $(systemctl show -p ActiveState,ExecMainStatus --value $n | tr "\n" " ")"; ps -o label= -C dotnet | head -1; sudo systemctl stop $n 2>/dev/null; sudo systemctl reset-failed $n 2>/dev/null; done

This is the loop as the lab ran it, so replace kenneth with your own user before you paste it. The first unit stays active in unconfined_service_t, and the second dies with 203.

/usr/bin/dotnet /home/kenneth/HelloApi/publish/HelloApi.dll => active 0
system_u:system_r:unconfined_service_t:s0
/home/kenneth/.dotnet/dotnet /home/kenneth/HelloApi/publish/HelloApi.dll => failed 203 

Here is the real cost of the script install on a server. Its dotnet binary can never be a systemd ExecStart while it lives in home, so you would have to relabel or move a private SDK just to run a service. Running services from home directories is a bad habit anyway, so move the build to /opt. A plain mv does not fix it, though, because a move keeps the old label.

cp -r ~/HelloApi/publish ~/helloapi-build && sudo mv ~/helloapi-build /opt/helloapi
ls -Z /opt/helloapi/HelloApi; matchpathcon /opt/helloapi/HelloApi

Now the file sits in /opt but still says user_home_t, while policy expects usr_t for that path.

unconfined_u:object_r:user_home_t:s0 /opt/helloapi/HelloApi
/opt/helloapi/HelloApi	system_u:object_r:usr_t:s0

A service started from that state hit the same status=203/EXEC in the lab. Reset the labels to what policy expects.

sudo restorecon -Rv /opt/helloapi

Every file is relabelled from user_home_t to usr_t.

Relabeled /opt/helloapi from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:usr_t:s0
Relabeled /opt/helloapi/appsettings.Development.json from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:usr_t:s0
Relabeled /opt/helloapi/appsettings.json from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:usr_t:s0
Relabeled /opt/helloapi/HelloApi.dll from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:usr_t:s0
...
Relabeled /opt/helloapi/HelloApi from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:usr_t:s0

Make restorecon -Rv part of every deploy script that moves files. Copying with cp straight into /opt creates new files that inherit the target’s label, so it avoids the problem. One forgotten mv in a script brings the 203 back, though, and it will look like a broken release rather than a label. If you deploy with rsync or an Ansible copy task, the same rule applies, so run restorecon as the last step of the deploy rather than trusting each tool to get the label right. It costs a fraction of a second and removes a whole class of failure from your release notes.

The service runs as its own user

Give the app a system account with no login shell and no home of its own. It owns nothing under /opt/helloapi, and the files there are only world readable, so a compromised app cannot rewrite its own binaries.

sudo useradd --system --no-create-home --home-dir /opt/helloapi --shell /usr/sbin/nologin helloapi && id helloapi

Fedora hands out a UID below 1000, as it does for every system account.

uid=990(helloapi) gid=990(helloapi) groups=990(helloapi)

Now write the unit file.

sudo vim /etc/systemd/system/helloapi.service

Use the unit the lab ran. ExecStart points at the apphost, which finds the runtime through /etc/dotnet/install_location, so no DOTNET_ROOT is needed.

[Unit]
Description=HelloApi ASP.NET Core minimal API
After=network-online.target
Wants=network-online.target

[Service]
Type=exec
User=helloapi
Group=helloapi
WorkingDirectory=/opt/helloapi
ExecStart=/opt/helloapi/HelloApi
Environment=ASPNETCORE_URLS=http://0.0.0.0:5000
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_NOLOGO=1
Restart=on-failure
RestartSec=5
KillSignal=SIGINT
TimeoutStopSec=30
SyslogIdentifier=helloapi
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target

A few lines do more than they look, and each one closes a specific failure:

  • Type=exec makes systemctl start fail when the binary cannot execute
  • KillSignal=SIGINT lets Kestrel drain requests the way Ctrl+C does
  • ProtectSystem=strict makes the filesystem read only for the app
  • ProtectHome=true hides every home directory from it

With Type=simple, systemd reports success before the exec even happens, so a 203 only shows up later in status. With Type=exec your deploy script sees the failure on the start command itself. The unit binds all interfaces for now so you can test from outside, and the nginx section narrows it to loopback.

sudo systemctl daemon-reload
sudo systemctl enable --now helloapi
systemctl status helloapi --no-pager

Once the unit is up, the main PID is the apphost itself, not a dotnet process.

● helloapi.service - HelloApi ASP.NET Core minimal API
     Loaded: loaded (/etc/systemd/system/helloapi.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: active (running) since Sun 2026-11-29 22:40:19 UTC; 16ms ago
 Invocation: 991050f5ce304d4b9ded5a0c41793d77
   Main PID: 3423 (HelloApi)
      Tasks: 10 (limit: 19099)
     Memory: 3.2M (peak: 3.4M)
        CPU: 35ms
     CGroup: /system.slice/helloapi.service
             └─3423 /opt/helloapi/HelloApi

Read the journal, query /info, and check which user and SELinux domain the process landed in.

sudo journalctl -u helloapi --no-pager -o cat | tail -12; curl -s http://localhost:5000/info; echo; ps -o user,label,rss,cmd -C HelloApi; ss -ltn | grep 5000

The “Failed to start” line at the top of this capture comes from an extra lab run that started the unit on purpose after putting the user_home_t label back with chcon. Your journal will not have it, and everything after it is the clean start.

helloapi systemd service journal, info endpoint and process running as helloapi with unconfined_service_t label

All three values from the development run have changed to Production, helloapi and /opt/helloapi. The process runs in unconfined_service_t because Fedora’s policy has no dedicated domain for .NET apps, and it settled at about 70 MB of resident memory. Since that domain is unconfined, the label on the executable is the only SELinux gate the app itself meets, which is why fixing one label was enough.

firewalld decides who reaches port 5000

Kestrel listening on 0.0.0.0 does not mean other hosts can reach it. Fedora’s firewall zones differ by edition, and the difference catches people moving from a laptop to a server.

Workstation and Server ship firewalld running. Fedora Cloud images do not include it, so on a cloud VM install and start it first. Its default public zone already allows SSH on port 22, so enabling it over an SSH session does not lock you out unless sshd listens on another port. On a cloud VM, the provider’s security group must also allow 5000/tcp, and later 80/tcp, before outside tests work.

sudo dnf install -y firewalld
sudo systemctl enable --now firewalld

Then compare the two edition zones you are likely to meet, so you know which one your machine inherited.

sudo firewall-cmd --info-zone=FedoraWorkstation | grep -E "ports|services"; sudo firewall-cmd --info-zone=FedoraServer | grep -E "ports|services"

Workstation opens every port above 1024, while Server opens only SSH, Cockpit and DHCPv6.

  services: dhcpv6-client samba-client ssh
  ports: 1025-65535/udp 1025-65535/tcp
  forward-ports:
  source-ports:
  services: cockpit dhcpv6-client ssh
  ports:
  forward-ports:
  source-ports: 

So the API is reachable from the LAN on a Workstation install with no rule at all, and invisible on Server. Fedora Cloud images ship without firewalld, so the lab installed it and got the public zone. Whatever your edition, open the port explicitly so the rule is written down and survives a zone change. Relying on the Workstation range is risky because you never wrote that rule yourself, so moving the box to another zone or edition silently closes the API. An explicit rule also tells the next admin which port the app owns.

sudo firewall-cmd --get-default-zone
sudo firewall-cmd --permanent --add-port=5000/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports

Both the zone name and the new port confirm the rule landed.

public
success
success
5000/tcp

Test from a second machine, not from the server itself, because loopback traffic never meets the zone rules.

curl -s http://10.0.1.50:5000/health
curl -si http://10.0.1.50:5000/ | head -5

A Server: Kestrel header proves the request reached the .NET process with nothing in between.

{"status":"ok","time":"2026-11-29T22:41:18.2014811Z"}
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Sun, 29 Nov 2026 22:41:17 GMT
Server: Kestrel
Transfer-Encoding: chunked

For zones and rich rules, the firewalld guide for RHEL family systems applies to Fedora unchanged. Exposing Kestrel directly is fine for an internal API on a trusted network. Anything public should sit behind a reverse proxy that handles TLS, request limits and access logs, so you are not rebuilding those in application code. Kestrel can terminate TLS itself, but then you manage certificates inside the app, and every renewal becomes a restart you have to schedule.

nginx needs one SELinux boolean

Install nginx from the Fedora repo and start it.

sudo dnf install -y nginx
sudo systemctl enable --now nginx

Create a server block for the API.

sudo vim /etc/nginx/conf.d/helloapi.conf

Use a real server_name rather than _, which collides with Fedora’s default server, and keep the IPv6 listen line. Without it, a request to localhost arrives on ::1 and Fedora’s default server answers it with a 404.

server {
    listen 80;
    listen [::]:80;
    server_name api.example.com;

    location / {
        proxy_pass         http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

Reload nginx with sudo systemctl reload nginx and request the health route through it. Send the Host header, because a bare localhost request lands on Fedora’s default server and returns 404 instead.

curl -si -H "Host: api.example.com" http://localhost/health | head -1; sudo tail -1 /var/log/nginx/error.log; sudo ausearch -m avc -c nginx --input-logs 2>/dev/null | grep avc | tail -1

You get a 502, and the error log blames permissions.

nginx 502 Bad Gateway with SELinux name_connect denial, fixed by setsebool httpd_can_network_connect

Nothing is wrong with the app. nginx runs as httpd_t, and the AVC shows it was denied name_connect to port 5000, which policy labels commplex_main_port_t. Web server processes may not open outbound connections unless a boolean allows it, because a compromised web server is a classic pivot point. So the 502 is policy working as designed, and you should not answer it with setenforce 0, which would turn off every other check on the box to fix one connection. One persistent switch opens that path, and the -P flag keeps it across reboots.

sudo setsebool -P httpd_can_network_connect 1

After that, the same request returns the JSON from Kestrel, as the second half of the capture above shows. The Django and Gunicorn setup on Fedora hits the same boolean from the Python side, which tells you the rule belongs to nginx, not to .NET.

With nginx in front, Kestrel should not listen on public interfaces any more. Override the address with a drop-in instead of editing the unit, so a later unit update cannot undo it.

sudo mkdir -p /etc/systemd/system/helloapi.service.d
sudo vim /etc/systemd/system/helloapi.service.d/listen.conf

Put only the URL variable in it.

[Service]
Environment=ASPNETCORE_URLS=http://127.0.0.1:5000

Restart the service, then swap the firewall rule from port 5000 to the HTTP service.

sudo systemctl daemon-reload && sudo systemctl restart helloapi
ss -ltn | grep 5000
sudo firewall-cmd --permanent --remove-port=5000/tcp
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --list-all | grep -E "services|ports"

Kestrel is bound to loopback only, and the zone exposes HTTP instead of the raw port.

LISTEN 0      512        127.0.0.1:5000      0.0.0.0:*
success
success
success
  services: dhcpv6-client http mdns ssh
  ports:
  forward-ports:
  source-ports: 

Before this server takes real traffic, point a DNS record at it and add TLS to that server block with certbot’s nginx plugin. The proxy headers above already pass X-Forwarded-Proto through, so the app can tell HTTPS requests apart once you enable the forwarded headers middleware.

Relabelling the port is not enough on its own

A common alternative is to label port 5000 as a web port instead of opening all outbound connections. Treat this subsection as a replacement for the boolean, not an extra step: the lab turned the boolean back off and tried the label alone.

sudo setsebool -P httpd_can_network_connect 0
sudo semanage port -m -t http_port_t -p tcp 5000
sudo semanage port -l | grep -w 5000
curl -s -o /dev/null -w "%{http_code}\n" -H "Host: api.example.com" http://localhost/health

Port 5000 moved to http_port_t, and nginx still returned 502.

commplex_main_port_t           tcp      5000
commplex_main_port_t           udp      5000
http_port_t                    tcp      5000, 80, 81, 443, 488, 8008, 8009, 8443, 9000
502

Why did the label change do nothing? The new AVC shows that the target type changed, but connecting to a web port still needs its own permission.

type=AVC msg=audit(1795992144.711:2212): avc:  denied  { name_connect } for  pid=4228 comm="nginx" dest=5000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0

That permission comes from the narrower httpd_can_network_relay boolean. Turn it on and leave the broad boolean off.

sudo setsebool -P httpd_can_network_relay 1
getsebool httpd_can_network_relay httpd_can_network_connect

Now the health check returns 200 through the proxy.

httpd_can_network_relay --> on
httpd_can_network_connect --> off
200

Pick one approach and stick to it:

  • httpd_can_network_connect alone, simplest, lets nginx reach any port
  • port label plus httpd_can_network_relay, limits nginx to web-labelled ports

On a single-purpose API host the first is fine, because nginx has nothing else on the box worth reaching. If the same machine also runs a database or a cache on local ports, the second keeps a compromised nginx from talking to them, which is worth the extra command.

SDK 11 changes the default

Installing the newer SDK next to 10 is safe for running apps, but it changes what your next build produces. The lab added it and then checked three things in order:

  1. which SDKs dotnet now lists
  2. which target framework a new project gets
  3. whether the running service noticed
sudo dnf install -y dotnet-sdk-11.0
dotnet --list-sdks
cd /tmp && dotnet --version && dotnet new console -o Net11Check && grep TargetFramework Net11Check/Net11Check.csproj

Both SDKs share /usr/lib64/dotnet, the highest one becomes the default, and new projects target net11.0. Pin a project to the 10 SDK with a global.json in its directory.

cd ~/HelloApi && dotnet new globaljson --sdk-version 10.0.115 --roll-forward latestFeature && dotnet --version

Inside the project, dotnet now answers with the 10 SDK, and the running service never noticed the upgrade.

SDK 11 installed next to SDK 10 on Fedora with global.json pinning the project and the service still on .NET 10

Your published app’s runtimeconfig.json says net10.0, and by default the host never rolls a net10.0 app onto a newer major runtime. A new SDK never moves an existing build onto a different runtime, so only a rebuild with a new target framework does that. You can install 11 on a server for one new app without retesting every old one. The catch is on the build side, because a developer who runs dotnet new without a global.json gets a net11.0 project, and that app will not start on a server that only has the 10 runtime. Add the pin to the repository before the second SDK lands on anyone’s machine.

Keep rollForward set to latestFeature rather than pinning an exact SDK. A file that pins the script’s 4xx SDK breaks every machine that uses the packaged one, as the next section shows. If you also install Python, Node.js or Go on the same workstation, the Fedora language toolchain setup follows the same dnf-first approach for each of them.

Errors that point at the wrong cause

Each of these came up in the lab, and none of them says what actually went wrong. Read the cause first, because the obvious reaction to each one (reinstalling .NET) fixes none of them.

“does not contain any version-numbered child folders”

You see this from dotnet --version when only the host package is installed, usually after sudo dnf install dotnet.

Error: [/usr/lib64/dotnet/host/fxr] does not contain any version-numbered child folders

Nothing is corrupt. The muxer has no hostfxr, SDK or runtime to hand off to, so it reports the first empty folder it finds. Install dotnet-sdk-10.0 for development or aspnetcore-runtime-10.0 on a server.

“You must install .NET to run this application”

Apphosts print this when they cannot locate a runtime, which happens on a machine where .NET only exists in ~/.dotnet.

You must install .NET to run this application.

App: /home/kenneth/HelloApi/publish/HelloApi
Architecture: x64
App host version: 10.0.15
.NET location: Not found

The following locations were searched:
  Application directory:
    /home/kenneth/HelloApi/publish/
  Environment variable:
    DOTNET_ROOT_X64 = <not set>
    DOTNET_ROOT = <not set>
  Registered location:
    /etc/dotnet/install_location_x64 = <not set>
  Default location:
    /usr/share/dotnet

Read the search order in that output: the app folder, DOTNET_ROOT, the registered location file, then /usr/share/dotnet. The script registers nothing, so either set the variable for your shell or install the packaged runtime and let Fedora’s location file do the work. The packaged route is the better choice on anything you deploy to, because the variable only lives in the shell that set it. Log in again, run the app from cron, or start it from another user, and the error comes straight back.

DOTNET_ROOT=$HOME/.dotnet ./HelloApi

Don’t copy that variable into a systemd unit as a workaround. The script’s binaries are still labelled user_home_t, so systemd hits the same exec denial covered earlier, just with a different binary.

“A compatible .NET SDK was not found”

A global.json pinning 10.0.404, committed by someone who used the script, makes the packaged SDK refuse every command.

  * You intended to execute a .NET SDK command:
      A compatible .NET SDK was not found.

Requested SDK version: 10.0.404
global.json file: /home/kenneth/HelloApi/global.json

Installed SDKs:

Install the [10.0.404] .NET SDK or update [/home/kenneth/HelloApi/global.json] to match an installed SDK.

Don’t install a second SDK just to satisfy it. Lower the version to the band’s base and allow feature roll forward, which both SDKs accept.

{"sdk":{"version":"10.0.100","rollForward":"latestFeature"}}

With that file the packaged dotnet reported 10.0.115 and the script copy reported 10.0.404, both from the same project directory. Commit that form, and your teammates on either install method stay unblocked.

“Failed to bind to address … address already in use”

dotnet run starts your app as a child process. If the parent dies without forwarding the stop signal, the child keeps running and keeps the port.

fail: Microsoft.Extensions.Hosting.Internal.Host[11]
      Hosting failed to start
      System.IO.IOException: Failed to bind to address http://127.0.0.1:5292: address already in use.
       ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use

Find the orphan with ss -ltnp | grep 5292 and kill that PID. Stopping dev servers with Ctrl+C avoids it, because the signal reaches both processes. If you work over flaky SSH, run dotnet run inside tmux, so a dropped connection leaves the session alive instead of leaving an orphan holding your port.

Every layer checks one thing

A request to the API passes these checks in order, and each failure has its own signature. When something breaks, find the first row whose symptom matches what you see.

LayerWhat it checksSymptom when it failsFix
dnf packagesA runtime exists behind dotnet-hosthost/fxr has no version foldersInstall dotnet-sdk-10.0 or aspnetcore-runtime-10.0
Apphost lookupApp folder, DOTNET_ROOT, then /etc/dotnet/install_location*“You must install .NET”Packaged runtime, or DOTNET_ROOT in your shell
SELinux execLabel of the ExecStart binary203/EXEC, AVC on user_home_tDeploy to /opt, restorecon -Rv
Kestrel bindPort is free“address already in use”Kill the orphaned process
firewalldZone allows the port or serviceTimeouts from other hosts only--add-port or --add-service=http
SELinux networkhttpd_t may connect to the backend portnginx 502, Permission denied in error.loghttpd_can_network_connect or port label plus relay

None of these rows needs SELinux disabled, and switching it to permissive only hides which row you are on. If you later containerise the app, the Docker on Fedora guide covers the container labels that replace these file labels. For the enterprise side, the .NET guide for Rocky Linux and AlmaLinux walks the same SDK and service setup under the same policy.

Keep reading

How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Fedora How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Things to Do After Installing Fedora 45 Workstation Fedora Things to Do After Installing Fedora 45 Workstation Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Fedora Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Install Nix Package Manager on Fedora 45 / 44 with SELinux Fedora Install Nix Package Manager on Fedora 45 / 44 with SELinux Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Fedora Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Btrfs Snapshots and Rollback with Snapper on Fedora 45 / 44 Fedora Btrfs Snapshots and Rollback with Snapper on Fedora 45 / 44

Leave a Comment

Press ESC to close