Skip to content

Commit 8d0fee1

Browse files
Adds initial version of stackable bcrypt tool (#19)
Adds initial version of stackable bcrypt tool. This reads from stdin and outputs the bcrypt hashed value and is expected to be mostly useful for replacing sensitive values in init containers. We tried using https://github.com/bitnami/bcrypt-cli instead but that was incompatible with NiFi's password hashing algo - which is the initial use case. Co-authored-by: Teo Klestrup Röijezon <teo.roijezon@stackable.de>
1 parent f4130e9 commit 8d0fee1

File tree

4 files changed

+391
-0
lines changed

4 files changed

+391
-0
lines changed

stackable-bcrypt/Cargo.lock

Lines changed: 327 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stackable-bcrypt/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "stackable-bcrypt"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
bcrypt = "0.10"
10+
clap = { version = "3.0", features = ["derive"] }

stackable-bcrypt/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# BCrypt Tool
2+
3+
This is a tiny tool along the same lines as https://github.com/bitnami/bcrypt-cli to enable hashing of a cleartext password with bcrypt on the commandline. The bitnami tool didn't work for our initial use case, as it was incompatible with the salting mechanism used by NiFi for its internal password storage.
4+
5+
Most common use case will be in init containers to hash cleartext passwords from Kubernetes secrets and replace these in config files.
6+
7+
The tool reads from stdin.
8+
9+
## Usage
10+
11+
stackable-bcrypt [OPTIONS]
12+
13+
OPTIONS:
14+
-c, --cost <COST>
15+
[default: 10]

stackable-bcrypt/src/main.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use clap::Parser;
2+
use std::io;
3+
use std::process::exit;
4+
5+
#[derive(Parser)]
6+
#[clap(
7+
about = "bcrypt commandline tool",
8+
long_about = "A tiny command line tool to hash a given string using the bcrypt algorithm.\
9+
Default cost used is 10, but can be configured. \
10+
The output is only the hash, so that this can be used for automation purposes without any parsing.",
11+
author
12+
)]
13+
struct Opts {
14+
#[clap(short, long, default_value = "10")]
15+
cost: u8,
16+
}
17+
18+
fn main() {
19+
let opts = Opts::parse();
20+
21+
// Read from stdin and fail on error
22+
let mut input = String::new();
23+
io::stdin().read_line(&mut input).unwrap_or_else(|error| {
24+
eprintln!("error: {}", error);
25+
exit(-1);
26+
});
27+
28+
// Hash what we read
29+
match bcrypt::hash(&input, opts.cost.into()) {
30+
Ok(hashed) => {
31+
println!("{}", hashed);
32+
exit(0);
33+
}
34+
Err(error) => {
35+
eprintln!("error: {:?}", error);
36+
exit(-1);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)