Skip to content

Commit

Permalink
Rebrand vaultwarden
Browse files Browse the repository at this point in the history
  • Loading branch information
ViViDboarder committed May 7, 2021
1 parent e059297 commit a0bb915
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 58 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bitwarden_rs_ldap"
name = "vaultwarden_ldap"
version = "0.3.1"
authors = ["ViViDboarder <vividboarder@gmail.com>"]
edition = "2018"
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM rust:1.46

WORKDIR /usr/src/
RUN USER=root cargo new --bin bitwarden_rs_ldap
WORKDIR /usr/src/bitwarden_rs_ldap
RUN USER=root cargo new --bin vaultwarden_ldap
WORKDIR /usr/src/vaultwarden_ldap

# Compile dependencies
COPY Cargo.toml Cargo.lock ./
RUN cargo build --locked --release

# Remove bins to make sure we rebuild
RUN rm ./target/release/deps/bitwarden_rs_ldap*
RUN rm ./target/release/deps/vaultwarden_ldap*
# Copy source and install
COPY src ./src
RUN cargo install --path .

CMD ["bitwarden_rs_ldap"]
CMD ["vaultwarden_ldap"]
6 changes: 3 additions & 3 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN cargo build --locked --release
# Remove temp src
RUN rm src/*.rs
# Remove bins to make sure we rebuild
# RUN rm ./target/release/deps/bitwarden_rs_ldap*
# RUN rm ./target/release/deps/vaultwarden_ldap*
COPY --chown=rust:rust ./src ./src
RUN touch ./src/main.rs

Expand All @@ -17,7 +17,7 @@ RUN cargo build --release
FROM alpine:3
RUN apk --no-cache add ca-certificates=20191127-r5
COPY --from=builder \
/home/rust/src/target/x86_64-unknown-linux-musl/release/bitwarden_rs_ldap \
/home/rust/src/target/x86_64-unknown-linux-musl/release/vaultwarden_ldap \
/usr/local/bin/

CMD ["/usr/local/bin/bitwarden_rs_ldap"]
CMD ["/usr/local/bin/vaultwarden_ldap"]
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOCKER_TAG ?= bitwarden_rs_ldap_${USER}
DOCKER_TAG ?= vaultwarden_ldap_${USER}

.PHONY: all
all: test check release
Expand All @@ -7,23 +7,23 @@ all: test check release
.DEFAULT_GOAL = test

# Build debug version
target/debug/bitwarden_rs_ldap: src/
target/debug/vaultwarden_ldap: src/
cargo build

# Build release version
target/release/bitwarden_rs_ldap: src/
target/release/vaultwarden_ldap: src/
cargo build --locked --release

.PHONY: debug
debug: target/debug/bitwarden_rs_ldap
debug: target/debug/vaultwarden_ldap

.PHONY: release
release: target/release/bitwarden_rs_ldap
release: target/release/vaultwarden_ldap

# Run debug version
.PHONY: run-debug
run-debug: target/debug/bitwarden_rs_ldap
target/debug/bitwarden_rs_ldap
run-debug: target/debug/vaultwarden_ldap
target/debug/vaultwarden_ldap

# Run all tests
.PHONY: test
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# bitwarden_rs_ldap
A simple LDAP connector for [bitwarden_rs](https://github.com/dani-garcia/bitwarden_rs)
# vaultwarden_ldap
An LDAP connector for [vaultwarden](https://github.com/dani-garcia/vaultwarden)

After configuring, run `bitwarden_rs_ldap` and it will invite any users it finds in LDAP to your `bitwarden_rs` instance.
After configuring, run `vaultwarden_ldap` and it will invite any users it finds in LDAP to your `vaultwarden` instance.

## Deploying

This is easiest done using Docker. See the `docker-compose.yml` file in this repo for an example. If you would like to use Docker Hub rather than building, change `build: .` to `image: vividboarder/bitwarden_rs_ldap`.
This is easiest done using Docker. See the `docker-compose.yml` file in this repo for an example. If you would like to use Docker Hub rather than building, change `build: .` to `image: vividboarder/vaultwarden_ldap`.

Make sure to populate and mount your `config.toml`!

Expand All @@ -17,9 +17,9 @@ Configuration values are as follows:

|Name|Type|Optional|Description|
|----|----|--------|-----------|
|`bitwarden_url`|String||The root URL for accessing `bitwarden_rs`. Eg: `https://bw.example.com`|
|`bitwarden_admin_token`|String||The value passed as `ADMIN_TOKEN` to `bitwarden_rs`|
|`bitwarden_root_cert_file`|String|Optional|Path to an additional der-encoded root certificate to trust. Eg. `root.cert`. If using Docker see `docker-compose.yml` for how to expose it. Defaults to `empty`|
|`vaultwarden_url`|String||The root URL for accessing `vaultwarden`. Eg: `https://vw.example.com`|
|`vaultwarden_admin_token`|String||The value passed as `ADMIN_TOKEN` to `vaultwarden`|
|`vaultwarden_root_cert_file`|String|Optional|Path to an additional der-encoded root certificate to trust. Eg. `root.cert`. If using Docker see `docker-compose.yml` for how to expose it. Defaults to `empty`|
|`ldap_host`|String||The hostname or IP address for your ldap server|
|`ldap_scheme`|String|Optional|The that should be used to connect. `ldap` or `ldaps`. This is set by default based on SSL settings|
|`ldap_ssl`|Boolean|Optional|Indicates if SSL should be used and if we should connect with `ldaps`. Defaults to `false`|
Expand All @@ -45,7 +45,7 @@ For those less familiar with `cargo`, you can use the `make` targets that have b
All testing is manual right now. First step is to set up Bitwarden and the LDAP server.

```bash
docker-compose up -d bitwarden ldap ldap_admin
docker-compose up -d vaultwarden ldap ldap_admin
```

1. After that, open the admin portal on http://localhost:8001 and log in using the default account info:
Expand Down
11 changes: 8 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ services:
dockerfile: Dockerfile.alpine
volumes:
- ./example.config.toml:/config.toml:ro
# ./root.cert:/usr/src/bitwarden_rs_ldap/root.cert:ro
# ./root.cert:/usr/src/vaultwarden_ldap/root.cert:ro
environment:
CONFIG_PATH: /config.toml
RUST_BACKTRACE: 1
depends_on:
- vaultwarden
- ldap
restart: always

bitwarden:
image: bitwardenrs/server
vaultwarden:
image: vaultwarden/server
ports:
- 8000:80
environment:
Expand Down Expand Up @@ -42,3 +45,5 @@ services:
environment:
PHPLDAPADMIN_HTTPS: 'false'
PHPLDAPADMIN_LDAP_HOSTS: ldap
depends_on:
- ldap
4 changes: 2 additions & 2 deletions example.config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bitwarden_url = "http://bitwarden:80"
bitwarden_admin_token = "admin"
vaultwarden_url = "http://vaultwarden:80"
vaultwarden_admin_token = "admin"
ldap_host = "ldap"
ldap_bind_dn = "cn=admin,dc=example,dc=org"
ldap_bind_password = "admin"
Expand Down
20 changes: 10 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub fn read_config() -> Config {
/// Contains all config values for LDAP syncing
pub struct Config {
// Bitwarden connection config
bitwarden_url: String,
bitwarden_admin_token: String,
bitwarden_root_cert_file: Option<String>,
vaultwarden_url: String,
vaultwarden_admin_token: String,
vaultwarden_root_cert_file: Option<String>,
// LDAP Connection config
ldap_host: String,
ldap_scheme: Option<String>,
Expand Down Expand Up @@ -66,17 +66,17 @@ impl Config {
read_config()
}

pub fn get_bitwarden_url(&self) -> String {
self.bitwarden_url.clone()
pub fn get_vaultwarden_url(&self) -> String {
self.vaultwarden_url.clone()
}

pub fn get_bitwarden_admin_token(&self) -> String {
self.bitwarden_admin_token.clone()
pub fn get_vaultwarden_admin_token(&self) -> String {
self.vaultwarden_admin_token.clone()
}

pub fn get_bitwarden_root_cert_file(&self) -> String {
match &self.bitwarden_root_cert_file {
Some(bitwarden_root_cert_file) => bitwarden_root_cert_file.clone(),
pub fn get_vaultwarden_root_cert_file(&self) -> String {
match &self.vaultwarden_root_cert_file {
Some(vaultwarden_root_cert_file) => vaultwarden_root_cert_file.clone(),
None => String::new(),
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use std::time::Duration;

use ldap3::{DerefAliases, LdapConn, LdapConnSettings, Scope, SearchEntry, SearchOptions};

mod bw_admin;
mod config;
mod vw_admin;

fn main() {
let config = config::Config::from_file();
let mut client = bw_admin::Client::new(
config.get_bitwarden_url().clone(),
config.get_bitwarden_admin_token().clone(),
config.get_bitwarden_root_cert_file().clone(),
let mut client = vw_admin::Client::new(
config.get_vaultwarden_url().clone(),
config.get_vaultwarden_admin_token().clone(),
config.get_vaultwarden_root_cert_file().clone(),
);

if let Err(e) = invite_users(&config, &mut client, config.get_ldap_sync_loop()) {
Expand All @@ -26,7 +26,7 @@ fn main() {
/// Invites new users to Bitwarden from LDAP
fn invite_users(
config: &config::Config,
client: &mut bw_admin::Client,
client: &mut vw_admin::Client,
start_loop: bool,
) -> Result<(), Box<dyn Error>> {
if start_loop {
Expand All @@ -39,7 +39,7 @@ fn invite_users(
}

/// Creates set of email addresses for users that already exist in Bitwarden
fn get_existing_users(client: &mut bw_admin::Client) -> Result<HashSet<String>, Box<dyn Error>> {
fn get_existing_users(client: &mut vw_admin::Client) -> Result<HashSet<String>, Box<dyn Error>> {
let all_users = client.users()?;
let mut user_emails = HashSet::with_capacity(all_users.len());
for user in all_users {
Expand Down Expand Up @@ -119,7 +119,7 @@ fn search_entries(config: &config::Config) -> Result<Vec<SearchEntry>, Box<dyn E
/// Invite all LDAP users to Bitwarden
fn invite_from_ldap(
config: &config::Config,
client: &mut bw_admin::Client,
client: &mut vw_admin::Client,
) -> Result<(), Box<dyn Error>> {
match get_existing_users(client) {
Ok(existing_users) => {
Expand Down Expand Up @@ -161,7 +161,7 @@ fn invite_from_ldap(
/// Begin sync loop to invite LDAP users to Bitwarden
fn start_sync_loop(
config: &config::Config,
client: &mut bw_admin::Client,
client: &mut vw_admin::Client,
) -> Result<(), Box<dyn Error>> {
let interval = Duration::from_secs(config.get_ldap_sync_interval_seconds());
loop {
Expand Down
File renamed without changes.

0 comments on commit a0bb915

Please sign in to comment.