(define-module (vkraus services webid-oidc) #:use-module (gnu services) #:use-module (gnu services shepherd) #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (vkraus packages webid-oidc) #:use-module (guix gexp) #:use-module (guix modules) #:use-module (guix records) #:use-module (ice-9 match) #:use-module (ice-9 optargs)) (define-record-type* webid-oidc-issuer-configuration make-webid-oidc-issuer-configuration webid-oidc-issuer-configuration? (webid-oidc webid-oidc-issuer-configuration-webid-oidc (default webid-oidc)) (issuer webid-oidc-issuer-configuration-issuer) (key-file webid-oidc-issuer-configuration-key-file (default "/var/lib/webid-oidc/issuer/key.jwk")) (subject webid-oidc-issuer-configuration-subject) (password webid-oidc-issuer-configuration-password) (jwks-uri webid-oidc-issuer-configuration-jwks-uri) (authorization-endpoint-uri webid-oidc-issuer-configuration-authorization-endpoint-uri) (token-endpoint-uri webid-oidc-issuer-configuration-token-endpoint-uri) (port webid-oidc-issuer-configuration-port (default 8088)) (extra-options webid-oidc-issuer-configuration-extra-options (default '()))) (define-record-type* webid-oidc-reverse-proxy-configuration make-webid-oidc-reverse-proxy-configuration webid-oidc-reverse-proxy-configuration? (webid-oidc webid-oidc-reverse-proxy-configuration-webid-oidc (default webid-oidc)) (port webid-oidc-reverse-proxy-port (default 8090)) (inbound-uri webid-oidc-reverse-proxy-configuration-inbound-uri) (outbound-uri webid-oidc-reverse-proxy-configuration-outbound-uri) (header webid-oidc-reverse-proxy-configuration-header (default "XXX-Agent")) (extra-options webid-oidc-reverse-proxy-extra-options (default '()))) (define-record-type* webid-oidc-hello-configuration make-webid-oidc-hello-configuration webid-oidc-hello-configuration? (webid-oidc webid-oidc-hello-configuration-webid-oidc (default webid-oidc)) (port webid-oidc-hello-configuration-port (default 8089)) (extra-options webid-oidc-hello-configuration-extra-options (default '()))) (export webid-oidc-issuer-configuration make-webid-oidc-issuer-configuration webid-oidc-issuer-configuration? webid-oidc-issuer-configuration-webid-oidc webid-oidc-issuer-configuration-issuer webid-oidc-issuer-configuration-key-file webid-oidc-issuer-configuration-subject webid-oidc-issuer-configuration-password webid-oidc-issuer-configuration-jwks-uri webid-oidc-issuer-configuration-authorization-endpoint-uri webid-oidc-issuer-configuration-token-endpoint-uri webid-oidc-issuer-configuration-port webid-oidc-issuer-configuration-extra-options webid-oidc-reverse-proxy-configuration make-webid-oidc-reverse-proxy-configuration webid-oidc-reverse-proxy-configuration? webid-oidc-reverse-proxy-configuration-webid-oidc webid-oidc-reverse-proxy-configuration-port webid-oidc-reverse-proxy-configuration-inbound-uri webid-oidc-reverse-proxy-configuration-outbound-uri webid-oidc-reverse-proxy-configuration-header webid-oidc-reverse-proxy-configuration-extra-options webid-oidc-hello-configuration make-webid-oidc-hello-configuration webid-oidc-hello-configuration? webid-oidc-hello-configuration-webid-oidc webid-oidc-hello-configuration-port webid-oidc-hello-configuration-extra-options) (define webid-oidc-issuer-shepherd-service (match-lambda (($ webid-oidc issuer key-file subject password jwks-uri authorization-endpoint-uri token-endpoint-uri port extra-options) (with-imported-modules (source-module-closure '((gnu build shepherd) (gnu system file-systems))) (list (shepherd-service (provision '(webid-oidc-issuer)) (documentation "Run the Solid identity provider.") (requirement '(user-processes)) (modules '((gnu build shepherd) (gnu system file-systems))) (start #~(begin (let* ((user (getpwnam "webid-oidc")) (prepare-directory (lambda (dir) (mkdir-p dir) (chown dir (passwd:uid user) (passwd:gid user)) (chmod dir #o700)))) (prepare-directory "/var/log/webid-oidc") (prepare-directory "/var/lib/webid-oidc") (prepare-directory "/var/cache/webid-oidc")) (make-forkexec-constructor (list (string-append #$webid-oidc "/bin/webid-oidc-issuer") "--issuer" #$issuer "--key-file" #$key-file "--subject" #$subject "--password" #$password "--jwks-uri" #$jwks-uri "--authorization-endpoint-uri" #$authorization-endpoint-uri "--token-endpoint-uri" #$token-endpoint-uri "--port" (with-output-to-string (lambda () (display #$port))) "--log-file" "issuer.log" "--error-file" "issuer.err" #$@extra-options) #:user "webid-oidc" #:group "webid-oidc" #:directory "/var/log/webid-oidc" #:environment-variables `("XDG_DATA_HOME=/var/lib" "XDG_CACHE_HOME=/var/cache" "LANG=C")))) (stop #~(make-kill-destructor)))))))) (define webid-oidc-reverse-proxy-shepherd-service (match-lambda (($ webid-oidc port inbound-uri outbound-uri header extra-options) (with-imported-modules (source-module-closure '((gnu build shepherd) (gnu system file-systems))) (list (shepherd-service (provision '(webid-oidc-reverse-proxy)) (documentation "Run a proxy to authenticate with Solid.") (requirement '(user-processes)) (modules '((gnu build shepherd) (gnu system file-systems))) (start #~(begin (let* ((user (getpwnam "webid-oidc")) (prepare-directory (lambda (dir) (mkdir-p dir) (chown dir (passwd:uid user) (passwd:gid user)) (chmod dir #o700)))) (prepare-directory "/var/log/webid-oidc") (prepare-directory "/var/lib/webid-oidc") (prepare-directory "/var/cache/webid-oidc")) (make-forkexec-constructor (list (string-append #$webid-oidc "/bin/webid-oidc-reverse-proxy") "--port" (with-output-to-string (lambda () (display #$port))) "--inbound-uri" #$inbound-uri "--outbound-uri" #$outbound-uri "--header" #$header "--log-file" "reverse-proxy.log" "--error-file" "reverse-proxy.err" #$@extra-options) #:user "webid-oidc" #:group "webid-oidc" #:directory "/var/log/webid-oidc" #:environment-variables `("XDG_DATA_HOME=/var/lib" "XDG_CACHE_HOME=/var/cache" "LANG=C")))) (stop #~(make-kill-destructor)))))))) (define webid-oidc-hello-shepherd-service (match-lambda (($ webid-oidc port extra-options) (with-imported-modules (source-module-closure '((gnu build shepherd) (gnu system file-systems))) (list (shepherd-service (provision '(webid-oidc-hello)) (documentation "Run a demonstration Solid server.") (requirement '(user-processes)) (modules '((gnu build shepherd) (gnu system file-systems))) (start #~(begin (let* ((user (getpwnam "webid-oidc")) (prepare-directory (lambda (dir) (mkdir-p dir) (chown dir (passwd:uid user) (passwd:gid user)) (chmod dir #o700)))) (prepare-directory "/var/log/webid-oidc") (prepare-directory "/var/lib/webid-oidc") (prepare-directory "/var/cache/webid-oidc")) (make-forkexec-constructor (list (string-append #$webid-oidc "/bin/webid-oidc-hello") "--port" (with-output-to-string (lambda () (display #$port))) #$@extra-options) #:user "webid-oidc" #:group "webid-oidc" #:directory "/var/log/webid-oidc" #:environment-variables `("XDG_DATA_HOME=/var/lib" "XDG_CACHE_HOME=/var/cache" "LANG=C")))) (stop #~(make-kill-destructor)))))))) (define %webid-oidc-accounts (list (user-group (name "webid-oidc") (system? #t)) (user-account (name "webid-oidc") (group "webid-oidc") (system? #t) (comment "The user that runs the webid-oidc issuer and resource server.") (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define-public webid-oidc-issuer-service-type (service-type (name 'webid-oidc-issuer) (extensions (list (service-extension account-service-type (const %webid-oidc-accounts)) (service-extension shepherd-root-service-type webid-oidc-issuer-shepherd-service))))) (define-public webid-oidc-reverse-proxy-service-type (service-type (name 'webid-oidc-reverse-proxy) (extensions (list (service-extension account-service-type (const %webid-oidc-accounts)) (service-extension shepherd-root-service-type webid-oidc-reverse-proxy-shepherd-service))))) (define-public webid-oidc-hello-service-type (service-type (name 'webid-oidc-hello) (extensions (list (service-extension account-service-type (const %webid-oidc-accounts)) (service-extension shepherd-root-service-type webid-oidc-hello-shepherd-service)))))