-
Notifications
You must be signed in to change notification settings - Fork 23
feat(tvc): add pivot digest validation #118
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
Open
annieke
wants to merge
2
commits into
main
Choose a base branch
from
annie/add-pivot-digest-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 +1,6 @@ | ||
| //! App commands. | ||
|
|
||
| pub mod create; | ||
| pub mod status; | ||
| pub mod init; | ||
| pub mod list; | ||
| pub mod status; |
This file contains hidden or 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 hidden or 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,8 +1,10 @@ | ||
| //! Approve deploy command - cryptographically approve a QOS manifest. | ||
|
|
||
| use super::validate_pivot_digest::print_result; | ||
| use crate::config::app::KNOWN_SHARE_SET_KEYS; | ||
| use crate::config::turnkey::{Config, StoredQosOperatorKey}; | ||
| use crate::pair::LocalPair; | ||
| use crate::pivot_digest::{compute_pivot_digest, validate_expected_digest, PivotDigestSource}; | ||
| use crate::util::{read_file_to_string, write_file}; | ||
| use anyhow::{anyhow, bail, Context}; | ||
| use clap::{ArgGroup, Args as ClapArgs}; | ||
|
|
@@ -19,6 +21,13 @@ use turnkey_client::generated::{ | |
| CreateTvcManifestApprovalsIntent, GetTvcDeploymentRequest, TvcManifestApproval, | ||
| }; | ||
|
|
||
| struct DeployApprovalSource { | ||
| manifest: Manifest, | ||
| manifest_id: String, | ||
| pivot_image_url: Option<String>, | ||
| pivot_path: Option<String>, | ||
| } | ||
|
|
||
| /// Cryptographically approve a QOS manifest for a deployment with your operator's manifest set key. | ||
| #[derive(Debug, ClapArgs)] | ||
| #[command(about, long_about = None)] | ||
|
|
@@ -57,6 +66,14 @@ pub struct Args { | |
| #[arg(long, help_heading = "Operator signing key", value_name = "PATH")] | ||
| pub operator_seed: Option<PathBuf>, | ||
|
|
||
| /// Locally validate the pivot digest before approval. Only supported with `--deploy-id`. | ||
| #[arg(long)] | ||
| pub validate_pivot_digest: bool, | ||
|
|
||
| /// Path to an unencrypted Docker-style pull secret JSON file. | ||
| #[arg(long, value_name = "PATH")] | ||
| pub pull_secret: Option<PathBuf>, | ||
|
|
||
| /// Walk through manifest approval prompts but do not generate an approval. | ||
| #[arg(long)] | ||
| pub dry_run: bool, | ||
|
|
@@ -76,15 +93,48 @@ pub struct Args { | |
|
|
||
| /// Run the approve deploy command. | ||
| pub async fn run(args: Args) -> anyhow::Result<()> { | ||
| if args.validate_pivot_digest && args.manifest.is_some() { | ||
| bail!( | ||
| "--validate-pivot-digest only works with --deploy-id. \ | ||
| Use `tvc deploy validate-pivot-digest` to validate a manifest file source locally." | ||
| ); | ||
| } | ||
|
|
||
| // Fetch manifest - track manifest_id if fetched from API | ||
| let (manifest, fetched_manifest_id) = match (&args.manifest, &args.deploy_id) { | ||
| (Some(path), _) => (read_manifest_from_path(path).await?, None), | ||
| (_, Some(deploy_id)) => { | ||
| let (manifest, manifest_id) = fetch_manifest_from_deploy(deploy_id).await?; | ||
| (manifest, Some(manifest_id)) | ||
| } | ||
| (None, None) => bail!("a manifest source is required"), | ||
| }; | ||
| let (manifest, fetched_manifest_id, pivot_image_url, pivot_path) = | ||
| match (&args.manifest, &args.deploy_id) { | ||
| (Some(path), _) => (read_manifest_from_path(path).await?, None, None, None), | ||
| (_, Some(deploy_id)) => { | ||
| let source = fetch_manifest_from_deploy(deploy_id).await?; | ||
| ( | ||
| source.manifest, | ||
| Some(source.manifest_id), | ||
| source.pivot_image_url, | ||
| source.pivot_path, | ||
| ) | ||
| } | ||
| (None, None) => bail!("a manifest source is required"), | ||
| }; | ||
|
|
||
| if args.validate_pivot_digest { | ||
| let pivot_image_url = pivot_image_url | ||
| .ok_or_else(|| anyhow!("deployment is missing a pivot container image URL"))?; | ||
| let pivot_path = | ||
| pivot_path.ok_or_else(|| anyhow!("deployment is missing a pivot container path"))?; | ||
|
|
||
| let result = compute_pivot_digest( | ||
| &PivotDigestSource { | ||
| image_url: pivot_image_url, | ||
| pivot_path, | ||
| }, | ||
| args.pull_secret.as_deref(), | ||
| ) | ||
| .await?; | ||
| validate_expected_digest(&result.digest, &hex::encode(manifest.pivot.hash))?; | ||
| print_result(&result); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i would prefer using path so it reads |
||
| println!("Pivot digest validated successfully."); | ||
| println!(); | ||
| } | ||
|
|
||
| if !args.dangerous_skip_interactive { | ||
| interactive_approve(&manifest)?; | ||
|
|
@@ -369,7 +419,7 @@ async fn read_manifest_from_path(path: &Path) -> anyhow::Result<Manifest> { | |
|
|
||
| /// Fetch manifest from Turnkey using GetTvcDeployment API. | ||
| /// Returns the manifest and its Turnkey manifest_id. | ||
| async fn fetch_manifest_from_deploy(deploy_id: &str) -> anyhow::Result<(Manifest, String)> { | ||
| async fn fetch_manifest_from_deploy(deploy_id: &str) -> anyhow::Result<DeployApprovalSource> { | ||
| println!("Fetching deployment {deploy_id}..."); | ||
|
|
||
| let auth = crate::client::build_client().await?; | ||
|
|
@@ -399,5 +449,15 @@ async fn fetch_manifest_from_deploy(deploy_id: &str) -> anyhow::Result<(Manifest | |
|
|
||
| println!("✓ Manifest loaded (manifest_id: {})", tvc_manifest.id); | ||
|
|
||
| Ok((manifest, tvc_manifest.id)) | ||
| let (pivot_image_url, pivot_path) = deployment | ||
| .pivot_container | ||
| .map(|container| (Some(container.container_url), Some(container.path))) | ||
| .unwrap_or((None, None)); | ||
|
|
||
| Ok(DeployApprovalSource { | ||
| manifest, | ||
| manifest_id: tvc_manifest.id, | ||
| pivot_image_url, | ||
| pivot_path, | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do people normally store the pull secret as a file? either way i think they could also do --pull-secret <(echo "contents")