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

feat: Add TLS certificate util crate #736

Merged
merged 57 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c6d8d35
Initial commit
Techassi Feb 13, 2024
4a00b7f
Merge branch 'main' into feat/tls-cert-generation
Techassi Feb 14, 2024
ced1d2b
Use certs crate
Techassi Feb 14, 2024
4f65367
Add first rough plans
Techassi Feb 14, 2024
8b985db
Merge changelog changes
Techassi Feb 15, 2024
eead4ac
Add ED25519 signing key support
Techassi Feb 15, 2024
c7e3236
Add RSA signing key
Techassi Feb 15, 2024
1384083
Finish initial CA creation, slowly start to refine code
Techassi Feb 16, 2024
4efd3c1
Start to add K8s traits
Techassi Feb 16, 2024
797dee7
Add SecretReference
Techassi Feb 19, 2024
3ab1b28
Add more errors, add more helper traits
Techassi Feb 19, 2024
e5470b1
Make certificate authority generic over the signing key
Techassi Feb 20, 2024
0d80f4e
Start to add leaf certificate generation
Techassi Feb 22, 2024
fc2e73e
Add more interop code, clean up trait impls and errors
Techassi Feb 22, 2024
df672bc
Slightly simplify wrapper types and trait impls
Techassi Feb 23, 2024
4271715
Start to work through initial round of TODOs
Techassi Feb 23, 2024
e03ad1c
Remove unwraps, add error handling
Techassi Mar 4, 2024
ba82b36
Move k8s code into own file
Techassi Mar 4, 2024
4810ed7
Merge branch 'main' into feat/tls-cert-generation
Techassi Mar 4, 2024
2970688
Remove initial manager code
Techassi Mar 4, 2024
cba32cd
Add a few more (doc) comments
Techassi Mar 4, 2024
13f5816
Add more doc comments for constants
Techassi Mar 4, 2024
2ad66c5
Apply suggestions
Techassi Mar 5, 2024
6c8db86
Add fixups for code suggestions
Techassi Mar 5, 2024
9c21a1c
Change default RSA bit size
Techassi Mar 5, 2024
0d5c001
Add RSA bit size guard
Techassi Mar 5, 2024
c27f43c
Add doc comments, add leaf cert helper functions
Techassi Mar 5, 2024
2b80739
Add doc comments for CertificatePairExt trait
Techassi Mar 5, 2024
5e67e50
Rename rustls feature to webhook
Techassi Mar 5, 2024
c43f2e2
Fix doc comment reference
Techassi Mar 5, 2024
0a2a8e0
Add secret type guard
Techassi Mar 5, 2024
6b89c3a
Remove unused trait function
Techassi Mar 5, 2024
7b45b50
Initial commit
Techassi Mar 5, 2024
7a6fc12
Add const for Kubernetes TLS secret type
Techassi Mar 7, 2024
573814d
Turn the RSA bit size into an enum
Techassi Mar 7, 2024
12100ee
Use enum discriminants
Techassi Mar 7, 2024
7461374
Remove hashset of serial numbers
Techassi Mar 7, 2024
597ec94
Remove customizable line endings
Techassi Mar 7, 2024
7c435bd
Adjust root CA subject
Techassi Mar 7, 2024
ec52972
Remove TLS mount related code
Techassi Mar 7, 2024
d0941e6
Add error handling for cert generation
Techassi Mar 7, 2024
1b4a78e
Adjust conditional imports
Techassi Mar 7, 2024
ac27db5
Merge branch 'main' into feat/tls-cert-generation
Techassi Mar 12, 2024
a0182d7
Apply suggestion
Techassi Mar 12, 2024
a5a00ef
Revert "Apply suggestion"
Techassi Mar 12, 2024
a372b7a
Add from_secret and from_secret_ref functions to struct directly
Techassi Mar 12, 2024
3c6bf74
Remove unneeded newlines
Techassi Mar 12, 2024
17a6aef
Add doc comment to SecretReference
Techassi Mar 13, 2024
7a96031
Rename to KeySize, add bits method
Techassi Mar 14, 2024
694e337
Slightly adjust doc comment for SecretReference
Techassi Mar 14, 2024
c96fa62
Rename Keypair trait to CertificateKeypair
Techassi Mar 14, 2024
c4a044e
Merge branch 'main' into feat/tls-cert-generation
Techassi Mar 14, 2024
862d2bb
Remove KeySize enum
Techassi Mar 14, 2024
9dc89ae
Move key size into constant
Techassi Mar 14, 2024
dd51591
Use with_context to avoid unnecessary allocation when Ok
Techassi Mar 15, 2024
b90dc1f
Adjust error message to reflect underlying error
Techassi Mar 15, 2024
4eb2743
Add doc comment to clarify paramter usage
Techassi Mar 15, 2024
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ Cargo.lock
.idea/
*.iws
*.iml

