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

support setting a custom cert ttl via SECRET_TTL env var #742

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ trust-dns-client = "0.22.0"
trust-dns-proto = "0.22.0"
trust-dns-resolver = "0.22.0"
trust-dns-server = { version = "0.22.1", features = [ "trust-dns-resolver" ] }
duration-str = "0.7.0"

[target.'cfg(target_os = "linux")'.dependencies]
netns-rs = "0.1.0"
Expand Down
31 changes: 31 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const LOCAL_XDS_PATH: &str = "LOCAL_XDS_PATH";
const XDS_ON_DEMAND: &str = "XDS_ON_DEMAND";
const XDS_ADDRESS: &str = "XDS_ADDRESS";
const CA_ADDRESS: &str = "CA_ADDRESS";
const SECRET_TTL: &str = "SECRET_TTL";
const FAKE_CA: &str = "FAKE_CA";
const ZTUNNEL_WORKER_THREADS: &str = "ZTUNNEL_WORKER_THREADS";
const ENABLE_ORIG_SRC: &str = "ENABLE_ORIG_SRC";
Expand All @@ -53,6 +54,7 @@ const DEFAULT_DNS_PORT: u16 = 15053;
const DEFAULT_SELFTERM_DEADLINE: Duration = Duration::from_secs(5);
const DEFAULT_CLUSTER_ID: &str = "Kubernetes";
const DEFAULT_CLUSTER_DOMAIN: &str = "cluster.local";
const DEFAULT_TTL: Duration = Duration::from_secs(60 * 60 * 24); // 24 hours

const ISTIO_META_PREFIX: &str = "ISTIO_META_";
const DNS_CAPTURE_METADATA: &str = "DNS_CAPTURE";
Expand Down Expand Up @@ -139,6 +141,8 @@ pub struct Config {
pub xds_address: Option<String>,
/// Root cert for XDS TLS verification.
pub xds_root_cert: RootCert,
/// TTL for CSR requests
pub secret_ttl: Duration,
/// YAML config for local XDS workloads
#[serde(skip_serializing)]
pub local_xds_config: Option<ConfigSource>,
Expand Down Expand Up @@ -335,6 +339,10 @@ pub fn construct_config(pc: ProxyConfig) -> Result<Config, Error> {
xds_root_cert,
ca_address,
ca_root_cert,
secret_ttl: match parse::<String>(SECRET_TTL)? {
Some(ttl) => duration_str::parse(&ttl).unwrap_or(DEFAULT_TTL),
None => DEFAULT_TTL,
},
local_xds_config: parse::<PathBuf>(LOCAL_XDS_PATH)?.map(ConfigSource::File),
xds_on_demand: parse_default(XDS_ON_DEMAND, false)?,
proxy_metadata: pc.proxy_metadata,
Expand Down
5 changes: 4 additions & 1 deletion src/identity/caclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::xds::istio::ca::IstioCertificateRequest;
pub struct CaClient {
pub client: IstioCertificateServiceClient<InterceptedService<TlsGrpcChannel, AuthSource>>,
pub enable_impersonated_identity: bool,
pub secret_ttl: i64,
}

impl CaClient {
Expand All @@ -39,6 +40,7 @@ impl CaClient {
cert_provider: Box<dyn tls::ClientCertProvider>,
auth: AuthSource,
enable_impersonated_identity: bool,
secret_ttl: i64,
) -> Result<CaClient, Error> {
let svc = tls::grpc_connector(address, cert_provider.fetch_cert().await?)?;
// let client = IstioCertificateServiceClient::new(svc);
Expand All @@ -48,6 +50,7 @@ impl CaClient {
Ok(CaClient {
client,
enable_impersonated_identity,
secret_ttl,
})
}
}
Expand All @@ -65,7 +68,7 @@ impl CaClient {
let csr = std::str::from_utf8(&csr).map_err(Error::Utf8)?.to_string();
let req = IstioCertificateRequest {
csr,
validity_duration: 60 * 60 * 24, // 24 hours
validity_duration: self.secret_ttl,
metadata: {
if self.enable_impersonated_identity {
Some(Struct {
Expand Down
1 change: 1 addition & 0 deletions src/identity/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ impl SecretManager {
)),
cfg.auth,
cfg.proxy_mode == ProxyMode::Shared,
cfg.secret_ttl.as_secs().try_into().unwrap_or(60 * 60 * 24),
)
.await?;
Ok(Self::new_with_client(caclient))
Expand Down
1 change: 1 addition & 0 deletions src/test_helpers/ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl CaServer {
"Kubernetes".to_string(),
),
true,
60 * 60 * 24,
)
.await
.unwrap();
Expand Down