Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature: Decode gpg secrets #126

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions containers/base_rpm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package containers

import "dagger.io/dagger"
import (
"encoding/base64"

"dagger.io/dagger"
)

const RPMMacros = `
%_signature gpg
Expand All @@ -21,8 +25,13 @@ func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container {
if !opts.Sign {
return container
}
gpgPublicKeyBase64Secret := d.SetSecret("gpg-public-key-base64", opts.GPGPublicKeyBase64)
gpgPrivateKeyBase64Secret := d.SetSecret("gpg-private-key-base64", opts.GPGPrivateKeyBase64)
var gpgPublicKeyBase64Secret, gpgPrivateKeyBase64Secret *dagger.Secret
if decodedGPGPublicKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPublicKeyBase64); err != nil {
gpgPublicKeyBase64Secret = d.SetSecret("gpg-public-key-base64", string(decodedGPGPublicKeyBase64Secret))
}
zerok marked this conversation as resolved.
Show resolved Hide resolved
if decodedGPGPrivateKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPrivateKeyBase64); err != nil {
gpgPrivateKeyBase64Secret = d.SetSecret("gpg-private-key-base64", string(decodedGPGPrivateKeyBase64Secret))
}
gpgPassphraseBase64Secret := d.SetSecret("gpg-passphrase-base64", opts.GPGPassphraseBase64)
return container.
WithSecretVariable("GPG_PUBLIC_KEY_BASE64", gpgPublicKeyBase64Secret).
Expand All @@ -32,9 +41,9 @@ func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container {
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/privkeys"}).
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/passkeys"}).
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/pubkeys"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PRIVATE_KEY_BASE64\" | base64 -d > /root/.rpmdb/privkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PASSPHRASE_BASE64\" | base64 -d > /root/.rpmdb/passkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PUBLIC_KEY_BASE64\" | base64 -d > /root/.rpmdb/pubkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PRIVATE_KEY_BASE64\" > /root/.rpmdb/privkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PASSPHRASE_BASE64\" > /root/.rpmdb/passkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PUBLIC_KEY_BASE64\" > /root/.rpmdb/pubkeys/grafana.key"}).
WithNewFile("/root/.rpmmacros", dagger.ContainerWithNewFileOpts{
Permissions: 0400,
Contents: RPMMacros,
Expand Down
Loading