Skip to content

Harden Linux container runtime by switching CallbackHandler to a non-root user#236

Merged
StuartFerguson merged 3 commits intomainfrom
copilot/fix-dockerfile-user-security
Mar 16, 2026
Merged

Harden Linux container runtime by switching CallbackHandler to a non-root user#236
StuartFerguson merged 3 commits intomainfrom
copilot/fix-dockerfile-user-security

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

The Linux Docker image for CallbackHandler did not declare a runtime user, so the application could start as root. This change hardens the container by running the app under a dedicated non-root account while preserving the existing runtime filesystem layout.

  • Container runtime hardening

    • Add a dedicated txnproc user in /home/txnproc
    • Set the final image to run as USER txnproc
  • Preserve existing runtime paths

    • Create the expected runtime directories up front:
      • /home/txnproc/config
      • /home/txnproc/trace
    • Ensure these directories remain writable/readable by the non-root runtime user
  • Keep app startup behavior unchanged

    • Retain the existing published app layout under /app
    • Keep the existing entrypoint intact
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
WORKDIR /app
RUN useradd --create-home --shell /usr/sbin/nologin txnproc \
    && install -d -o txnproc -g txnproc /home/txnproc/config /home/txnproc/trace

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
RUN chown -R txnproc:txnproc /app
USER txnproc
ENTRYPOINT ["dotnet", "CallbackHandler.dll"]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build CallbackHandler.sln --configuration Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Security] By not specifying a USER, a program in the container may run as 'root'. This is a security hazard.</issue_title>
<issue_description>

Codacy ID: be6427fcb08f3ff17d0ff0305b40cf32

File: CallbackHandler/Dockerfile
Line: 25
Rule: Security (High)
Commit: 5c2c13630c67205156fc1779c5d732722a75a82f

Message: By not specifying a USER, a program in the container may run as 'root'. This is a security hazard.

**Code Snippet:**
```csharp
ENTRYPOINT ["dotnet", "CallbackHandler.dll"] 
```

</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 16, 2026 14:05
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Security] Fix program running as root in Dockerfile Harden Linux container runtime by switching CallbackHandler to a non-root user Mar 16, 2026
Copilot AI requested a review from StuartFerguson March 16, 2026 14:09
@StuartFerguson StuartFerguson marked this pull request as ready for review March 16, 2026 14:14
@StuartFerguson StuartFerguson merged commit afa7d67 into main Mar 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] By not specifying a USER, a program in the container may run as 'root'. This is a security hazard.

2 participants