certificates icon indicating copy to clipboard operation
certificates copied to clipboard

[Bug]: Step CA 0.30.1-hsm fails to start: "connecting to pcsc: access was denied because of a security violation"

Open jorti opened this issue 8 months ago • 9 comments

Steps to Reproduce

I run Step CA in a container and using a Yubikey.

After upgrading the container from 0.29.0-hsm to 0.30.1-hsm, the container fails to start with this error:

badger 2026/03/19 07:27:03 INFO: All 1 tables opened in 2ms
badger 2026/03/19 07:27:03 INFO: Replaying file id: 0 at offset: 59458095
badger 2026/03/19 07:27:03 INFO: Replay took: 1.160165ms
connecting to pcsc: access was denied because of a security violation

Debugging pcscd, I can see it's failing because of polkit:

11953524 [140696989920704] ../src/winscard_msg_srv.c:253:ProcessEventsServer() Common channel packet arrival
00000017 [140696989920704] ../src/winscard_msg_srv.c:264:ProcessEventsServer() ProcessCommonChannelRequest detects: 12
00000002 [140696989920704] ../src/pcscdaemon.c:130:SVCServiceRunLoop() A new context thread creation is requested: 12
00000157 [140696887490240] ../src/auth.c:115:IsClientAuthorized() polkit_authority_get_sync failed: Error initializing authority: Could not connect: No such file or directory
00000007 [140696887490240] ../src/winscard_svc.c:357:ContextThread() Rejected unauthorized PC/SC client
00000008 [140696887490240] ../src/winscard_svc.c:1112:MSGCleanupClient() Thread is stopping: dwClientID=12, threadContext @0x55f9792ec870
00000002 [140696887490240] ../src/winscard_svc.c:1120:MSGCleanupClient() Freeing SCONTEXT @0x55f9792ec870

There's no polkit inside a container. Starting pcscd with the option --disable-polkit fixes the issue.

Your Environment

  • OS: Fedora CoreOS 43
  • step-ca Version:
Smallstep CA/0.30.1 (linux/amd64)
Release Date: 2026-03-19 01:49 UTC

Expected Behavior

  • Container works as it did before.
  • pcscd is started with --disable-polkit in the container.

Actual Behavior

Container crashes.

Additional Context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

jorti avatar Mar 19 '26 07:03 jorti

any progress here? i see the original PR request author is reluctant to on board to your process, so can we please get this fixed? this has broke the step hsm image.

gtaws avatar Mar 26 '26 16:03 gtaws

I've created a workaround for my own purposes until a change like this can be landed:

Create a new entrypoint script:

#!/bin/sh
set -e

if [ -f /usr/sbin/pcscd-real ]; then
    exec /bin/bash /entrypoint.sh "$@"
fi

cp /usr/sbin/pcscd /usr/sbin/pcscd-real

cat > /usr/sbin/pcscd <<'EOF'
#!/bin/sh
exec /usr/sbin/pcscd-real --disable-polkit "$@"
EOF
chmod +x /usr/sbin/pcscd

exec /bin/bash /entrypoint.sh "$@"

Then, use this script as the entrypoint in your docker command or compose configuration. In my case, I mounted it at /entrypoint2.sh and specified ["/bin/bash", "/entrypoint2.sh"] as the entrypoint.

subtervisor avatar Mar 31 '26 01:03 subtervisor

I've fixed this in the entrypoint script, it's a one-line fix. The issue was caused by upgrading Debian to trixie However, I don't have a Linux device to test this on. Would one of you be willing to test out this fix? You'll need to build the image using Dockerfile.hsm:

docker build -f docker/Dockerfile.hsm -t step-ca-hsm:test .

tashian avatar Mar 31 '26 17:03 tashian

My recommendation is to run pcscd on the host and pass /var/run/pcscd into the container. That way a container is just an application for pcscd and you can have multiple container accessing different devices.

pcscd usually requires root privileges to access USB devices, which is not always possible in a container.

You may still see polkit restrictions when connecting from the container. In that case you can disable polkit by adding

PCSCD_ARGS="--disable-polkit"

in /etc/default/pcscd on the host.

CardContact avatar Apr 02 '26 20:04 CardContact

I think that's a fine approach @CardContact. I added a conditional to the PR to accommodate that approach.

tashian avatar Apr 02 '26 20:04 tashian

I run stepca in kubernetes, I have a sidecar container that connects to an HSM and then mounts the pcscd socket inside the stepca container.

The suggestion of setting PCSCD_ARGS in /etc/default/pcscd is very host centric and doesn’t really translate into a containerised/kubernetes environment

If you can provide an easy way to set PCSCD_ARGS inside the stepca container using the helm chart provided image that would be great

lareeth avatar Apr 02 '26 21:04 lareeth

What do you mean by "connects to a HSM and then mounts the pcscd socket inside the stepca container" ?

pcscd comes to play to connect to smart cards or token connected locally. So unless you use things like USBIP to relay usb communication you are dealing with real hardware to which you connect an USB device. That is different for network connected HSMs of course - but they don't use pcscd.

Disabling polkit must be done for the daemon, not the client. If you provide the socket into the container, then libpscsclite1 connects to this socket and talks to the daemon, wherever that is located.

For completely virtual environments we are working on a Cloud-HSM setup, where a local (typically remote) HSM connects to a cloud service, that in turn makes HSM access available via a REST-API. That will then also support advanced authentication mechanisms like n-of-m public key authentication and key escrow.

CardContact avatar Apr 02 '26 22:04 CardContact

Sorry, the HSM is USB, its a NitroKey HSM. We use a tool called Akri to identify host USB devices and map them to containers.

In the sidecar container we were able to set the --disable-polkit for our daemon, but because the step-ca container tries to run the pcscd command even the socket exists, we got hit by this issue, even though step-ca should be a client

The PR https://github.com/smallstep/certificates/pull/2630 looks to now be updated to check the if the socket is set, making it a proper client. I have tested and that fixes it for our issue. 🙌

lareeth avatar Apr 02 '26 22:04 lareeth

Sorry, the HSM is USB, its a NitroKey HSM

:+1: and thanks for sharing the link to Akri.

IMHO this is still way to much stack to integrate a secure key store with a certificate issuing application. We need to improve that.

CardContact avatar Apr 03 '26 08:04 CardContact