Spack Package Signing
The goal of package signing in Spack is to provide data integrity assurances around official packages produced by the automated Spack CI pipelines. These assurances directly address the security of Spack’s software supply chain by explaining why a security-conscious user can be reasonably justified in the belief that packages installed via Spack have an uninterrupted auditable trail back to change management decisions judged to be appropriate by the Spack maintainers. This is achieved through cryptographic signing of packages built by Spack CI pipelines based on code that has been transparently reviewed and approved on GitHub. This document describes the signing process for interested users.
Risks, Impact and Threat Model
This document addresses the approach taken to safeguard Spack’s reputation with regard to the integrity of the package data produced by Spack’s CI pipelines. It does not address issues of data confidentiality (Spack is intended to be largely open source) or availability (efforts are described elsewhere). With that said the main reputational risk can be broadly categorized as a loss of faith in the data integrity due to a breach of the private key used to sign packages. Remediation of a private key breach would require republishing the public key with a revocation certificate, generating a new signing key, an assessment and potential rebuild/resigning of all packages since the key was breached, and finally direct intervention by every spack user to update their copy of Spack’s public keys used for local verification.
The primary threat model used in mitigating the risks of these stated impacts is one of individual error not malicious intent or insider threat. The primary objective is to avoid the above impacts by making a private key breach nearly impossible due to oversight or configuration error. Obvious and straightforward measures are taken to mitigate issues of malicious interference in data integrity and insider threats but these attack vectors are not systematically addressed. It should be hard to exfiltrate the private key intentionally, and almost impossible to leak the key by accident.
Spack pipelines build software through progressive stages where packages in later stages nominally depend on packages built in earlier stages. For both technical and design reasons these dependencies are not implemented through the default GitLab artifacts mechanism; instead built packages are uploaded to AWS S3 mirrors (buckets) where they are retrieved by subsequent stages in the pipeline. Two broad categories of pipelines exist: Pull Request (PR) pipelines and Develop/Release pipelines.
PR pipelines are launched in response to pull requests made by trusted and untrusted users. Packages built on these pipelines upload code to quarantined AWS S3 locations which cache the built packages for the purposes of review and iteration on the changes proposed in the pull request. Packages built on PR pipelines can come from untrusted users so signing of these pipelines is not implemented. Jobs in these pipelines are executed via normal GitLab runners both within the AWS GitLab infrastructure and at affiliated institutions.
Develop and Release pipelines sign the packages they produce and carry strong integrity assurances that trace back to auditable change management decisions. These pipelines only run after members from a trusted group of reviewers verify that the proposed changes in a pull request are appropriate. Once the PR is merged, or a release is cut, a pipeline is run on protected GitLab runners which provide access to the required signing keys within the job. Intermediary keys are used to sign packages in each stage of the pipeline as they are built and a final job officially signs each package external to any specific packages’ build environment. An intermediate key exists in the AWS infrastructure and for each affiliated instritution that maintains protected runners. The runners that execute these pipelines exclusively accept jobs from protected branches meaning the intermediate keys are never exposed to unreviewed code and the official keys are never exposed to any specific build environment.
Spack’s CI process uses public-key infrastructure (PKI) based on GNU Privacy Guard (gpg) keypairs to sign public releases of spack package metadata, also called specs. Two classes of GPG keys are involved in the process to reduce the impact of an individual private key compromise, these key classes are the Intermediate CI Key and Reputational Key. Each of these keys has signing sub-keys that are used exclusively for signing packages. This can be confusing so for the purpose of this explanation we’ll refer to Root and Signing keys. Each key has a private and a public component as well as one or more identities and zero or more signatures.
Intermediate CI Key
The Intermediate key class is used to sign and verify packages between stages within a develop or release pipeline. An intermediate key exists for the AWS infrastructure as well as each affiliated institution that maintains protected runners. These intermediate keys are made available to the GitLab execution environment building the package so that the package’s dependencies may be verified by the Signing Intermediate CI Public Key and the final package may be signed by the Signing Intermediate CI Private Key.
Intermediate CI Key (GPG)
Root Intermediate CI Private Key (RSA 4096)#
Root Intermediate CI Public Key (RSA 4096)
Signing Intermediate CI Private Key (RSA 4096)
Signing Intermediate CI Public Key (RSA 4096)
Identity: “Intermediate CI Key <email@example.com>”
The Root intermediate CI Private KeyIs stripped out of the GPG key and stored offline completely separate from Spack’s infrastructure. This allows the core development team to append revocation certificates to the GPG key and issue new sub-keys for use in the pipeline. It is our expectation that this will happen on a semi regular basis. A corollary of this is that this key should not be used to verify package integrity outside the internal CI process.
The Reputational Key is the public facing key used to sign complete groups of development and release packages. Only one key pair exists in this class of keys. In contrast to the Intermediate CI Key the Reputational Key should be used to verify package integrity. At the end of develop and release pipeline a final pipeline job pulls down all signed package metadata built by the pipeline, verifies they were signed with an Intermediate CI Key, then strips the Intermediate CI Key signature from the package and re-signs them with the Signing Reputational Private Key. The officially signed packages are then uploaded back to the AWS S3 mirror. Please note that separating use of the reputational key into this final job is done to prevent leakage of the key in a spack package. Because the Signing Reputational Private Key is never exposed to a build job it cannot accidentally end up in any built package.
Reputational Key (GPG)
Root Reputational Private Key (RSA 4096)#
Root Reputational Public Key (RSA 4096)
Signing Reputational Private Key (RSA 4096)
Signing Reputational Public Key (RSA 4096)
Identity: “Spack Project <firstname.lastname@example.org>”
Signatures: Signed by core development team 
The Root Reputational Private Key is stripped out of the GPG key and stored offline completely separate from Spack’s infrastructure. This allows the core development team to append revocation certificates to the GPG key in the unlikely event that the Signing Reputation Private Key is compromised. In general it is the expectation that rotating this key will happen infrequently if at all. This should allow relatively transparent verification for the end-user community without needing deep familiarity with GnuPG or Public Key Infrastructure.
Build Cache Format
A binary package consists of a metadata file unambiguously defining the built package (and including other details such as how to relocate it) and the installation directory of the package stored as a compressed archive file. The metadata files can either be unsigned, in which case the contents are simply the json-serialized concrete spec plus metadata, or they can be signed, in which case the json-serialized concrete spec plus metadata is wrapped in a gpg cleartext signature. Built package metadata files are named to indicate the operating system and architecture for which the package was built as well as the compiler used to build it and the packages name and version. For example:
would contain the concrete spec and binary metadata for a binary package
email@example.com, built for the
ubuntu operating system and
architecture. The id of the built package exists in the name of the file
as well (after the package name and version) and in this case begins
llv2ys. The id distinguishes a particular built package from all
other built packages with the same os/arch, compiler, name, and version.
Below is an example of a signed binary package metadata file. Such a
file would live in the
build_cache directory of a binary mirror:
-----BEGIN PGP SIGNED MESSAGE-----
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
If a user has trusted the public key associated with the private key used to sign the above spec file, the signature can be verified with gpg, as follows:
$ gpg –verify linux-ubuntu18.04-haswell-gcc-7.5.0-zlib-1.2.12-llv2ysfdxnppzjrt5ldybb5c52qbmoow.spec.json.sig
The metadata (regardless whether signed or unsigned) contains the checksum
.spack file containing the actual installation. The checksum should
be compared to a checksum computed locally on the
.spack file to ensure the
contents have not changed since the binary spec plus metadata were signed. The
.spack files are actually tarballs containing the compressed archive of the
install tree. These files, along with the metadata files, live within the
build_cache directory of the mirror, and together are organized as follows:
# unsigned metadata (for indexing, contains sha256 of .spack file)
# clearsigned metadata (same as above, but signed)
# tar.gz-compressed prefix (may support more compression formats later)
Uncompressing and extracting the
.spack file results in the install tree.
This is in contrast to previous versions of spack, where the
contained a (duplicated) metadata file, a signature file and a nested tarball
containing the install tree.
The technical implementation of the pipeline signing process includes components defined in Amazon Web Services, the Kubernetes cluster, at affilicated institutions, and the GitLab/GitLab Runner deployment. We present the technical implementation in two interdependent sections. The first addresses how secrets are managed through the lifecycle of a develop or release pipeline. The second section describes how Gitlab Runner and pipelines are configured and managed to support secure automated signing.
As stated above the Root Private Keys (intermediate and reputational) are stripped from the GPG keys and stored outside Spack’s infrastructure.
Explanation here about where and how access is handled for these keys.
Both Root private keys are protected with strong passwords
Who has access to these and how?
Intermediate CI Key
Multiple intermediate CI signing keys exist, one Intermediate CI Key for jobs run in AWS, and one key for each affiliated institution (e.g. University of Oregon). Here we describe how the Intermediate CI Key is managed in AWS:
The Intermediate CI Key (including the Signing Intermediate CI Private Key is
exported as an ASCII armored file and stored in a Kubernetes secret called
spack-intermediate-ci-signing-key. For convenience sake, this same secret
contains an ASCII-armored export of just the public components of the
Reputational Key. This secret also contains the public components of each of
the affiliated institutions’ Intermediate CI Key. These are potentially needed
to verify dependent packages which may have been found in the public mirror or
built by a protected job running on an affiliated institution’s infrastructure
in an earlier stage of the pipeline.
spack-intermediate-ci-signing-key secret is used in
the following way:
large-x86-protprotected runner picks up a job tagged
protectedfrom a protected GitLab branch. (See Protected Runners and Reserved Tags).
Based on its configuration, the runner creates a job Pod in the pipeline namespace and mounts the spack-intermediate-ci-signing-key Kubernetes secret into the build container
The Intermediate CI Key, affiliated institutions’ public key and the Reputational Public Key are imported into a keyring by the
spack gpg …sub-command. This is initiated by the job’s build script which is created by the generate job at the beginning of the pipeline.
Assuming the package has dependencies those specs are verified using the keyring.
The package is built and the spec.json is generated
The spec.json is signed by the keyring and uploaded to the mirror’s build cache.
Because of the increased impact to end users in the case of a private
key breach, the Reputational Key is managed separately from the
Intermediate CI Keys and has additional controls. First, the Reputational
Key was generated outside of Spack’s infrastructure and has been signed
by the core development team. The Reputational Key (along with the
Signing Reputational Private Key) was then ASCII armor exported to a
file. Unlike the Intermediate CI Key this exported file is not stored as
a base64 encoded secret in Kubernetes. Insteadthe key file
itselfis encrypted and stored in Kubernetes as the
spack-signing-key-encrypted secret in the pipeline namespace.
The encryption of the exported Reputational Key (including the Signing
Reputational Private Key) is handled by AWS Key Management Store (KMS) data
The private key material is decrypted and imported at the time of signing into a
memory mounted temporary directory holding the keychain. The signing job uses
the AWS Encryption SDK
aws-encryption-cli) to decrypt the Reputational Key. Permission to
decrypt the key is granted to the job Pod through a Kubernetes service account
specifically used for this, and only this, function. Finally, for convenience
sake, this same secret contains an ASCII-armored export of the public
components of the Intermediate CI Keys and the Reputational Key. This allows the
signing script to verify that packages were built by the pipeline (both on AWS
or at affiliated institutions), or signed previously as a part of a different
pipeline. This is is done before importing decrypting and importing the
Signing Reputational Private Key material and officially signing the packages.
spack-singing-key-encrypted secret is used in the
spack-package-signing-gitlab-runnerprotected runner picks up a job tagged
notaryfrom a protected GitLab branch (See Protected Runners and Reserved Tags).
Based on its configuration, the runner creates a job pod in the pipeline namespace. The job is run in a stripped down purpose-built image
ghcr.io/spack/notary:latestDocker image. The runner is configured to only allow running jobs with this image.
The runner also mounts the
spack-signing-key-encryptedsecret to a path on disk. Note that this becomes several files on disk, the public components of the Intermediate CI Keys, the public components of the Reputational CI, and an AWS KMS encrypted file containing the Singing Reputational Private Key.
In addition to the secret, the runner creates a tmpfs memory mounted directory where the GnuPG keyring will be created to verify, and then resign the package specs.
The job script syncs all spec.json.sig files from the build cache to a working directory in the job’s execution environment.
The job script then runs the
sign.shscript built into the notary Docker image.
sign.shscript imports the public components of the Reputational and Intermediate CI Keys and uses them to verify good signatures on the spec.json.sig files. If any signed spec does not verify the job immediately fails.
Assuming all specs are verified, the
sign.shscript then unpacks the spec json data from the signed file in preparation for being re-signed with the Reputational Key.
The private components of the Reputational Key are decrypted to standard out using
aws-encryption-clidirectly into a
gpg –import …statement which imports the key into the keyring mounted in-memory.
The private key is then used to sign each of the json specs and the keyring is removed from disk.
The re-signed json specs are resynced to the AWS S3 Mirror and the public signing of the packages for the develop or release pipeline that created them is complete.
Non service-account access to the private components of the Reputational Key that are managed through access to the symmetric secret in KMS used to encrypt the data key (which in turn is used to encrypt the GnuPG key - See:Encryption SDK Documentation). A small trusted subset of the core development team are the only individuals with access to this symmetric key.