iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📸

Building a PAM module for Linux face authentication in Rust: chissu-pam

に公開
2025/11/18

What is this?

I got tired of typing my password every time I needed sudo or to unlock my screen, so I built a custom PAM module for face authentication. While Howdy is the standard for face authentication on Linux Desktops, I’ve summarized this article including the reasons why I chose to build chissu-pam. The name comes from the flow: Windows Hello → Japanese "Chii-su" (a casual greeting) → Chissu.

Most people on Mac are freed from password entry via Touch ID, and those on Windows via Windows Hello. Driven by the desire to have that same comfort on Linux Desktop and to experiment with the trendy "Vibe Coding," I decided to build this.

Why did I build it?

First, there is fprintd for biometrics on Linux. It’s for fingerprint authentication like Touch ID, and fingerprint readers supported on Linux are basically built into laptops. I bought a Linux-compatible external USB device after researching, but the recognition accuracy was mediocre.

Next, I tried Howdy. It is a PAM module that achieves face authentication like Windows Hello, and it fulfills almost everything I wanted to do. I actually ran it for about two years, but it’s painful that it breaks every time I do-release-upgrade Ubuntu every six months. Howdy didn’t have official Python 3 support for a long time, and I had to fix it manually as I went (though this issue was recently resolved with an update, even if it wasn't released for a while). The fact that installing the Python dlib library requires --break-system-packages because there are no Deb packages available was also stressful. I wanted something that wouldn’t break during the semi-annual Ubuntu upgrades.

Additionally, another motivation was wanting to use it as a testing ground for Vibe Coding.

What are the rough requirements?

  • Must: Generate a binary because I want robustness against environments. Go or Rust were strong candidates, and as a result of my research, I chose Rust.
  • Should: Run as non-root.
  • Should: Be secure if possible. I don't like that my face feature vector is just sitting somewhere in plain sight. Other systems stored them with 644 permissions.

How does it work roughly?

For details, check https://github.com/sett4/chissu-pam or https://deepwiki.com/sett4/chissu-pam. It works if you have the following 6 files:

  • chissu-cli
  • /etc/chissu-pam/config.toml
  • /usr/lib/security/libpam_chissu.so
  • /var/lib/chissu-pam/embeddings/$USER.json
  • /var/lib/chissu-pam/dlib-models/shape_predictor_68_face_landmarks.dat
  • /var/lib/chissu-pam/dlib-models/dlib_face_recognition_resnet_model_v1.dat

Rough usage:

  • Register face images with chissu-cli enroll. sudo is not required here. It registers an encryption key with the D-Bus Secret Service and uses that to encrypt /var/lib/chissu-pam/embeddings/$USER.json.
  • Face authentication cannot be used on the login screen immediately after booting Linux. This is because the D-Bus Secret Service has not been initialized at this point. Even if you start without using a password here, you end up needing a password to initialize the Secret Service immediately after logging in.
  • Once the desktop is up, you can use face authentication for sudo, screen locks, and 1Password unlocking.
  • You can check if the settings are correct with chissu-cli doctor.

How did I proceed?

I consulted with Gemini on the selection of primary languages, libraries, and the general development strategy. I probably would have grown tired just researching how to create PAM modules without an LLM.

OpenSpec?

For the implementation itself, I integrated OpenSpec into the Codex CLI to proceed. I had previously tried SpecKit, but I felt a strong disconnect—while it preached "Spec Driven" development, I felt that it is difficult for people to finalize a spec from the very beginning. Aren't specs something that should grow little by little? Also, I felt like the sheer volume of Markdown output from SpecKit was overwhelming, making me wonder, "Do I really have to read all of this? Wouldn't it be faster just to show me the code?"

OpenSpec separates files into changes and specs. First, by running /prompts:openspec-proposal $PROPOSAL, proposal.md, tasks.md, and spec.md are output to openspec/changes/$proposalId. None of these are particularly large. If they look good after a quick glance, running /prompts:openspec-apply kicks off the implementation. If the result looks good, you run /prompts:openspec-archive. This moves openspec/changes/$proposalId to openspec/changes/archive/yyyy-mm-dd-$proposalId and creates openspec/specs/$spec-name/spec.md containing the changes. The spec.md files under specs are sometimes newly created with a proposal, or existing ones are updated. You basically don’t need to look at archived proposals anymore because everything you need is contained within the specs. Example: https://github.com/sett4/chissu-pam/tree/main/openspec

There is an article titled Spec-Driven Development: The Waterfall Strikes Back, and I agree with it. Can everyone really write a perfect spec from the start? I strongly feel that specifications are things that should be nurtured. The approach of growing specifications didn't seem compatible with SpecKit. Therefore, OpenSpec’s workflow—adding granular requirements as proposals to grow the specs—suited me perfectly.

Development Steps

I started by implementing the components as a command-line tool:

  1. chissu-cli capture: Capture an image and output it as a PNG file.
  2. chissu-cli face extract: Extract features from the PNG using dlib.
  3. chissu-cli face compare: Output the similarity between features.
  4. chissu-cli face enroll: Place the result of the face extraction (embedding) in a designated directory.

By this point, I had added the necessary parts for face authentication bit by bit and verified the CLI operation (the element technology phase).

  1. libchissu_pam.so: When I generated the PAM module and it worked on the first try, I braced myself for the possibility of losing my job soon.
  2. chissu-cli enroll (CLI expansion): Added a command to execute capture, face extract, and face enroll all at once.

At this stage, face authentication was fully functional.

Afterward, I handled various minor tasks: using the D-Bus Secret Service to encrypt the embeddings, performing a fork() and setuid() to drop privileges because the root-run PAM module couldn't access the general user's Secret Service, and retrieving the DISPLAY from logind since 1Password didn't pass it over.

Security Aspects

There are probably two main points regarding security:

  • The accuracy of face recognition.
  • The storage method for embeddings.

Regarding recognition accuracy, I am using dlib's dlib_face_recognition_resnet_model_v1.dat, which should have sufficient accuracy.

The storage method for embeddings is the most concerning part. Howdy places files at /usr/local/etc/howdy/models/$USER.dat with root:root permissions set to 0644. Anyone can read them, and if you look inside, the 128-dimensional embedding vector is stored in plain text. Regarding whether embeddings should be confidential, I believe they might be. It seems not impossible to reconstruct an image if you know the target embedding. While a human might see that it is different, one could likely create something that tricks dlib. I am not an expert in this field, so I cannot say for sure, but I would prefer to keep the embeddings confidential if possible.

Therefore, I wanted to encrypt them for confidentiality. In chissu-pam, I set the permissions for /var/lib/chissu-pam/embeddings to 0666, making it readable and writable by anyone. This allows for non-root operation. Then, running chissu-cli enroll encrypts and places the file at /var/lib/chissu-pam/embeddings/$USER.json. Since the encryption key is retrieved from the D-Bus Secret Service, it can be considered secure.

The PAM module is called by root. It must access the D-Bus Secret Manager as the user attempting to log in, so I perform a fork() to create a process, setuid() to drop privileges, and then retrieve the encryption key. It performs inter-process communication with the parent process via a pipe.

The encryption key differs per user, so others cannot read it, and if someone tries to force a write, it will result in a decryption error, alerting the system that it has been tampered with.

Repository and Documentation

By the way, what webcam are you using?

I am using Elecom's UCAM-CF20FBBK. This device has an infrared camera mode at /dev/video2, and capturing with this turns on the infrared light as an auxiliary light. Therefore, just like a hacker in a movie, I can be recognized even in a dark room.

Usage

The setup procedure and how to integrate PAM are summarized in the README's "Getting Started" (https://github.com/sett4/chissu-pam#getting-started). You can try it out by just grasping how to install the dependency packages and the flow of chissu-pam enroll.

What do I want to do in the future?

I don't really understand Rust, so I don't know if the current code is any good.

I have ensured that there are no cargo clippy warnings, but basically, I am doing this via Vibe Coding and I don’t understand the validity of the Rust code at all. It is the end of the world that I am building an authentication module despite understanding absolutely nothing. Since it is indeed the end of the world, I would at least like to understand it properly.

Is it secure?

The directory /var/lib/chissu-pam/embeddings has world-writable permissions, and /var/lib/chissu-pam/embeddings/$USER.json is 600. The content is encrypted, but is this sufficiently secure? I would like to ask experts about this. I considered requesting a review via services like Crowdworks, but I figured I wouldn't easily find someone strong in Rust, Linux PAM, and security, and as of now, no one has reviewed it. Since I am the only one using it, I have published it on GitHub for now, waiting for a kind soul to take a look.

Create an installer

Contradicting my excuse that "it's just for me," now that it’s working, I want to create an installer or a Deb package so others can use it. I've never made a Deb package before, so I will have to rely on an LLM for that.

Conclusion

I created a Linux PAM face authentication module that works at a minimum. I made it, but I don't have confidence in the security or Rust, so I would be happy if someone read the code or tried it out. Issues and PRs are welcome (https://github.com/sett4/chissu-pam).

99% of the code was written by AI, but 90% of this article was written by a human.

Discussion