Compare commits
No commits in common. "5a7652f3a47ab184f3054c617efe8b501db5e289" and "e9673211c1a3a79925b9b81c400585c2fa5b81d8" have entirely different histories.
5a7652f3a4
...
e9673211c1
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -1684,16 +1684,6 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "leon"
|
|
||||||
version = "3.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "42a865ffec5587961f5afc6d365bccb304f4feaa1928f4fe94c91c9d210d7310"
|
|
||||||
dependencies = [
|
|
||||||
"miette",
|
|
||||||
"thiserror 2.0.12",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.172"
|
version = "0.2.172"
|
||||||
|
@ -1782,29 +1772,6 @@ version = "2.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miette"
|
|
||||||
version = "7.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1a955165f87b37fd1862df2a59547ac542c77ef6d17c666f619d1ad22dd89484"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"miette-derive",
|
|
||||||
"thiserror 1.0.69",
|
|
||||||
"unicode-width 0.1.14",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miette-derive"
|
|
||||||
version = "7.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bf45bf44ab49be92fd1227a3be6fc6f617f1a337c06af54981048574d8783147"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
|
@ -2978,7 +2945,6 @@ dependencies = [
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"ldap3",
|
"ldap3",
|
||||||
"leon",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
|
|
@ -18,7 +18,6 @@ http-body-util = { version = "0.1.3", features = ["full"] }
|
||||||
hyper = { version = "1.6.0", features = ["full"] }
|
hyper = { version = "1.6.0", features = ["full"] }
|
||||||
hyper-util = { version = "0.1.11", features = ["full"] }
|
hyper-util = { version = "0.1.11", features = ["full"] }
|
||||||
ldap3 = "0.11.5"
|
ldap3 = "0.11.5"
|
||||||
leon = "3.0.2"
|
|
||||||
pin-project-lite = "0.2.16"
|
pin-project-lite = "0.2.16"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
ratatui = { version = "0.29.0", features = ["unstable-backend-writer"] }
|
ratatui = { version = "0.29.0", features = ["unstable-backend-writer"] }
|
||||||
|
|
|
@ -55,13 +55,8 @@ spec:
|
||||||
value: ldap://lldap.lldap.svc.cluster.local:3890
|
value: ldap://lldap.lldap.svc.cluster.local:3890
|
||||||
- name: LDAP_BASE
|
- name: LDAP_BASE
|
||||||
value: ou=people,dc=huizinga,dc=dev
|
value: ou=people,dc=huizinga,dc=dev
|
||||||
- name: LDAP_SEARCH_FILTER
|
|
||||||
value: (uid={username})
|
|
||||||
- name: LDAP_BIND_DN
|
- name: LDAP_BIND_DN
|
||||||
valueFrom:
|
value: uid=siranga.siranga,ou=people,dc=huizinga,dc=dev
|
||||||
secretKeyRef:
|
|
||||||
name: siranga-lldap-credentials
|
|
||||||
key: bind_dn
|
|
||||||
- name: LDAP_PASSWORD_FILE
|
- name: LDAP_PASSWORD_FILE
|
||||||
value: /secrets/credentials/password
|
value: /secrets/credentials/password
|
||||||
- name: PRIVATE_KEY_FILE
|
- name: PRIVATE_KEY_FILE
|
||||||
|
|
31
src/ldap.rs
31
src/ldap.rs
|
@ -1,5 +1,4 @@
|
||||||
use ldap3::{LdapConnAsync, SearchEntry};
|
use ldap3::{LdapConnAsync, SearchEntry};
|
||||||
use leon::{Template, vals};
|
|
||||||
use russh::keys::PublicKey;
|
use russh::keys::PublicKey;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
@ -10,7 +9,6 @@ use tracing::{debug, error};
|
||||||
pub struct Ldap {
|
pub struct Ldap {
|
||||||
base: String,
|
base: String,
|
||||||
ldap: ldap3::Ldap,
|
ldap: ldap3::Ldap,
|
||||||
search_filter: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
@ -23,10 +21,6 @@ pub enum LdapError {
|
||||||
MissingEnvironmentVariable(&'static str),
|
MissingEnvironmentVariable(&'static str),
|
||||||
#[error("Could not read password file: {0}")]
|
#[error("Could not read password file: {0}")]
|
||||||
CouldNotReadPasswordFile(#[from] std::io::Error),
|
CouldNotReadPasswordFile(#[from] std::io::Error),
|
||||||
#[error("Failed to parse search filter: {0}")]
|
|
||||||
FailedToParseSearchFilter(#[from] leon::ParseError),
|
|
||||||
#[error("Failed to render search filter: {0}")]
|
|
||||||
FailedToRenderSearchFilter(#[from] leon::RenderError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ldap {
|
impl Ldap {
|
||||||
|
@ -39,8 +33,6 @@ impl Ldap {
|
||||||
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_BASE"))?;
|
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_BASE"))?;
|
||||||
let bind_dn = std::env::var("LDAP_BIND_DN")
|
let bind_dn = std::env::var("LDAP_BIND_DN")
|
||||||
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_BIND_DN"))?;
|
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_BIND_DN"))?;
|
||||||
let search_filter = std::env::var("LDAP_SEARCH_FILTER")
|
|
||||||
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_SEARCH_FILTER"))?;
|
|
||||||
|
|
||||||
let password = std::env::var("LDAP_PASSWORD_FILE").map_or_else(
|
let password = std::env::var("LDAP_PASSWORD_FILE").map_or_else(
|
||||||
|_| {
|
|_| {
|
||||||
|
@ -73,39 +65,20 @@ impl Ldap {
|
||||||
|
|
||||||
ldap.simple_bind(&bind_dn, &password).await?.success()?;
|
ldap.simple_bind(&bind_dn, &password).await?.success()?;
|
||||||
|
|
||||||
Ok((
|
Ok((Self { base, ldap }, handle))
|
||||||
Self {
|
|
||||||
base,
|
|
||||||
ldap,
|
|
||||||
search_filter,
|
|
||||||
},
|
|
||||||
handle,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_ssh_keys(
|
pub async fn get_ssh_keys(
|
||||||
&mut self,
|
&mut self,
|
||||||
user: impl AsRef<str>,
|
user: impl AsRef<str>,
|
||||||
) -> Result<Vec<PublicKey>, LdapError> {
|
) -> Result<Vec<PublicKey>, LdapError> {
|
||||||
let search_filter = Template::parse(&self.search_filter)?;
|
|
||||||
|
|
||||||
let search_filter = search_filter.render(&&vals(|key| {
|
|
||||||
if key == "username" {
|
|
||||||
Some(user.as_ref().to_string().into())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}))?;
|
|
||||||
|
|
||||||
debug!("search_filter = {search_filter}");
|
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.ldap
|
.ldap
|
||||||
.search(
|
.search(
|
||||||
&self.base,
|
&self.base,
|
||||||
ldap3::Scope::Subtree,
|
ldap3::Scope::Subtree,
|
||||||
// TODO: Make this not hardcoded
|
// TODO: Make this not hardcoded
|
||||||
&search_filter,
|
&format!("(uid={})", user.as_ref()),
|
||||||
vec!["sshkeys"],
|
vec!["sshkeys"],
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user