-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove PGP signature verification skip for DEV builds (#3590)
* remove PGP signature verification skip for DEV builds * create pgptest package to sign and give the public key to verify the signature * fix tests that relied on skipping the PGP verification * add PGP/GPG how-to on docs * add test for VerifySHA512HashWithCleanup (cherry picked from commit e43be2a) # Conflicts: # internal/pkg/agent/application/upgrade/artifact/download/fs/verifier.go # internal/pkg/agent/application/upgrade/artifact/download/http/verifier.go
- Loading branch information
Showing
26 changed files
with
891 additions
and
452 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Signing Elastic Agent artifacts | ||
|
||
This doc covers generating a key, exporting the public key, signing a file and verifying it using GPG as well as pure Go. | ||
|
||
Full GPG docs: https://www.gnupg.org/documentation/manuals/gnupg/OpenPGP-Key-Management.html | ||
|
||
|
||
## Go | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"golang.org/x/crypto/openpgp" | ||
"golang.org/x/crypto/openpgp/armor" | ||
) | ||
|
||
func main() { | ||
dir, err := os.MkdirTemp(os.TempDir(), "pgp-") | ||
NoError(err, "could not create directory to save the files to") | ||
|
||
key := filepath.Join(dir, "key") | ||
keyPub := filepath.Join(dir, "key.pub") | ||
asc := filepath.Join(dir, "plaindata.asc") | ||
|
||
fmt.Printf("Writing files to %q\n", dir) | ||
|
||
data := []byte("some data") | ||
plaindata := filepath.Join(dir, "plaindata") | ||
err = os.WriteFile(plaindata, data, 0o600) | ||
NoError(err, "could not write plain data file") | ||
|
||
fmt.Printf("wrote %q\n", plaindata) | ||
|
||
// Create files | ||
fKeyPub, err := os.OpenFile( | ||
keyPub, | ||
os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | ||
NoError(err, "could not create %q file", keyPub) | ||
defer func() { | ||
if err := fKeyPub.Close(); err != nil { | ||
fmt.Printf("failed closing %q\n", fKeyPub.Name()) | ||
} | ||
fmt.Printf("wrote %q\n", fKeyPub.Name()) | ||
}() | ||
|
||
fKey, err := os.OpenFile( | ||
key, | ||
os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | ||
NoError(err, "could not create %q file", key) | ||
defer func() { | ||
if err := fKey.Close(); err != nil { | ||
fmt.Printf("failed closing %q\n", fKey.Name()) | ||
} | ||
fmt.Printf("wrote %q\n", fKey.Name()) | ||
}() | ||
|
||
fasc, err := os.OpenFile( | ||
asc, | ||
os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | ||
NoError(err, "could not create %q file", asc) | ||
defer func() { | ||
if err := fasc.Close(); err != nil { | ||
fmt.Printf("failed closing %q\n", fasc.Name()) | ||
} | ||
fmt.Printf("wrote %q\n", fasc.Name()) | ||
}() | ||
|
||
// Generate PGP key | ||
entity, err := openpgp.NewEntity("someKeyName", "", "", nil) | ||
|
||
// Create an ASCII armored encoder to serialize the private key | ||
wPubKey, err := armor.Encode(fKeyPub, openpgp.PublicKeyType, nil) | ||
NoError(err, "could not create PGP ASCII Armor encoder for public key") | ||
defer func() { | ||
err := wPubKey.Close() | ||
if err != nil { | ||
fmt.Println("failed closing private key writer") | ||
} | ||
}() | ||
|
||
// Writes the public key to the io.Writer passed to armor.Encode. | ||
// Use entity.SerializePrivate if you need the private key. | ||
err = entity.Serialize(wPubKey) | ||
NoError(err, "could not serialize the public key") | ||
|
||
// Create an ASCII armored encoder to serialize the private key | ||
wPrivKey, err := armor.Encode(fKey, openpgp.PrivateKeyType, nil) | ||
NoError(err, "could not create PGP ASCII Armor encoder for private key") | ||
defer func() { | ||
err := wPrivKey.Close() | ||
if err != nil { | ||
fmt.Println("failed closing private key writer") | ||
} | ||
}() | ||
|
||
// Writes the private key to the io.Writer passed to armor.Encode. | ||
// Use entity.SerializePrivate if you need the private key. | ||
err = entity.SerializePrivate(wPrivKey, nil) | ||
NoError(err, "could not serialize the private key") | ||
|
||
// Sign data and write the detached signature to fasc | ||
err = openpgp.ArmoredDetachSign(fasc, entity, bytes.NewReader(data), nil) | ||
NoError(err, "failed signing date") | ||
} | ||
|
||
func NoError(err error, msg string, args ...any) { | ||
if err != nil { | ||
panic(fmt.Sprintf(msg+": %v", append(args, err))) | ||
} | ||
} | ||
``` | ||
|
||
## GPG | ||
### Generate a key | ||
|
||
```shell | ||
gpg --no-default-keyring --keyring ./some-file-to-be-the-key-ring --quick-generate-key atest rsa2048 default none | ||
``` | ||
Where: | ||
- `--no-default-keyring`: do not use your keyring | ||
- `--keyring ./some-file-to-be-the-key-ring`: keyring to use, as the file do not exist, it'll create it | ||
- `--quick-generate-key`: quick generate the key | ||
- `atest`: user-id, a.k.a the key identifier | ||
- `rsa2048`: algorithm to use | ||
- `default`: "usage" for the key. Just use default | ||
- `none`: key expiration | ||
|
||
|
||
### Export the public key | ||
```shell | ||
gpg --no-default-keyring --keyring ./some-file-to-be-the-key-ring --armor --output public-key.pgp --export atest | ||
``` | ||
Where: | ||
- `--no-default-keyring`: do not use your keyring | ||
- `--keyring ./some-file-to-be-the-key-ring`: the keyring to use, created in the previous step | ||
- `--armor`: create ASCII armoured output. Otherwise, it's a binary format | ||
- `--output public-key.pgp`: the output file | ||
- `--export`: export the public key | ||
- `atest`: the key identifier | ||
|
||
### Sing the file | ||
```shell | ||
gpg --no-default-keyring --keyring ./some-file-to-be-the-key-ring -a -o elastic-agent-8.0.0-darwin-x86_64.tar.gz.asc --detach-sign elastic-agent-8.0.0-darwin-x86_64.tar.gz | ||
``` | ||
|
||
Where: | ||
- `-a -o`: --armored, --output | ||
- `elastic-agent-8.0.0-darwin-x86_64.tar.gz.asc`: the output file | ||
- `--detach-sign`: generate a separated file for signature | ||
- `elastic-agent-8.0.0-darwin-x86_64.tar.gz`: the file to sign | ||
|
||
|
||
|
||
### Verify the file | ||
|
||
#### Import the public key | ||
```shell | ||
gpg --no-default-keyring --keyring ./new-keyring --import public-key.pgp | ||
``` | ||
Where: | ||
- `--import`: import a key | ||
- `public-key.pgp`: the key to import | ||
|
||
#### Verify the signature using the imported key | ||
```shell | ||
gpg --no-default-keyring --keyring ./new-keyring --verify elastic-agent-8.0.0-darwin-x86_64.tar.gz.asc | ||
``` | ||
Where: | ||
- `--verify`: verify a signature | ||
- `elastic-agent-8.0.0-darwin-x86_64.tar.gz.asc`: the detached signature file. It'll assume the file to be verified is `elastic-agent-8.0.0-darwin-x86_64.tar.gz` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
...n/upgrade/artifact/download/fs/testdata/drop/elastic-agent-8.0.0-darwin-x86_64.tar.gz.asc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
|
||
iQGzBAABCgAdFiEE81a455Doc5DWexOcF4e6ez4rqzAFAmUn7TsACgkQF4e6ez4r | ||
qzDcIgwArpuXDex9aisWFWkXjCfjhJdrTTXr3wv8W68NeFsAaazLlvsWPxdol1db | ||
FeKFL+P/P/PhlTvdkZw9xMyXoVRWQXJ2p2jVjV0Wq2SCtbbjdrGjQ4OrchgE9FW7 | ||
onWxqV8RjzPyaMwpDWWtHKgxhQeLP5yXhWm6RXHvBLZ5mqbTCuIq2Q4sijEd6IFD | ||
9JoAA276tqyKGOsPZ1QzaPUFF69B9QLcWasEuNFf5ytMVFfTcMl6/HYDPO7ErhJx | ||
E1hnKGIc5rrMghL0LzaVLGYZUtnQwru02ZA0omXzEv1uYgqmZl75g9qHk2Cu2V5W | ||
0qbg9OtUKOkJ1sODvsVv8O40rVazdZTgL2ifNLi2wFwR3syMdHCih2aKMcPDPzt3 | ||
Q4q0zvsxuR9PGsv5+8zze74iC3oZSvF8h36XGjJuyjEFORUpcWNGDmhsC6l7ql5W | ||
rEbIPZ19j3r1M4yHG/ptBmrwRnQz9RKFnwTO9ME/5eBVumPLUD5kAcYXjvAFYQI5 | ||
qEc7okL5 | ||
=+nvi | ||
-----END PGP SIGNATURE----- |
2 changes: 1 addition & 1 deletion
2
...op/beat-8.0.0-darwin-x86_64.tar.gz.sha512 → ...c-agent-8.0.0-darwin-x86_64.tar.gz.sha512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
9af9aa016f3349aa248034629e4336ca2f4d31317bfb8c9a23a9d924c18969cf43ad93727e784da010a272690b2b5ce4c4ded3a5d2039e4408e93e1e18d113db beat-8.0.0-darwin-x86_64.tar.gz | ||
9af9aa016f3349aa248034629e4336ca2f4d31317bfb8c9a23a9d924c18969cf43ad93727e784da010a272690b2b5ce4c4ded3a5d2039e4408e93e1e18d113db elastic-agent-8.0.0-darwin-x86_64.tar.gz |
40 changes: 40 additions & 0 deletions
40
internal/pkg/agent/application/upgrade/artifact/download/fs/testdata/drop/public-key.pgp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-----BEGIN PGP PUBLIC KEY BLOCK----- | ||
|
||
mQGNBGUn7JEBDADH0iBdohpZIQY7QyBz9Hl68b7fq0zoFcB4HTDDM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Gyv5qu68eOZZXvkrCbDpysSIf7 | ||
YjwhmaZuerd4oBvRKJHbbHoqgde8sviSjm6cdU+ZSHILvwEaBLwW3pTgBJAupQcV | ||
4Ws7fo7/6R2YWws8c4sseGqLC+XxCXk+SvrvyA02ZBY+0L6IFD6Cb8BT0uMMrLIP | ||
YcZ1xK3gfrp4PCg2OFj46WER5ufHP1r0zvufY7chA9tP | ||
=Jwiw | ||
-----END PGP PUBLIC KEY BLOCK----- |
Oops, something went wrong.