Skip to content

Commit b39155c

Browse files
committed
Dockerfile
1 parent f9c1ce7 commit b39155c

File tree

7 files changed

+65
-12
lines changed

7 files changed

+65
-12
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cluster-files
2+
cluster-files-backup
3+
target

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM rust:1 AS chef
2+
# We only pay the installation cost once,
3+
# it will be cached from the second build onwards
4+
RUN cargo install cargo-chef
5+
WORKDIR app
6+
7+
FROM chef AS planner
8+
COPY . .
9+
RUN cargo chef prepare --recipe-path recipe.json
10+
11+
FROM chef AS builder
12+
RUN apt-get update
13+
RUN apt-get install -y protobuf-compiler
14+
COPY --from=planner /app/recipe.json recipe.json
15+
# Build dependencies - this is the caching Docker layer!
16+
RUN cargo chef cook --release --recipe-path recipe.json
17+
# Build application
18+
COPY . .
19+
RUN cargo build --release --bin recert
20+
21+
# We do not need the Rust toolchain to run the binary!
22+
FROM debian:bookworm AS runtime
23+
WORKDIR app
24+
COPY ouger /usr/local/bin
25+
RUN apt-get update
26+
RUN apt-get install -y openssl
27+
COPY --from=builder /app/target/release/recert /usr/local/bin
28+
ENTRYPOINT ["/usr/local/bin/recert"]

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,9 @@ ssh $SSH_FLAGS "$SSH_HOST" sudo systemctl enable kubelet
239239
ssh $SSH_FLAGS "$SSH_HOST" sudo systemctl enable crio
240240
ssh $SSH_FLAGS "$SSH_HOST" sudo reboot
241241
```
242+
243+
# Image build
244+
245+
export DOCKER_BUILDKIT=1
246+
docker build . -t quay.io/otuchfel/recert:latest
247+
docker push quay.io/otuchfel/recert:latest

src/cluster_crypto/certificate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ impl TryFrom<CapturedX509Certificate> for Certificate {
4040
&bytes::Bytes::copy_from_slice(&cert.to_public_key_der().context("parsing public key")?.as_bytes()),
4141
)),
4242
x509_certificate::KeyAlgorithm::Ecdsa(_) => {
43-
PublicKey::from_ec_cert_bytes(&bytes::Bytes::copy_from_slice(cert.encode_pem().as_bytes()))?
43+
PublicKey::from_ec_cert_bytes(&bytes::Bytes::copy_from_slice(cert.encode_pem().as_bytes()))
44+
.context("converting EC key bytes")?
4445
}
4546
x509_certificate::KeyAlgorithm::Ed25519 => panic!("ed25519 not supported"),
4647
},

src/cluster_crypto/crypto_utils.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{cert_key_pair::CertKeyPair, distributed_jwt, keys};
2-
use anyhow::Result;
2+
use anyhow::{Context, Result};
33
use bcder::{encode::Values, Mode};
44
use jwt_simple::prelude::RSAPublicKeyLike;
55
use rsa::{
@@ -79,13 +79,22 @@ pub(crate) fn verify_jwt(
7979

8080
pub(crate) async fn generate_rsa_key_async() -> Result<(RsaPrivateKey, InMemorySigningKeyPair)> {
8181
let rsa_private_key = RsaPrivateKey::from_pkcs8_pem(
82-
String::from_utf8_lossy(&Command::new("openssl").args(&["genrsa", "2048"]).output().await?.stdout)
83-
.to_string()
84-
.as_str(),
85-
)?;
82+
String::from_utf8(
83+
Command::new("openssl")
84+
.args(&["genrsa", "2048"])
85+
.output()
86+
.await
87+
.context("openssl genrsa")?
88+
.stdout,
89+
)
90+
.context("converting openssl key to utf-8")?
91+
.to_string()
92+
.as_str(),
93+
)
94+
.context("private from pem")?;
8695

87-
let rsa_pkcs8_der_bytes: Vec<u8> = rsa_private_key.to_pkcs8_der()?.as_bytes().into();
88-
let key_pair = InMemorySigningKeyPair::from_pkcs8_der(&rsa_pkcs8_der_bytes)?;
96+
let rsa_pkcs8_der_bytes: Vec<u8> = rsa_private_key.to_pkcs8_der().context("private to der")?.as_bytes().into();
97+
let key_pair = InMemorySigningKeyPair::from_pkcs8_der(&rsa_pkcs8_der_bytes).context("pair from der")?;
8998
Ok((rsa_private_key, key_pair))
9099
}
91100

src/cluster_crypto/keys.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ impl PublicKey {
8888
.arg("-noout")
8989
.stdin(Stdio::piped())
9090
.stdout(Stdio::piped())
91-
.spawn()?;
91+
.spawn()
92+
.context("running openssl")?;
9293

9394
command
9495
.stdin
9596
.take()
9697
.context("failed to get openssl stdin pipe")?
9798
.write_all(cert_bytes)?;
9899

99-
let output = command.wait_with_output()?;
100+
let output = command.wait_with_output().context("waiting for openssl output")?;
100101
if !output.status.success() {
101102
return Err(anyhow::anyhow!("openssl failed: {}", String::from_utf8_lossy(&output.stderr)));
102103
}

src/k8s_etcd.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ impl InMemoryK8sEtcd {
8282
}
8383
}
8484

85-
let get_result = self.etcd_client.kv_client().get(key.clone(), None).await?;
85+
let get_result = self
86+
.etcd_client
87+
.kv_client()
88+
.get(key.clone(), None)
89+
.await
90+
.context("during etcd get")?;
8691
let raw_etcd_value = get_result.kvs().first().context("key not found")?.value();
8792

8893
if key.starts_with("/kubernetes.io/machineconfiguration.openshift.io/machineconfigs/") {
8994
result.value = raw_etcd_value.to_vec();
9095
return Ok(result);
9196
}
9297

93-
let decoded_value = run_ouger("decode", raw_etcd_value).await?;
98+
let decoded_value = run_ouger("decode", raw_etcd_value).await.context("decoding value with ouger")?;
9499
self.etcd_keyvalue_hashmap
95100
.lock()
96101
.await

0 commit comments

Comments
 (0)