public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Tobias Hagelborn <tobias.hagelborn@axis.com>,
	 openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] [PATCH] lib/oe/gpg_sign.py: Avoid race when creating .sig files in detach_sign
Date: Wed, 29 Mar 2023 23:33:25 +0100	[thread overview]
Message-ID: <d7fad7b0cea99470a35d5c3c0f057d6e4f70f758.camel@linuxfoundation.org> (raw)
In-Reply-To: <20230323100847.3740485-1-tobiasha@axis.com>

On Thu, 2023-03-23 at 11:08 +0100, Tobias Hagelborn wrote:
> Move the signature file into place only after it is successfully signed.
> This to avoid race and corrupted .sig files in cases multiple onging
> builds write to a shared sstate-cache dir.
> 
> Signed-off-by: Tobias Hagelborn <tobiasha@axis.com>
> ---
>  meta/lib/oe/gpg_sign.py | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/meta/lib/oe/gpg_sign.py b/meta/lib/oe/gpg_sign.py
> index 613dab8561..868846cdc5 100644
> --- a/meta/lib/oe/gpg_sign.py
> +++ b/meta/lib/oe/gpg_sign.py
> @@ -5,11 +5,12 @@
>  #
>  
>  """Helper module for GPG signing"""
> -import os
>  
>  import bb
> -import subprocess
> +import os
>  import shlex
> +import subprocess
> +import tempfile
>  
>  class LocalSigner(object):
>      """Class for handling local (on the build host) signing"""
> @@ -73,8 +74,6 @@ class LocalSigner(object):
>              cmd += ['--homedir', self.gpg_path]
>          if armor:
>              cmd += ['--armor']
> -        if output_suffix:
> -            cmd += ['-o', input_file + "." + output_suffix]
>          if use_sha256:
>              cmd += ['--digest-algo', "SHA256"]
>  
> @@ -83,19 +82,25 @@ class LocalSigner(object):
>          if self.gpg_version > (2,1,):
>              cmd += ['--pinentry-mode', 'loopback']
>  
> -        cmd += [input_file]
> -
>          try:
>              if passphrase_file:
>                  with open(passphrase_file) as fobj:
>                      passphrase = fobj.readline();
>  
> -            job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
> -            (_, stderr) = job.communicate(passphrase.encode("utf-8"))
> +            output_file = input_file + "." + (output_suffix or 'sig')

This doesn't match the behaviour of output_suffix as used above where
it defaults to None. This forces it to a default of "sig" instead?

If that intentional that should be in the commit message.


> +            with tempfile.TemporaryDirectory(dir=os.path.dirname(output_file)) as tmp_dir:
> +                tmp_file = os.path.join(tmp_dir, os.path.basename(output_file))
> +                cmd += ['-o', tmp_file]
> +
> +                cmd += [input_file]
> +
> +                job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
> +                (_, stderr) = job.communicate(passphrase.encode("utf-8"))
>  
> -            if job.returncode:
> -                bb.fatal("GPG exited with code %d: %s" % (job.returncode, stderr.decode("utf-8")))
> +                if job.returncode:
> +                    bb.fatal("GPG exited with code %d: %s" % (job.returncode, stderr.decode("utf-8")))
>  
> +                os.rename(tmp_file, output_file)
>          except IOError as e:
>              bb.error("IO error (%s): %s" % (e.errno, e.strerror))
>              raise Exception("Failed to sign '%s'" % input_file)

Cheers,

Richard


  reply	other threads:[~2023-03-29 22:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 10:08 [PATCH] lib/oe/gpg_sign.py: Avoid race when creating .sig files in detach_sign Tobias Hagelborn
2023-03-29 22:33 ` Richard Purdie [this message]
     [not found] ` <1751049D3A378E36.12651@lists.openembedded.org>
2023-03-30  9:10   ` [OE-core] " Richard Purdie
2023-03-30 12:39     ` Tobias Hagelborn
2023-03-30 12:54     ` Alexandre Belloni
     [not found]   ` <1751275EEB419793.12651@lists.openembedded.org>
2023-03-30  9:14     ` Richard Purdie
     [not found] <174F047FDC936771.19937@lists.openembedded.org>
2023-03-23 10:13 ` Tobias Hagelborn

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

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

  git send-email \
    --in-reply-to=d7fad7b0cea99470a35d5c3c0f057d6e4f70f758.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=tobias.hagelborn@axis.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox