From 839a76c481823dfdede38ec63420653a08028af1 Mon Sep 17 00:00:00 2001 From: Eric Rodrigues Pires Date: Wed, 22 Jul 2026 19:45:59 -0300 Subject: [PATCH] Remove now-secret library --- Cargo.lock | 17 ------ Cargo.toml | 20 ++----- nix/default.nix | 1 - now-secret/Cargo.toml | 10 ---- now-step/Cargo.toml | 9 ++- now-step/src/main.rs | 1 + now-step/src/run.rs | 3 +- .../src/lib.rs => now-step/src/secrets.rs | 60 ++----------------- src/environment.rs | 6 +- src/main.rs | 1 + src/project.rs | 7 +-- src/secret.rs | 53 ++++++++++++++++ src/workflow.rs | 4 +- 13 files changed, 78 insertions(+), 114 deletions(-) delete mode 100644 now-secret/Cargo.toml rename now-secret/src/lib.rs => now-step/src/secrets.rs (69%) create mode 100644 src/secret.rs diff --git a/Cargo.lock b/Cargo.lock index dd226a1..92df257 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -879,7 +879,6 @@ dependencies = [ "futures", "ignore", "include_dir", - "now-secret", "owo-colors", "petgraph", "rand", @@ -889,15 +888,6 @@ dependencies = [ "smol", "sys-info", "uuid", - "zeroize", -] - -[[package]] -name = "now-secret" -version = "0.1.0" -dependencies = [ - "serde", - "zeroize", ] [[package]] @@ -906,7 +896,6 @@ version = "0.1.0" dependencies = [ "clap", "color-eyre", - "now-secret", "portable-pty", "serde", "serde_json", @@ -1493,12 +1482,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "zeroize" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" - [[package]] name = "zmij" version = "1.0.21" diff --git a/Cargo.toml b/Cargo.toml index 0123223..23738a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,34 +10,24 @@ name = "now" path = "src/main.rs" [workspace] -members = ["now-secret", "now-step"] - -[workspace.dependencies] -clap = { version = "4.6.1", features = ["derive"] } -color-eyre = "0.6.5" -now-secret = { version = "0.1.0", path = "now-secret" } -serde = { version = "1.0.228", features = ["derive"] } -serde_json = "1.0.150" -zeroize = "1.9.0" +members = [ "now-step" ] [dependencies] async-trait = "0.1.91" -clap = { workspace = true } +clap = { version = "4.6.1", features = ["derive"] } clap_complete = "4.6.7" -color-eyre = { workspace = true } +color-eyre = "0.6.5" ctrlc = { version = "3.5.2", features = ["termination"] } dotenvy = "0.15.7" futures = "0.3.33" ignore = "0.4.30" include_dir = "0.7.4" -now-secret = { workspace = true } owo-colors = "4.3.0" petgraph = "0.8.3" -serde = { workspace = true } rand = "0.10.2" regex = "1.13.1" -serde_json = { workspace = true } +serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1.0.150" smol = "2.0.2" sys-info = "0.9.1" uuid = { version = "1.23.5", features = ["v4"] } -zeroize = { workspace = true } diff --git a/nix/default.nix b/nix/default.nix index 425d3df..f68bbd7 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -25,7 +25,6 @@ let root = ../.; fileset = lib.fileset.unions [ ../nix - ../now-secret ../now-step ../src ../Cargo.toml diff --git a/now-secret/Cargo.toml b/now-secret/Cargo.toml deleted file mode 100644 index c6188db..0000000 --- a/now-secret/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "now-secret" -version = "0.1.0" -edition = "2024" -description = "Secret handling for now" -license = "AGPL-3.0-or-later" - -[dependencies] -serde = { workspace = true } -zeroize = { workspace = true } diff --git a/now-step/Cargo.toml b/now-step/Cargo.toml index a12ee94..7b8bf58 100644 --- a/now-step/Cargo.toml +++ b/now-step/Cargo.toml @@ -6,9 +6,8 @@ description = "Step runner for now" license = "AGPL-3.0-or-later" [dependencies] -clap = { workspace = true } -color-eyre = { workspace = true } -now-secret = { workspace = true } +clap = { version = "4.6.1", features = ["derive"] } +color-eyre = "0.6.5" portable-pty = "0.9.0" -serde = { workspace = true } -serde_json = { workspace = true } +serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1.0.150" diff --git a/now-step/src/main.rs b/now-step/src/main.rs index 67bc4fd..4bcd8bf 100644 --- a/now-step/src/main.rs +++ b/now-step/src/main.rs @@ -21,6 +21,7 @@ use clap::Parser; use crate::run::run; mod run; +mod secrets; #[derive(Parser)] #[command(version, about, long_about = None)] diff --git a/now-step/src/run.rs b/now-step/src/run.rs index 125ae16..9a37db3 100644 --- a/now-step/src/run.rs +++ b/now-step/src/run.rs @@ -23,9 +23,10 @@ use std::{ thread::spawn, }; -use now_secret::SecretStringCollection; use portable_pty::{CommandBuilder, PtySize, native_pty_system}; +use crate::secrets::SecretStringCollection; + pub(crate) fn run(derivation: PathBuf, secrets: &Vec) -> color_eyre::Result<()> { let env: HashMap = std::env::vars_os().collect(); diff --git a/now-secret/src/lib.rs b/now-step/src/secrets.rs similarity index 69% rename from now-secret/src/lib.rs rename to now-step/src/secrets.rs index 547cda2..50c5690 100644 --- a/now-secret/src/lib.rs +++ b/now-step/src/secrets.rs @@ -16,63 +16,14 @@ use std::borrow::Cow; -use serde::{Deserialize, Serialize}; -use zeroize::Zeroizing; - -/// A secret containing a string. -/// -/// On drop, the value is zeroized in memory. -pub struct SecretString(Zeroizing); - -impl SecretString { - /// Create a new secret. - pub fn new(secret: String) -> Self { - Self(Zeroizing::new(secret)) - } - - /// Get a borrow to the secret value. - pub fn get_secret_value(&self) -> &str { - self.0.as_ref() - } -} - -impl std::fmt::Debug for SecretString { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("SecretString").field(&"***").finish() - } -} - -impl Serialize for SecretString { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.serialize_str(&self.0) - } -} - -impl<'de> Deserialize<'de> for SecretString { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - Ok(Self(Zeroizing::new(String::deserialize(deserializer)?))) - } -} - -/// A collection of secrets, ordered from longest to shortest. -/// -/// On drop, the value are zeroized in memory. -pub struct SecretStringCollection(Zeroizing>); +pub(crate) struct SecretStringCollection(Vec); impl SecretStringCollection { - /// Create a new secret collection. - pub fn new() -> Self { - Self(Zeroizing::new(Vec::new())) + pub(crate) fn new() -> Self { + Self(Vec::new()) } - /// Add a secret to the collection, keeping longer strings before smaller strings. - pub fn push(&mut self, secret: String) { + pub(crate) fn push(&mut self, secret: String) { if secret.is_empty() { return; } @@ -86,8 +37,7 @@ impl SecretStringCollection { self.0.insert(index, secret); } - /// Replaces all instances of secrets in this collection with "***". - pub fn anonymize<'a>(&self, string: &'a str) -> Cow<'a, str> { + pub(crate) fn anonymize<'a>(&self, string: &'a str) -> Cow<'a, str> { let mut string = Cow::Borrowed(string); for secret in self.0.iter() { let mut output: Option = None; diff --git a/src/environment.rs b/src/environment.rs index 2d6134f..caeac76 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -24,10 +24,12 @@ use std::{ sync::Mutex, }; -use now_secret::SecretString; use serde::{Deserialize, Serialize}; -use crate::workflow::{NowJob, NowJobContainer, NowStepEnvVar, NowWorkflow}; +use crate::{ + secret::SecretString, + workflow::{NowJob, NowJobContainer, NowStepEnvVar, NowWorkflow}, +}; #[derive(Debug, Default, Serialize, Deserialize)] pub(crate) struct NowEnvironment { diff --git a/src/main.rs b/src/main.rs index 46b1b87..eed4c06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ mod builder; mod environment; mod job; mod project; +mod secret; mod utils; mod workflow; diff --git a/src/project.rs b/src/project.rs index 5a5e2e2..1cc3ba4 100644 --- a/src/project.rs +++ b/src/project.rs @@ -22,10 +22,9 @@ static CARGO_TOML: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/ static CARGO_LOCK: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.lock")); static NIX_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/nix"); static SRC_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/src"); -static NOW_SECRET_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/now-secret"); static NOW_STEP_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/now-step"); -pub(crate) fn create_project_source() -> color_eyre::Result { +pub(crate) fn create_now_step_source() -> color_eyre::Result { let tmpdir = temp_dir().join(format!("now-{}", uuid::Uuid::new_v4())); let nix_dir = tmpdir.join("nix"); @@ -36,10 +35,6 @@ pub(crate) fn create_project_source() -> color_eyre::Result { create_dir_all(&src_dir)?; SRC_DIR.extract(&src_dir)?; - let now_secret_dir = tmpdir.join("now-secret"); - create_dir_all(&now_secret_dir)?; - NOW_SECRET_DIR.extract(&now_secret_dir)?; - let now_step_dir = tmpdir.join("now-step"); create_dir_all(&now_step_dir)?; NOW_STEP_DIR.extract(&now_step_dir)?; diff --git a/src/secret.rs b/src/secret.rs new file mode 100644 index 0000000..61e8cc7 --- /dev/null +++ b/src/secret.rs @@ -0,0 +1,53 @@ +// now: A Nix-based distributed command runner +// Copyright (C) 2026 Eric Rodrigues Pires +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +// more details. +// +// You should have received a copy of the GNU Affero General Public License along +// with this program. If not, see . + +use serde::{Deserialize, Serialize}; + +pub(crate) struct SecretString(String); + +impl SecretString { + pub(crate) fn new(secret: String) -> Self { + Self(secret) + } + + pub(crate) fn get_secret_value(&self) -> &str { + self.0.as_ref() + } +} + +impl std::fmt::Debug for SecretString { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("SecretString").field(&"***").finish() + } +} + +impl Serialize for SecretString { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_str(&self.0) + } +} + +impl<'de> Deserialize<'de> for SecretString { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + Ok(Self(String::deserialize(deserializer)?)) + } +} diff --git a/src/workflow.rs b/src/workflow.rs index 9c07b81..bc2f8a8 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -34,7 +34,7 @@ use crate::{ CheckoutStrategy, builder::{NowBuilder, local::LocalBuilder}, environment::NowEnvironment, - project::create_project_source, + project::create_now_step_source, }; #[derive(Debug, Deserialize)] @@ -211,7 +211,7 @@ impl NowEnvironment { .ok_or_else(|| color_eyre::eyre::eyre!("non-UTF8 path"))?; let workflow_path = format!("(/. + {})", serde_json::to_string(&workflow_str)?); - let nix_workflow = create_project_source()?.join("nix/workflow.nix"); + let nix_workflow = create_now_step_source()?.join("nix/workflow.nix"); let nix_workflow_canonical = std::fs::canonicalize(&nix_workflow)?; let nix_workflow_str = nix_workflow_canonical .to_str() -- knotmirror 0.0.1