# TLS certificates for testing
*.crt
*.key
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ rstest = "0.18.1"
tempfile = "3.7.1"

[workspace]
members = ["stackable-operator-derive", "stackable-webhook"]
members = ["stackable-certs", "stackable-operator-derive", "stackable-webhook"]
1 change: 1 addition & 0 deletions src/commons/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub mod product_image_selection;
pub mod rbac;
pub mod resources;
pub mod s3;
pub mod secret;
pub mod secret_class;
45 changes: 45 additions & 0 deletions src/commons/secret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::fmt::Display;

use k8s_openapi::api::core::v1::Secret;
use kube::runtime::reflector::ObjectRef;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// [`SecretReference`] represents a Kubernetes [`Secret`] reference.
///
/// In order to use this struct, the following two requirements must be met:
///
/// - Must only be used in cluster-scoped objects
/// - Namespaced objects must not be able to define cross-namespace secret
/// references
///
/// This struct is a redefinition of the one provided by k8s-openapi to make
/// name and namespace mandatory.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct SecretReference {
/// Namespace of the Secret being referred to.
pub namespace: String,

/// Name of the Secret being referred to.
pub name: String,
}

// Use ObjectRef for logging/errors
impl Display for SecretReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
ObjectRef::<Secret>::from(self).fmt(f)
}
}

impl From<SecretReference> for ObjectRef<Secret> {
fn from(val: SecretReference) -> Self {
ObjectRef::<Secret>::from(&val)
}
}

impl From<&SecretReference> for ObjectRef<Secret> {
fn from(val: &SecretReference) -> Self {
ObjectRef::<Secret>::new(&val.name).within(&val.namespace)
}
}
37 changes: 37 additions & 0 deletions stackable-certs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "stackable-certs"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true

[features]
default = []
rustls = ["dep:tokio-rustls", "dep:rustls-pemfile"]

[dependencies]
stackable-operator = { path = ".." }

const-oid = "0.9.6"
ecdsa = { version = "0.16.9", features = ["digest", "pem"] }
p256 = { version = "0.13.2", features = ["ecdsa"] }
k8s-openapi = { version = "0.21.0", default-features = false, features = [
"v1_28",
] }
kube = { version = "0.88.1", default-features = false, features = [
"client",
"rustls-tls",
] }
tracing = "0.1.40"
tokio = { version = "1.29.1", features = ["fs"] }
tokio-rustls = { version = "0.25.0", optional = true }
rand = "0.8.5"
rand_core = "0.6.4"
rsa = { version = "0.9.6", features = ["sha2"] }
rustls-pemfile = { version = "2.0.0", optional = true }
sha2 = { version = "0.10.8", features = ["oid"] }
signature = "2.2.0"
snafu = "0.8.0"
x509-cert = { version = "0.2.5", features = ["builder"] }
zeroize = "1.7.0"
5 changes: 5 additions & 0 deletions stackable-certs/src/ca/consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// The default CA validity time span of one hour (3600 seconds).
pub const DEFAULT_CA_VALIDITY_SECONDS: u64 = 3600;

/// The root CA subject name containing only the common name.
pub const ROOT_CA_SUBJECT: &str = "CN=Stackable Data Platform Internal CA";
Techassi marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading