Replies: 2 comments 1 reply
-
On top of BYOK we could have a command to generate a key for the computer/project automatically for users that don't necessarily care what key is used. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks for this proposal, looks interesting. Will you also document how to leverage BYOK for users that uses their own custom cache server? For example, https://github.com/Tapico/tapico-turborepo-remote-cache |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
Turborepo CLI caches build artifacts locally. When linked to a remote cache, Turborepo will upload those artifacts so that they can be downloaded by teammates. The contents of artifacts can range from compiled code to event logs emitted during build. Assuming the remote cache itself is not encrypted, if the remote cache is compromised by an adversary, the adversary will be able to read all artifacts and possibly write artifacts on the remote cache themselves.
We would like to provide a mechanism to encrypt the artifacts before they are uploaded to any remote cache and ensure integrity of artifacts downloaded by users.
Related Artifact Signatures RFC
Terminologies Used in this RFC
Goals
Non-Goals
Proposal
Option 1: Turborepo CLI request encryption from key manager
We assume that Turborepo CLI is authenticated to request encryption and decryption from an external key manager.
This process uses encryption and decryption by a key manager service. The flowchart outlines the following:
key
and encryptedE(kms,key)
by the service.key
to encrypt theartifact
.E(key,artifact)
andE(kms,key)
to the remote cache.E(key,artifact)
andE(kms,key)
from the remote cache.E(kms,key)
to derivekey
key
to decryptE(key,artifact)
to deriveartifact
Option 2: Turborepo CLI accepts per user public-private keys
We assume that Turborepo CLI is using a strong Public-Private key pairs associated with individual users and certified by the Team. Teams using Turborepo CLI will be responsible for establishing the authenticity of Public Keys.
For each artifact Turborepo CLI will generate a secure symmetric key
artifact-secret
. Theartifact-secret
is the AES key used to encrypt and decrypt the uploaded artifact. Theartifact-secret
will be encrypted with all teammates public keys and uploaded to the remote cache alongside the encrypted artifact. For N members of a team, theartifact-secret
will be encrypted N times and all versions of the encryptedartifact-secret
will be uploaded to the remote cache.Additionally, the user that generated the artifact will send the signature over the SHA256 of the artifact. This is signed using the sender’s secret key.
Receivers should decrypt the
artifact-secret
using their own secret key and verify the signature using the sender’s public key.Turborepo CLI will computes the following for each artifact and append the values as headers to the Remote Cache uploads.
x-artifact-artifact-secret-keys
x-artifact-signature
Option 3: Turborepo CLI accepts versioned symmetric keys
We should use AES-GCM with 256 bit symmetric keys. This is the NIST recommended method for authenticated encryption with associated data. Turborepo is written in GO, and there is a standard crypto library implementation of this algorithm that can be used to encrypt and decrypt artifacts. AES-GCM allows for authenticating plaintext Associated Data on the ciphertext which is used below.
The impact here is that the symmetric key used to encrypt and decrypt the artifacts will need to be distributed to teammates using Turborepo CLI.
Enable Encryption on Turborepo CLI
Turborepo will specify an
enableEncryption: boolean
flag on theturbo.json
config. When this flag is present, all uploaded and downloaded artifacts are expected to be encrypted.Turborepo CLI Accepts User provided secret keys
Getting the Key
Yet to be determined what will be easiest for users to expose the secret key from their machine to the Turborepo CLI. Some options include:
turbo.json
path to local file config where keys are storedturbo.json
configured environment variable where key is accessibleAlternatively, the CLI can follow a pattern like Viper and support decreasing precedence lookups for the token.
We could take a similar approach. Require a key in
turbo.json
with a path, and apply overrides as appropriate. Teams that don’t want to use a file can put in a bogus path and override via environment or command line.Key Format
The BYOK secret key must be a 32 byte (256 bit) AES key.
Turborepo will version secret keys used in encryption. This version will be stored on the
turbo.json
config. The version is semver stylemajor.minor
. Note that the secret key is not stored on theturbo.json
config, only the version. This version can be attached to the associated data on the encrypted artifact. This is useful for processing key rotations and signaling to users that they’re using an expired secret key.This means that technically Turborepo CLI can support re-encryption of downloaded artifacts after key-rotation, though this may not be desired.
If the secret key is rotated, Turborepo can take advantage of secret key versioning to decrypt artifacts that were encrypted using the old key. When any new artifacts are created they will always be encrypted with the most recent version specified on the
turbo.json
config.Turborepo CLI handles Decryption
If an artifact is downloaded and the secret-key version on the associated data is a version used to the decrypt the artifact, then it must successfully decrypt. Otherwise, Turborepo CLI should throw an error.
If the secret key version of a downloaded artifact is more recent than the version on the
turbo.json
config then an error is thrown with message indicating they don’t have most recent key.If the secret key version of a downloaded artifact is older than the most recent version of the key on the
turbo.json
we can either:Whether or not Turborepo CLI decrypts is based on the difference in versions. If the artifact is a major version away then the artifact is not decrypted. If the artifact is only a minor version away, then the artifact can be decrypted if the Turborepo CLI has access to the key.
Beta Was this translation helpful? Give feedback.
All reactions