Added option to load lldap password from file (#12)
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 6m15s
kustomization/lldap-controller/b5ae0585 reconciliation succeeded

This commit is contained in:
Dreaded_X 2025-04-22 10:49:39 +02:00
parent f714773ba8
commit 8a07d661ce
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA
2 changed files with 26 additions and 7 deletions

View File

@ -31,6 +31,10 @@ spec:
requests:
cpu: 50m
memory: 100Mi
volumeMounts:
- name: credentials
readOnly: true
mountPath: "/secrets/credentials"
env:
- name: RUST_LOG
value: info,lldap_controller=debug
@ -38,10 +42,11 @@ spec:
value: "http://lldap:17170"
- name: LLDAP_USERNAME
value: admin
- name: LLDAP_PASSWORD
valueFrom:
secretKeyRef:
name: lldap-credentials
key: lldap-ldap-user-pass
- name: LLDAP_PASSWORD_FILE
value: /secrets/credentials/lldap-ldap-user-pass
- name: LLDAP_BIND_DN
value: uid={username},ou=people,dc=huizinga,dc=dev
volumes:
- name: credentials
secret:
secretName: lldap-credentials

View File

@ -30,6 +30,8 @@ pub enum Error {
GraphQl(#[from] GraphQlError),
#[error("Missing environment variable: {0}")]
MissingEnvironmentVariable(&'static str),
#[error("Could not read password file: {0}")]
CouldNotReadPasswordFile(#[from] std::io::Error),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
@ -55,11 +57,23 @@ pub struct LldapConfig {
impl LldapConfig {
pub fn try_from_env() -> Result<Self> {
let password = std::env::var("LLDAP_PASSWORD_FILE").map_or_else(
|_| {
std::env::var("LLDAP_PASSWORD").map_err(|_| {
Error::MissingEnvironmentVariable("LLDAP_PASSWORD or LLDAP_PASSWORD_FILE")
})
},
|path| {
std::fs::read_to_string(path)
.map(|v| v.trim().into())
.map_err(|err| err.into())
},
)?;
Ok(Self {
username: std::env::var("LLDAP_USERNAME")
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_USERNAME"))?,
password: std::env::var("LLDAP_PASSWORD")
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_PASSWORD"))?,
password,
url: std::env::var("LLDAP_URL")
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_URL"))?,
})