File tree 7 files changed +65
-12
lines changed
7 files changed +65
-12
lines changed Original file line number Diff line number Diff line change
1
+ cluster-files
2
+ cluster-files-backup
3
+ target
Original file line number Diff line number Diff line change
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" ]
Original file line number Diff line number Diff line change @@ -239,3 +239,9 @@ ssh $SSH_FLAGS "$SSH_HOST" sudo systemctl enable kubelet
239
239
ssh $SSH_FLAGS " $SSH_HOST " sudo systemctl enable crio
240
240
ssh $SSH_FLAGS " $SSH_HOST " sudo reboot
241
241
` ` `
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
Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ impl TryFrom<CapturedX509Certificate> for Certificate {
40
40
& bytes:: Bytes :: copy_from_slice ( & cert. to_public_key_der ( ) . context ( "parsing public key" ) ?. as_bytes ( ) ) ,
41
41
) ) ,
42
42
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" ) ?
44
45
}
45
46
x509_certificate:: KeyAlgorithm :: Ed25519 => panic ! ( "ed25519 not supported" ) ,
46
47
} ,
Original file line number Diff line number Diff line change 1
1
use super :: { cert_key_pair:: CertKeyPair , distributed_jwt, keys} ;
2
- use anyhow:: Result ;
2
+ use anyhow:: { Context , Result } ;
3
3
use bcder:: { encode:: Values , Mode } ;
4
4
use jwt_simple:: prelude:: RSAPublicKeyLike ;
5
5
use rsa:: {
@@ -79,13 +79,22 @@ pub(crate) fn verify_jwt(
79
79
80
80
pub ( crate ) async fn generate_rsa_key_async ( ) -> Result < ( RsaPrivateKey , InMemorySigningKeyPair ) > {
81
81
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" ) ?;
86
95
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" ) ?;
89
98
Ok ( ( rsa_private_key, key_pair) )
90
99
}
91
100
Original file line number Diff line number Diff line change @@ -88,15 +88,16 @@ impl PublicKey {
88
88
. arg ( "-noout" )
89
89
. stdin ( Stdio :: piped ( ) )
90
90
. stdout ( Stdio :: piped ( ) )
91
- . spawn ( ) ?;
91
+ . spawn ( )
92
+ . context ( "running openssl" ) ?;
92
93
93
94
command
94
95
. stdin
95
96
. take ( )
96
97
. context ( "failed to get openssl stdin pipe" ) ?
97
98
. write_all ( cert_bytes) ?;
98
99
99
- let output = command. wait_with_output ( ) ?;
100
+ let output = command. wait_with_output ( ) . context ( "waiting for openssl output" ) ?;
100
101
if !output. status . success ( ) {
101
102
return Err ( anyhow:: anyhow!( "openssl failed: {}" , String :: from_utf8_lossy( & output. stderr) ) ) ;
102
103
}
Original file line number Diff line number Diff line change @@ -82,15 +82,20 @@ impl InMemoryK8sEtcd {
82
82
}
83
83
}
84
84
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" ) ?;
86
91
let raw_etcd_value = get_result. kvs ( ) . first ( ) . context ( "key not found" ) ?. value ( ) ;
87
92
88
93
if key. starts_with ( "/kubernetes.io/machineconfiguration.openshift.io/machineconfigs/" ) {
89
94
result. value = raw_etcd_value. to_vec ( ) ;
90
95
return Ok ( result) ;
91
96
}
92
97
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" ) ?;
94
99
self . etcd_keyvalue_hashmap
95
100
. lock ( )
96
101
. await
You can’t perform that action at this time.
0 commit comments