substitute: Make '%allow-unauthenticated-substitutes?' public.

* guix/scripts/substitute.scm (warn-about-missing-authentication): New
procedure.
(%allow-unauthenticated-substitutes?): Turn into a public parameter and
use 'warn-about-missing-authentication'.
(valid-narinfo?): Adjust accordingly.
* tests/substitute.scm (call-with-narinfo): Likewise.
This commit is contained in:
Ludovic Courtès 2019-11-26 12:30:45 +01:00
parent 7f3bbfaf8e
commit 434138e2f2
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 17 additions and 11 deletions

View file

@ -86,6 +86,8 @@ (define-module (guix scripts substitute)
read-narinfo
write-narinfo
%allow-unauthenticated-substitutes?
substitute-urls
guix-substitute))
@ -118,15 +120,21 @@ (define %narinfo-cache-directory
(string-append %state-directory "/substitute/cache"))
(string-append (cache-directory #:ensure? #f) "/substitute")))
(define (warn-about-missing-authentication)
(warning (G_ "authentication and authorization of substitutes \
disabled!~%"))
#t)
(define %allow-unauthenticated-substitutes?
;; Whether to allow unchecked substitutes. This is useful for testing
;; purposes, and should be avoided otherwise.
(and (and=> (getenv "GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES")
(cut string-ci=? <> "yes"))
(begin
(warning (G_ "authentication and authorization of substitutes \
disabled!~%"))
#t)))
(make-parameter
(and=> (getenv "GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES")
(cut string-ci=? <> "yes"))
(lambda (value)
(when value
(warn-about-missing-authentication))
value)))
(define %narinfo-ttl
;; Number of seconds during which cached narinfo lookups are considered
@ -370,7 +378,7 @@ (define %mandatory-fields
(define* (valid-narinfo? narinfo #:optional (acl (current-acl))
#:key verbose?)
"Return #t if NARINFO's signature is not valid."
(or %allow-unauthenticated-substitutes?
(or (%allow-unauthenticated-substitutes?)
(let ((hash (narinfo-sha256 narinfo))
(signature (narinfo-signature narinfo))
(uri (uri->string (first (narinfo-uris narinfo)))))

View file

@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2014, 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@ -169,9 +169,7 @@ (define* (call-with-narinfo narinfo thunk
(cute write-file
(string-append narinfo-directory "/example.out") <>))
(set! (@@ (guix scripts substitute)
%allow-unauthenticated-substitutes?)
#f))
(%allow-unauthenticated-substitutes? #f))
thunk
(lambda ()
(when (file-exists? cache-directory)