きりかノート 3冊め

おあそびプログラミング

MacBookのTouch IDでsudoを使う(PAM)

MacBookに付いてるTouch IDでsudoできないかなあと探してみたら、"「MacBook Proの「Touch ID」を利用してsudoなどの認証を行うPAMが公開。 | AAPL Ch.」"という記事を見つけたので試してみた。

手順は

1. pam_touchidコンパイルして、てきとうな場所に置く
2. /etc/pam.d/sudo を編集して上記のモジュールの記述を**先頭に**追加

となる。これだけでちゃんと動いて、なんか不思議な感じする。。

ローカルにPortfile書いてインストールして設定した。issueでSSHのケース議論してたり、コードまだ読んでなかったりと自信ないので公式のportには入れてない。brewもまだないっぽいし。

   % port contents pam_touchid
   Port pam_touchid contains:
     /opt/local/lib/pam/pam_touchid.so.2
     /opt/local/share/doc/pam_touchid/LICENSE
     /opt/local/share/doc/pam_touchid/README.md
     /opt/local/share/doc/pam_touchid/screenshot.png
   % grep -n pam_touchid /etc/pam.d/sudo
   2:auth     sufficient     /opt/local/lib/pam/pam_touchid.so reason="execute a command as another user"
   % port cat pam_touchid
   # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

   PortSystem          1.0
   PortGroup           github 1.0
   PortGroup           xcode 1.0

   github.setup        hamzasood pam_touchid 0.0.1
   github.version      ec7b7bdc1285b3588fe083d5bb9ac5ab5137fda2
   categories          security
   description         A PAM module for authentication with Touch ID
   long_description    ${description}

   platforms           darwin
   license             GPL-3
   maintainers         kimuraw openmaintainer

   checksums           md5  5a80622d1150b9ff34515e7e97ee3a9c \
                       sha1 b08b8d338574da2131faaebd9f188098c93d51a1 \
                       sha256  7bac41ef30b7ba4a69aea5f8683d3b035a469139697f985ab8030c68f9724a13

   xcode.project       pam_touchid.xcodeproj
   xcode.configuration Release
   xcode.destroot.path ${prefix}/lib/pam
   xcode.destroot.type none
   # build without code signing for macports
   xcode.build.settings    CODE_SIGN_IDENTITY=
   xcode.destroot.settings CODE_SIGN_IDENTITY= INSTALL_MODE_FLAG=440

   post-destroot {
       xinstall -d ${destroot}${prefix}/share/doc/${name}
       xinstall -W ${worksrcpath} README.md LICENSE screenshot.png \
           ${destroot}${prefix}/share/doc/${name}
   }

    post-activate {
       ui_msg ""
       ui_msg "================================================================================"
       ui_msg "If you try to use Touch ID with `sudo` command, add the below line to the top "
       ui_msg "of \"/etc/pam.d/sudo\". (see ${homepage})"
       ui_msg ""
       ui_msg "auth sufficient ${prefix}/lib/pam/pam_touchid.so reason=\"execute a command as another user\""
       ui_msg "================================================================================"
       ui_msg ""
   }

(2016-12-30 追記)reasonをローカライズする方法がわからない……別に英語で出るのはかまわんのだけど、日本語のメッセージにまざってるとかっこ悪いしなあ。