[RFC PATCH consfigurator] WIP: support pass(1) format data sources

David Bremner david at tethera.net
Tue Dec 28 19:13:24 GMT 2021


---
 consfigurator.asd  |  3 +-
 src/data/pass.lisp | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 src/package.lisp   |  4 ++-
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 src/data/pass.lisp

This is an initial attempt to use a local pass(1) password store as a
data source in consfigurator.

* Are there security implications here that I've missed? I saw the
  passphrase class in data.lisp, but this seems like wrong level to apply that.

* A typical pass entry might be "host.example.com/username", and we'd
  currently expect people to pass IDEN1="host.example.com" and
  IDEN2="username". In principle this collides with a file called
  "username" on host.example.com, maybe this is not a problem?

* should we try to reduce code duplication? The function %read-gpg is
  a small modification of data.pgp:read-store, substituting string
  trimming for reading; the register data source function is pretty
  similar to that in files-tree. Does it make sense to base one data
  source on another one?

* The choice of interface is the on-disk layout used by pass. This is
  justified (?) by the existence of e.g. gopass, which does the same
  thing.

diff --git a/consfigurator.asd b/consfigurator.asd
index ab31dcc..86e592d 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -94,7 +94,8 @@
 	       (:file "src/data/gpgpubkeys")
                (:file "src/data/ssh-askpass")
                (:file "src/data/local-file")
-               (:file "src/data/files-tree"))
+               (:file "src/data/files-tree")
+               (:file "src/data/pass"))
   :in-order-to ((test-op (test-op "consfigurator/tests"))))
 
 (defsystem "consfigurator/tests"
diff --git a/src/data/pass.lisp b/src/data/pass.lisp
new file mode 100644
index 0000000..11078d8
--- /dev/null
+++ b/src/data/pass.lisp
@@ -0,0 +1,70 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2021  David Bremner <david at tethera.net>
+
+;;; This file is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator.data.pass)
+(named-readtables:in-readtable :consfigurator)
+
+;; based on data.pgp:read-store
+(defun %read-gpg (location)
+  (handler-case
+      (string-right-trim
+       '(#\Return #\Newline)
+       (run-program
+        (escape-sh-command (list "gpg" "--decrypt" (unix-namestring location)))
+       :output :string))
+    (subprocess-error (error)
+      (missing-data-source "While attempt to decrypt, gpg exited with ~A"
+			   (uiop:subprocess-error-code error)))))
+
+(defmethod register-data-source ((type (eql :pass)) &key (location "~/.password-store"))
+  "Provide the contents of a pass(1)  on the machine running the root
+Lisp.  Register this data source multiple times to provide multiple stores.
+
+LOCATION specifies the root of the password store.
+
+IDEN1 specifies a (possibly nested) subdirectory under LOCATION and IDEN2 a
+relative path within that subdirectory.  For convenience IDEN1 and IDEN2 may
+be passed as absolute and will be converted to relative paths.  The usual
+cases of IDEN1 as a hostname, IDEN1 as an underscore-prefixed identifier, and
+IDEN2 an an absolute or relative path are all supported."
+  (let ((base-path (ensure-directory-pathname (uiop:native-namestring location))))
+    (unless (directory-exists-p base-path)
+      (missing-data-source
+       "~A does not exist, or is not a directory." base-path))
+    (labels ((%make-path (iden1 iden2)
+               (merge-pathnames
+                (uiop:relativize-pathname-directory
+                 (uiop:parse-unix-namestring iden2 :type "gpg"))
+                (merge-pathnames
+                 (uiop:relativize-pathname-directory
+                  (ensure-directory-pathname iden1))
+                 base-path)))
+             (check (iden1 iden2)
+               (let ((file-path (%make-path iden1 iden2)))
+                 (informat 4 "called check ~a ~a ~a~%" iden1 iden2 file-path)
+                 (and (file-exists-p file-path)
+                      (file-write-date file-path))))
+             (extract (iden1 iden2)
+               (let ((file-path (%make-path iden1 iden2)))
+                 (princ "called extract")
+                 (and (file-exists-p file-path)
+                      (make-instance 'string-data
+                                     :string (%read-gpg file-path)
+                                     :iden1 iden1
+                                     :iden2 iden2
+                                     :version (file-write-date file-path))))))
+      (cons #'check #'extract))))
diff --git a/src/package.lisp b/src/package.lisp
index acc6b85..7259094 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -1015,4 +1015,6 @@
 
   (package :consfigurator.data.local-file)
 
-  (package :consfigurator.data.files-tree))
+  (package :consfigurator.data.files-tree)
+
+  (package :consfigurator.data.pass))
-- 
2.34.1




More information about the sgo-software-discuss mailing list