unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Attila Lendvai <attila@lendvai.name>
Cc: 50814@debbugs.gnu.org
Subject: [bug#50814] [PATCH] guix: git-authenticate: Also authenticate the channel intro commit.
Date: Mon, 10 Jan 2022 15:53:38 +0100	[thread overview]
Message-ID: <87sftvy74d.fsf_-_@gnu.org> (raw)
In-Reply-To: <20211018155734.5175-5-attila@lendvai.name> (Attila Lendvai's message of "Mon, 18 Oct 2021 17:57:34 +0200")

Hi Attila,

Sorry for dropping the ball.  On the private guix-security mailing list,
I just sent an analysis showing why the bug reported there was, AFAICS,
not a bug; however, the test here is different and seems to be poised to
expose a different problem.

Attila Lendvai <attila@lendvai.name> skribis:

> This test used to fail before a recent fix to authenticate-repository.
>
> * tests/git-authenticate.scm: New test "signed commits, .guix-authorizations,
> channel-introduction".

I won’t comment on the whole test for now, because it’s too complex, but
here’s what I noticed:


[...]

> +            (checkout "main" orphan)
> +            (add "noise0")
> +            (add ".guix-authorizations"
> +                 ,(object->string
> +                   `(authorizations
> +                     (version 0)
> +                     ((,(key-fingerprint key1) (name "Alice"))
> +                      ;; Notice that key2 is not authorized at this point.
> +                      (,(key-fingerprint key3) (name "Charlie"))))))
> +            (commit "commit 0" (signer ,(key-fingerprint key3)))
> +            (add "noise1")
> +            (commit "commit 1" (signer ,(key-fingerprint key1)))
> +            (add "noise2")
> +            (commit "commit 2" (signer ,(key-fingerprint key1))))
> +        (with-repository dir repo
> +          (let* ((commit-0 (find-commit repo "commit 0"))
> +                 (check-from
> +                  (lambda* (commit #:key (should-fail? #false) (key key1)
> +                                   (historical-authorizations
> +                                    ;; Let's mark key3 to be trusted
> +                                    ;; unconditionally, so that it authorizes
> +                                    ;; commit 0.
> +                                    (list (key-fingerprint-vector key3))))

This is exercising support for “historical authorizations”, which works
slightly differently than the regular ‘.guix-authorizations’-process
used by ‘guix pull’ & co.

> +                      (set! commit (find-commit repo commit))

Mutation is making it harder for me to understand what the test does.

> +            (with-git-repository dir
> +                ;; Drop the faulty commit 3
> +                `((reset ,(oid->string (commit-id (find-commit repo "commit 2"))))
> +                  (add "noise 4")
> +                  (add ".guix-authorizations"
> +                       ,(object->string
> +                         ;; Remove key3, add key2.
> +                         `(authorizations
> +                           (version 0)
> +                           ((,(key-fingerprint key1) (name "Alice"))
> +                            (,(key-fingerprint key2) (name "Bob"))))))
> +                  (commit "commit 4" (signer ,(key-fingerprint key2))))

Due to ‘reset’ here, the intro commit that ‘check-from’ passes to
‘authenticate-repository’ is no longer the right one (IIUC).

> +              ;; This should fail because even though commit 4 adds key2 to
> +              ;; .guix-authorizations, but commit 1 was created prior to that,
> +              ;; therefore it is not authorized.
> +              (check-from "commit 1" #:should-fail? #true)
> +              ;; This should pass, because it's a valid channel intro at commit 4
> +              (check-from "commit 4" #:key key2))
> +            (with-git-repository dir
> +                `((add "noise 5")
> +                  (commit "commit 5" (signer ,(key-fingerprint key2))))
> +              ;; It is not very intuitive why commit 1 and 2 should be trusted
> +              ;; at this point: commit 4 has previously been used as a channel
> +              ;; intro, thus it got marked as trusted in the ~/.cache/.
> +              ;; Because commit 1 and 2 are among its parents, it should also
> +              ;; be trusted at this point because of the cache.  Note that
> +              ;; it's debatable whether this semantics is a good idea, but
> +              ;; this is how git-authenticate is and has been implemented for
> +              ;; a while (modulo failing to update the cache in the past when
> +              ;; taking certain code paths).

Any commit in the closure of one of those listed in
~/.cache/guix/authentication is considered authentic.

So, if you arrange to populate that file with IDs of commits that were
not authenticated, then yes, you’ll find that ‘authenticate-repository’
reports surprising things.  But that’s because fundamentally, we cannot
protect the user from self-inflicted attacks.

To summarize, I do not see a bug here, but I’m also not sure what the
test was trying to demonstrate.

Could you boil it down?  (Keep in mind that it takes a lot of time to
merely review and under the test and claim.)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On guix-security (in your Dec. 22, 2021, message), you provided a
different test case, showing that the introductory commit’s signature is
not verified when ‘authenticate-repository’ is asked to authenticate an
empty commit range (introductory commit = tip of the branch).  This is
due to the (null? commit) condition in ‘authenticate-repository’:

  ;; When COMMITS is empty, it's because END-COMMIT is in the closure of
  ;; START-COMMIT and/or AUTHENTICATED-COMMITS, in which case it's known to
  ;; be authentic already.
  (if (null? commits)
      '()
      (let ((reporter (make-reporter start-commit end-commit commits)))
        ;; If it's our first time, verify START-COMMIT's signature.
        (when (null? authenticated-commits)
          (verify-introductory-commit repository keyring
                                      start-commit signer))

        …))

When START = END, the (null? commits) condition is true, and thus
‘verify-introductory-commit’ is not called.  This is the “bug”, although
START = END is a situation where there’s not much to do anyway.

As I wrote, we could move the ‘verify-introductory-commit’ call before
the ‘if’, specifically for this test case, but that doesn’t strike me as
useful; it may also have a visible performance impact on real cases.

Thanks,
Ludo’.




  reply	other threads:[~2022-01-10 15:14 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-26 10:19 [bug#50814] [PATCH] guix: git-authenticate: Also authenticate the channel intro commit Attila Lendvai
2021-09-26 18:02 ` Leo Famulari
2021-10-09 13:44   ` Ludovic Courtès
2021-10-12 15:17     ` Leo Famulari
2021-09-26 18:14 ` Maxime Devos
2021-09-27 18:01   ` Attila Lendvai
2021-09-27 18:45   ` Attila Lendvai
2021-09-28 10:02     ` Maxime Devos
2021-09-28  1:05 ` [bug#50814] [PATCH 1/4] tests: Smarten up git repository testing framework Attila Lendvai
2021-09-28  1:05   ` [bug#50814] [PATCH 2/4] tests: Move keys into ./tests/keys/ and add a third ed25519 key Attila Lendvai
2021-09-28  1:05   ` [bug#50814] [PATCH 3/4] tests: Add failing test for .guix-authorizations and channel intro Attila Lendvai
2021-09-29 13:58     ` Maxime Devos
2021-09-28  1:05   ` [bug#50814] [PATCH 4/4] guix: git-authenticate: Fix authenticate-repository Attila Lendvai
2021-09-28 16:24 ` [bug#50814] [PATCH 1/5] tests: Smarten up git repository testing framework Attila Lendvai
2021-09-28 16:24   ` [bug#50814] [PATCH 2/5] tests: Move keys into ./tests/keys/ and add a third ed25519 key Attila Lendvai
2021-09-28 16:24   ` [bug#50814] [PATCH 3/5] tests: Add failing test for .guix-authorizations and channel intro Attila Lendvai
2021-09-28 16:24   ` [bug#50814] [PATCH 4/5] guix: Prepare the UI for continuable &warning exceptions Attila Lendvai
2021-09-29 14:13     ` Maxime Devos
2021-09-29 14:50       ` Attila Lendvai
2021-09-29 20:36         ` Maxime Devos
2021-09-29 21:22           ` Attila Lendvai
2021-09-29 22:03             ` Maxime Devos
2021-09-28 16:24   ` [bug#50814] [PATCH 5/5] guix: git-authenticate: Fix authenticate-repository Attila Lendvai
2021-09-29 23:14     ` Maxime Devos
2021-10-09 13:53 ` [bug#50814] [PATCH] guix: git-authenticate: Also authenticate the channel intro commit Ludovic Courtès
2021-10-09 15:31   ` Attila Lendvai
2021-10-12  9:39     ` Ludovic Courtès
2021-10-17 10:09     ` Attila Lendvai
2021-10-18  9:10       ` Ludovic Courtès
2021-10-18 15:27         ` Attila Lendvai
2021-10-10 14:15 ` [bug#50814] [PATCH] tests: Add test for .guix-authorizations and channel intro Attila Lendvai
2021-10-18 15:57 ` [bug#50814] [PATCH 1/5] tests: Smarten up git repository testing framework Attila Lendvai
2021-10-18 15:57   ` [bug#50814] [PATCH 2/5] tests: Move keys into ./tests/keys/ and add a third ed25519 key Attila Lendvai
2021-10-18 15:57   ` [bug#50814] [PATCH 3/5] guix: Prepare the UI for continuable &warning exceptions Attila Lendvai
2021-10-18 15:57   ` [bug#50814] [PATCH 4/5] guix: git-authenticate: Fix authenticate-repository Attila Lendvai
2021-10-18 15:57   ` [bug#50814] [PATCH 5/5] tests: Add test for .guix-authorizations and channel intro Attila Lendvai
2022-01-10 14:53     ` Ludovic Courtès [this message]
2022-04-04  6:47 ` [bug#50814] [PATCH] guix: git-authenticate: Also authenticate the channel intro commit Attila Lendvai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sftvy74d.fsf_-_@gnu.org \
    --to=ludo@gnu.org \
    --cc=50814@debbugs.gnu.org \
    --cc=attila@lendvai.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).