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: requests:
cpu: 50m cpu: 50m
memory: 100Mi memory: 100Mi
volumeMounts:
- name: credentials
readOnly: true
mountPath: "/secrets/credentials"
env: env:
- name: RUST_LOG - name: RUST_LOG
value: info,lldap_controller=debug value: info,lldap_controller=debug
@ -38,10 +42,11 @@ spec:
value: "http://lldap:17170" value: "http://lldap:17170"
- name: LLDAP_USERNAME - name: LLDAP_USERNAME
value: admin value: admin
- name: LLDAP_PASSWORD - name: LLDAP_PASSWORD_FILE
valueFrom: value: /secrets/credentials/lldap-ldap-user-pass
secretKeyRef:
name: lldap-credentials
key: lldap-ldap-user-pass
- name: LLDAP_BIND_DN - name: LLDAP_BIND_DN
value: uid={username},ou=people,dc=huizinga,dc=dev 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), GraphQl(#[from] GraphQlError),
#[error("Missing environment variable: {0}")] #[error("Missing environment variable: {0}")]
MissingEnvironmentVariable(&'static str), 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>; pub type Result<T, E = Error> = std::result::Result<T, E>;
@ -55,11 +57,23 @@ pub struct LldapConfig {
impl LldapConfig { impl LldapConfig {
pub fn try_from_env() -> Result<Self> { 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 { Ok(Self {
username: std::env::var("LLDAP_USERNAME") username: std::env::var("LLDAP_USERNAME")
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_USERNAME"))?, .map_err(|_| Error::MissingEnvironmentVariable("LLDAP_USERNAME"))?,
password: std::env::var("LLDAP_PASSWORD") password,
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_PASSWORD"))?,
url: std::env::var("LLDAP_URL") url: std::env::var("LLDAP_URL")
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_URL"))?, .map_err(|_| Error::MissingEnvironmentVariable("LLDAP_URL"))?,
}) })