Command line tool to convert env variables beginning with user to a htpasswd file

Overview

envhtp

This command line tool converts environment variables whose keys start with "user_" into htpasswd compatible username/password pairs.

The goal is to easily create Traefik-compatible htpasswd secrets (for BasicAuth middleware, see https://doc.traefik.io/traefik/middlewares/http/basicauth) in a CI/CD environment. The htpasswd content is Base64 encoded for this purpose and then output to stdout.

Warning: htpasswd-files generated with this tool are not considered to be super secure. Do not use this to protect production sites or sensitive data. The reason is that wether this implementation nor the underlying bcrypt implementation is audited (as far as i know) and the random number generator used to create the hashes may be insecure.

However - i use it to protect review deployments.

$ envhtp --help

envhtp 1.0.0
Florian Neumann 
   
    
Command line tool to convert env variables beginning with user to a htpasswd file.

USAGE:
    envhtp [OPTIONS]

OPTIONS:
    -h, --help                 Print help information
    -n, --no-base64            Do not encode htpasswd with Base64
    -p, --pattern 
    
         Pattern to match the beginning of env variable names. Uses remaining
                               part of env key as username [default: user_]
    -V, --version              Print version information

    
   

Examples

$ USER_Florian=Florian ./envhtp
RmxvcmlhbjokMmIkMDUkWFNLZHZPeWNBZlRLR2ExZkdWczZFLkZvRG53Q3ltT2l5eGdGOXRKSmMxWnd0RGV4YlhEek8K

$ USER_Florian=Florian ./envhtp -n
Florian:$2b$05$ok43ZDvLYUL8EVtzfyf5/OVc9iBgsn12xWjzqL43EXD5.kCGknXWq

$ lil_flo=florian lil_you=you ./envhtp -np 'lil_'
flo:$2b$05$Qs22hV79ExJEyxOnYh3SieQzTNUS1WxOOcrzuNEf8kAwYDxiZaz8q
you:$2b$05$2zFo5l7oW099/Wj4Tn5J4OHnWoQ8FWPHylbwGApon7Bv0CwVvu1Pe

Pipe into a file for further usage:

$ lil_flo=florian lil_you=you ./envhtp -np 'lil_' > .htpasswd

$ cat .htpasswd 
flo:$2b$05$X/diD1PdqfDkqginEZRVN.FdrX5etQY4c57VuelrdIOc9ijWGFsX6
you:$2b$05$5.JlIjRmZ9T7Oa045p0frOOfxmJCEwRKOcJTkyLQYCpna8baxZKRq

$ htpasswd -vb .htpasswd you you
Password for user you correct.

MIT License – Copyright (c) 2022 – Florian Neumann

You might also like...
A Modern And Secure CLI Tool For Managing Environment Variables
A Modern And Secure CLI Tool For Managing Environment Variables

Envio is a command-line tool that simplifies the management of environment variables across multiple profiles. It allows users to easily switch between different configurations and apply them to their current environment

Scriptable tool to read and write UEFI variables from EFI shell. View, save, edit and restore hidden UEFI (BIOS) Setup settings faster than with the OEM menu forms.
Scriptable tool to read and write UEFI variables from EFI shell. View, save, edit and restore hidden UEFI (BIOS) Setup settings faster than with the OEM menu forms.

UEFI Variable Tool (UVT) UEFI Variable Tool (UVT) is a command-line application that runs from the UEFI shell. It can be launched in seconds from any

A simple (but really fast!) CLI tool to convert an epub into a text file.

epub_to_txt A simple (but really fast!) CLI tool written in Rust to convert an epub into a text file (in Markdown format). Usage epub_to_txt filename.

A command line tool for easily generating multiple versions of a configuration file from a single template

MultiConf A command line tool for easily generating multiple versions of a configuration file from a single template. Why? I'm a big fan of the i3 win

rpsc is a *nix command line tool to quickly search for file systems items matching varied criterions like permissions, extended attributes and much more.

rpsc rpsc is a *nix command line tool to quickly search for file systems items matching varied criterions like permissions, extended attributes and mu

Download pdbs from symbol servers and cache locally, parse symbol paths from env vars

symsrv This crate lets you download and cache pdb files from symbol servers, according to the rules from the _NT_SYMBOL_PATH environment variable. It

⚡️(cd with env) Is a configurable cd wrapper that lets you define your environment per directory.
⚡️(cd with env) Is a configurable cd wrapper that lets you define your environment per directory.

⚡️cdwe (cd with env) A simple configurable cd wrapper that provides powerful utilities for customizing your envionment per directory. (For ZSH / BASH

Env.exe for Windows

env.exe for Windows $ env {options} {NAME=VALUE}... COMMAND ARGS... -v, --debug print verbose information --version output version information -h, -

Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

Owner
Florian Neumann
Florian Neumann
Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Harikesh Ranjan Sinha 5 May 2, 2024
A command-line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the returned URL.

Pup A command line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the return

SteveLau 11 Aug 17, 2022
hj is a command line tool to convert HTTP/1-style text into JSON

hj hj is a command line tool to convert HTTP/1-style text into JSON. This command is inspired by yusukebe/rj, which is a standalone HTTP client that s

FUJI Goro 10 Aug 21, 2022
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
Set Shell Environment Variables across multiple shells with a single configuration file.

Xshe – Cross-Shell Environment Vars xshe allows for setting Shell Environment Variables across multiple shells with a single TOML configuration file.

Ethan Kinnear 9 Dec 16, 2022
SAORI for UKAGAKA. Convert a image file to resized png file.

Resized Png GitHub repository これは何? デスクトップマスコット、「伺か」で使用できるSAORIの一種です。 機能としては、指定した画像ファイルを拡大または縮小し、pngとして出力します。 「伺か」「SAORI」等の用語については詳しく説明いたしませんのでご了承下さい。

月波 清火 2 Jan 3, 2023
This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

null 3 Mar 23, 2022
Command line linguistic tools: display pronunciation, convert between regional norms of orthography

Command line linguistic tools: display pronunciation, convert between regional norms of orthography; support for multiple modern and ancient languages: English, Latin, Polish, Quechua, Tikuna

Piotr Bajdek 7 Nov 28, 2022
Envful is a CLI tool that verifies the presence of environment variables

Envful is a CLI tool that verifies the presence of environment variables. It looks inside your .env file and the host system. You can use it to run any process while ensuring all the variables are set.

Alex Vilchis 65 Sep 8, 2022