Update compose to mostly work

Untested since latest bitwarden_rs image doesn't have new endpoints
This commit is contained in:
ViViDboarder 2019-04-11 17:07:59 -07:00
parent d373a99211
commit 8171464c49
5 changed files with 52 additions and 51 deletions

View File

@ -1,8 +1,19 @@
FROM rust:1.33 FROM rust:1.33
WORKDIR /usr/src/myapp WORKDIR /usr/src/
COPY . . RUN USER=root cargo new --bin bitwarden_rs_ldap
WORKDIR /usr/src/bitwarden_rs_ldap
# Compile dependencies
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
RUN cargo build --release
# Remove temp src
RUN rm src/*.rs
# Copy source and install
COPY ./src ./src
RUN rm ./target/release/deps/bitwarden_rs_ldap*
RUN cargo install --path . RUN cargo install --path .
CMD ["bitwarden_rs_ldap"] CMD ["bitwarden_rs_ldap"]

View File

@ -1,29 +0,0 @@
version: '3'
services:
ldap:
image: osixia/openldap
ports:
- 389:389
- 636:636
volumes:
- /var/lib/ldap
- /etc/ldap/slapd.d
environment:
LDAP_READONLY_USER: 'true'
LDAP_READONLY_USER_USERNAME: readonly
LDAP_READONLY_USER_PASSWORD: readonly
admin:
image: osixia/phpldapadmin
ports:
- 8001:80
environment:
PHPLDAPADMIN_HTTPS: 'false'
PHPLDAPADMIN_LDAP_HOSTS: ldap
admin-host:
image: osixia/phpldapadmin
ports:
- 80:80
network_mode: "host"
environment:
PHPLDAPADMIN_HTTPS: 'false'
PHPLDAPADMIN_LDAP_HOSTS: 0.0.0.0

View File

@ -2,9 +2,16 @@ version: '3'
services: services:
ldap_sync: ldap_sync:
build: . build: .
volumes:
- ./example.config.toml:/usr/src/bitwarden_rs_ldap/config.toml:ro
restart: always
bitwarden: bitwarden:
image: mprasil/bitwarden_rs image: mprasil/bitwarden
ports:
- 8000:80
environment:
ADMIN_TOKEN: admin
ldap: ldap:
image: osixia/openldap image: osixia/openldap

8
example.config.toml Normal file
View File

@ -0,0 +1,8 @@
bitwarden_url = "http://bitwarden:80"
bitwarden_admin_token = "admin"
ldap_host = "ldap"
ldap_bind_dn = "cn=admin,dc=example,dc=org"
ldap_bind_password = "admin"
ldap_search_base_dn = "dc=example,dc=org"
ldap_search_filter = "(&(objectClass=*)(uid=*))"
ldap_sync_interval_seconds = 10

View File

@ -28,8 +28,6 @@ fn invite_users(
client: &mut bw_admin::Client, client: &mut bw_admin::Client,
start_loop: bool, start_loop: bool,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<Error>> {
// TODO: Better error handling to differentiate failure to connect to Bitwarden vs LDAP
if start_loop { if start_loop {
start_sync_loop(config, client)?; start_sync_loop(config, client)?;
} else { } else {
@ -74,7 +72,7 @@ fn search_entries(config: &config::Config) -> Result<Vec<SearchEntry>, Box<Error
); );
if ldap.is_err() { if ldap.is_err() {
println!("Error: Could not connect to ldap server"); println!("Error: Could not bind to ldap server");
} }
let mail_field = config.get_ldap_mail_field(); let mail_field = config.get_ldap_mail_field();
@ -105,26 +103,32 @@ fn invite_from_ldap(
config: &config::Config, config: &config::Config,
client: &mut bw_admin::Client, client: &mut bw_admin::Client,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<Error>> {
let existing_users = get_existing_users(client)?; match get_existing_users(client) {
Ok(existing_users) => {
let mail_field = config.get_ldap_mail_field(); let mail_field = config.get_ldap_mail_field();
let mut num_users = 0; let mut num_users = 0;
for ldap_user in search_entries(config)? { for ldap_user in search_entries(config)? {
if let Some(user_email) = ldap_user.attrs[mail_field.as_str()].first() { if let Some(user_email) = ldap_user.attrs[mail_field.as_str()].first() {
if existing_users.contains(user_email) { if existing_users.contains(user_email) {
println!("User with email already exists: {}", user_email); println!("User with email already exists: {}", user_email);
} else { } else {
println!("Try to invite user: {}", user_email); println!("Try to invite user: {}", user_email);
let response = client.invite(user_email); let response = client.invite(user_email);
num_users = num_users + 1; num_users = num_users + 1;
println!("Invite response: {:?}", response); println!("Invite response: {:?}", response);
}
}
} }
// Maybe think about returning this value for some other use
println!("Sent invites to {} user(s).", num_users);
},
Err(e) => {
println!("Error: Failed to get existing users from Bitwarden");
return Err(e);
} }
} }
// Maybe think about returning this value for some other use
println!("Sent invites to {} user(s).", num_users);
Ok(()) Ok(())
} }