Compare commits
1 Commits
master
...
30b789e443
| Author | SHA1 | Date | |
|---|---|---|---|
|
30b789e443
|
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[env]
|
||||
RUSTC_BOOTSTRAP = "1"
|
||||
@@ -7,9 +7,87 @@ on:
|
||||
tags:
|
||||
- v*.*.*
|
||||
|
||||
env:
|
||||
OCI_REPO: git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name}}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
uses: dreaded_x/workflows/.gitea/workflows/docker-kubernetes.yaml@ef78704b98c72e4a6b8340f9bff7b085a7bdd95c
|
||||
secrets: inherit
|
||||
with:
|
||||
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
||||
name: Build container and manifests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set timestamp and release version
|
||||
run: |
|
||||
echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
|
||||
git fetch --prune --unshallow --tags --force
|
||||
echo "RELEASE_VERSION=$(git describe --always --dirty='--modified')" >> $GITHUB_ENV
|
||||
cat $GITHUB_ENV
|
||||
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.huizinga.dev
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Install kustomize
|
||||
run: |
|
||||
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
|
||||
|
||||
- name: Setup Flux CLI
|
||||
uses: https://github.com/fluxcd/flux2/action@main
|
||||
with:
|
||||
version: v2.5.0
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.OCI_REPO }}
|
||||
tags: |
|
||||
type=edge
|
||||
type=ref,event=branch
|
||||
type=semver,pattern=v{{version}}
|
||||
type=semver,pattern=v{{major}}.{{minor}}
|
||||
type=semver,pattern=v{{major}}
|
||||
|
||||
- name: Build container
|
||||
id: build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
sbom: true
|
||||
provenance: mode=max
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
annotations: ${{ steps.meta.outputs.annotations }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
"RELEASE_VERSION=${{ env.RELEASE_VERSION }}"
|
||||
env:
|
||||
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
|
||||
|
||||
- name: Generate CRDs
|
||||
run: |
|
||||
docker run --rm ${{ env.OCI_REPO }}@${{ steps.build.outputs.imageid }} /crdgen > ./manifests/crds.yaml
|
||||
|
||||
- name: Kustomize manifests
|
||||
run: |
|
||||
./kustomize build ./manifests | sed "s/\${DIGEST}/${{ steps.build.outputs.digest }}/" > ./manifests.yaml
|
||||
|
||||
- name: Push manifests
|
||||
run: |
|
||||
flux push artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
|
||||
--path="./manifests.yaml" \
|
||||
--source="$(git config --get remote.origin.url)" \
|
||||
--revision="$(git rev-parse HEAD)" \
|
||||
$(echo "${{ steps.meta.outputs.labels }}" | sed -e 's/^/-a /')
|
||||
|
||||
flux tag artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
|
||||
$(echo "${{ steps.meta.outputs.tags }}" | sed -e 's/^.*:/--tag /')
|
||||
|
||||
@@ -2,7 +2,7 @@ fail_fast: true
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v6.0.0
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
@@ -14,7 +14,7 @@ repos:
|
||||
- id: check-merge-conflict
|
||||
|
||||
- repo: https://github.com/crate-ci/typos
|
||||
rev: typos-dict-v0.13.13
|
||||
rev: v1.31.1
|
||||
hooks:
|
||||
- id: typos
|
||||
args: ["--force-exclude"]
|
||||
@@ -72,6 +72,6 @@ repos:
|
||||
pass_filenames: false
|
||||
|
||||
- repo: https://github.com/hadolint/hadolint
|
||||
rev: v2.14.0
|
||||
rev: v2.12.0
|
||||
hooks:
|
||||
- id: hadolint
|
||||
|
||||
1486
Cargo.lock
generated
1486
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
31
Cargo.toml
31
Cargo.toml
@@ -8,38 +8,35 @@ default-run = "lldap-controller"
|
||||
members = ["queries"]
|
||||
|
||||
[workspace.dependencies]
|
||||
cynic = "3.12.0"
|
||||
cynic-codegen = "3.12.0"
|
||||
insta = { version = "1.45.0", features = ["yaml"] }
|
||||
cynic = "3.10.0"
|
||||
insta = { version = "1.42.2", features = ["yaml"] }
|
||||
|
||||
[dependencies]
|
||||
queries = { path = "./queries" }
|
||||
lldap_auth = { git = "https://github.com/lldap/lldap" }
|
||||
# Purposefully kept at 0.8.x for compatibility with lldap
|
||||
rand = { version = "0.8.5" }
|
||||
serde_json = "1.0.145"
|
||||
serde_json = "1.0.140"
|
||||
cynic = { workspace = true, features = ["http-reqwest"] }
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
kube = { version = "2.0.1", features = ["derive", "runtime"] }
|
||||
k8s-openapi = { version = "0.26.1", features = ["v1_34"] }
|
||||
schemars = { version = "1.1.0", features = ["chrono04"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
tokio = { version = "1.44.0", features = ["full"] }
|
||||
kube = { version = "0.99.0", features = ["derive", "runtime"] }
|
||||
k8s-openapi = { version = "0.24.0", features = ["v1_31"] }
|
||||
schemars = { version = "0.8.22", features = ["chrono"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_yaml = "0.9.34"
|
||||
futures = "0.3.31"
|
||||
tracing-subscriber = { version = "0.3.22", features = ["json", "env-filter"] }
|
||||
tracing = "0.1.44"
|
||||
thiserror = "2.0.17"
|
||||
chrono = "0.4.42"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["json", "env-filter"] }
|
||||
tracing = "0.1.41"
|
||||
thiserror = "2.0.12"
|
||||
chrono = "0.4.40"
|
||||
passwords = "3.1.16"
|
||||
reqwest = { version = "0.12.26", default-features = false, features = [
|
||||
reqwest = { version = "0.12.14", default-features = false, features = [
|
||||
"json",
|
||||
"rustls-tls",
|
||||
] }
|
||||
git-version = "0.3.9"
|
||||
color-eyre = "0.6.5"
|
||||
color-eyre = "0.6.3"
|
||||
dotenvy = "0.15.7"
|
||||
leon = "3.0.2"
|
||||
async-trait = "0.1.89"
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM rust:1.92 AS base
|
||||
FROM rust:1.86 AS base
|
||||
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
|
||||
RUN cargo install cargo-chef --locked --version 0.1.71 && \
|
||||
cargo install cargo-auditable --locked --version 0.6.6
|
||||
@@ -15,11 +15,9 @@ RUN cargo chef cook --release --recipe-path recipe.json
|
||||
COPY . .
|
||||
ARG RELEASE_VERSION
|
||||
ENV RELEASE_VERSION=${RELEASE_VERSION}
|
||||
RUN cargo auditable build --release && /app/target/release/crdgen > /crds.yaml
|
||||
|
||||
FROM scratch AS manifests
|
||||
COPY --from=builder /crds.yaml /
|
||||
RUN cargo auditable build --release
|
||||
|
||||
FROM gcr.io/distroless/cc-debian12:nonroot AS runtime
|
||||
COPY --from=builder /app/target/release/lldap-controller /lldap-controller
|
||||
COPY --from=builder /app/target/release/crdgen /crdgen
|
||||
CMD ["/lldap-controller"]
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
variable "TAG_BASE" {}
|
||||
variable "RELEASE_VERSION" {}
|
||||
|
||||
group "default" {
|
||||
targets = ["lldap-controller", "manifests"]
|
||||
}
|
||||
|
||||
target "docker-metadata-action" {}
|
||||
|
||||
target "lldap-controller" {
|
||||
inherits = ["docker-metadata-action"]
|
||||
context = "./"
|
||||
dockerfile = "Dockerfile"
|
||||
tags = [for tag in target.docker-metadata-action.tags : "${TAG_BASE}:${tag}"]
|
||||
target = "runtime"
|
||||
}
|
||||
|
||||
target "manifests" {
|
||||
context = "./"
|
||||
dockerfile = "Dockerfile"
|
||||
target = "manifests"
|
||||
output = [{ type = "cacheonly" }, "manifests"]
|
||||
}
|
||||
@@ -31,10 +31,6 @@ spec:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 100Mi
|
||||
volumeMounts:
|
||||
- name: credentials
|
||||
readOnly: true
|
||||
mountPath: "/secrets/credentials"
|
||||
env:
|
||||
- name: RUST_LOG
|
||||
value: info,lldap_controller=debug
|
||||
@@ -42,11 +38,10 @@ spec:
|
||||
value: "http://lldap:17170"
|
||||
- name: LLDAP_USERNAME
|
||||
value: admin
|
||||
- name: LLDAP_PASSWORD_FILE
|
||||
value: /secrets/credentials/lldap-ldap-user-pass
|
||||
- name: LLDAP_BIND_DN
|
||||
- name: LLDAP_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: lldap-credentials
|
||||
key: lldap-ldap-user-pass
|
||||
- name: BIND_DN_TEMPLATE
|
||||
value: uid={username},ou=people,dc=huizinga,dc=dev
|
||||
volumes:
|
||||
- name: credentials
|
||||
secret:
|
||||
secretName: lldap-credentials
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "queries"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cynic = { workspace = true }
|
||||
@@ -10,4 +10,4 @@ cynic = { workspace = true }
|
||||
insta = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
cynic-codegen = { workspace = true }
|
||||
cynic-codegen = "3.10.0"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "1.92"
|
||||
channel = "1.86"
|
||||
profile = "default"
|
||||
components = ["rust-analyzer"]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#![feature(let_chains)]
|
||||
pub mod context;
|
||||
pub mod lldap;
|
||||
pub mod resources;
|
||||
|
||||
36
src/lldap.rs
36
src/lldap.rs
@@ -1,5 +1,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use color_eyre::eyre::Context;
|
||||
use cynic::http::{CynicReqwestError, ReqwestExt};
|
||||
use cynic::{GraphQlError, GraphQlResponse, MutationBuilder, QueryBuilder};
|
||||
use lldap_auth::login::{ClientSimpleLoginRequest, ServerLoginResponse};
|
||||
@@ -28,19 +29,15 @@ pub enum Error {
|
||||
Authentication(#[from] AuthenticationError),
|
||||
#[error("GraphQL error: {0}")]
|
||||
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>;
|
||||
|
||||
fn check_graphql_errors<T>(response: GraphQlResponse<T>) -> Result<T> {
|
||||
if let Some(errors) = &response.errors
|
||||
&& !errors.is_empty()
|
||||
{
|
||||
Err(errors.first().expect("Should not be empty").clone())?;
|
||||
if let Some(errors) = &response.errors {
|
||||
if !errors.is_empty() {
|
||||
Err(errors.first().expect("Should not be empty").clone())?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(response
|
||||
@@ -56,26 +53,13 @@ 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())
|
||||
},
|
||||
)?;
|
||||
|
||||
pub fn try_from_env() -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
username: std::env::var("LLDAP_USERNAME")
|
||||
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_USERNAME"))?,
|
||||
password,
|
||||
url: std::env::var("LLDAP_URL")
|
||||
.map_err(|_| Error::MissingEnvironmentVariable("LLDAP_URL"))?,
|
||||
.wrap_err("Variable 'LLDAP_USERNAME' is not set")?,
|
||||
password: std::env::var("LLDAP_PASSWORD")
|
||||
.wrap_err("Variable 'LLDAP_PASSWORD' is not set")?,
|
||||
url: std::env::var("LLDAP_URL").wrap_err("Variable 'LLDAP_URL' is not set")?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ async fn main() -> color_eyre::Result<()> {
|
||||
|
||||
info!(version = VERSION, "Starting");
|
||||
|
||||
let bind_dn_template = std::env::var("LLDAP_BIND_DN").wrap_err("LLDAP_BIND_DN is not set")?;
|
||||
let bind_dn_template =
|
||||
std::env::var("BIND_DN_TEMPLATE").wrap_err("BIND_DN_TEMPLATE is not set")?;
|
||||
|
||||
let client = KubeClient::try_default().await?;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use kube::CustomResource;
|
||||
use kube::runtime::controller::Action;
|
||||
use schemars::JsonSchema;
|
||||
@@ -20,7 +19,6 @@ use crate::context::{Context, ControllerEvents};
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GroupSpec {}
|
||||
|
||||
#[async_trait]
|
||||
impl Reconcile for Group {
|
||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
||||
let name = self
|
||||
|
||||
@@ -5,7 +5,6 @@ mod user_attribute;
|
||||
use core::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use k8s_openapi::{ClusterResourceScope, NamespaceResourceScope};
|
||||
use kube::runtime::controller::Action;
|
||||
use kube::runtime::finalizer;
|
||||
@@ -44,8 +43,7 @@ impl From<finalizer::Error<Self>> for Error {
|
||||
|
||||
type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Reconcile {
|
||||
trait Reconcile {
|
||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action>;
|
||||
|
||||
async fn cleanup(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action>;
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::str::from_utf8;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use k8s_openapi::api::core::v1::Secret;
|
||||
use k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference;
|
||||
@@ -77,7 +76,6 @@ fn format_username(name: &str, namespace: &str) -> String {
|
||||
format!("{name}.{namespace}")
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Reconcile for ServiceUser {
|
||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
||||
let name = self
|
||||
@@ -126,9 +124,13 @@ impl Reconcile for ServiceUser {
|
||||
}
|
||||
};
|
||||
|
||||
let bind_dn = match bind_dn_template.render(&&vals(|key| match key {
|
||||
"username" => Some(username.clone().into()),
|
||||
_ => None,
|
||||
let bind_dn = match bind_dn_template.render(&&vals(|key| {
|
||||
if key == "username" {
|
||||
Some(username.clone().into())
|
||||
} else {
|
||||
warn!("Invalid bind_dn template key: {key}");
|
||||
None
|
||||
}
|
||||
})) {
|
||||
Ok(bind_dn) => bind_dn,
|
||||
Err(err) => {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use kube::api::{Patch, PatchParams};
|
||||
use kube::runtime::controller::Action;
|
||||
use kube::{Api, CustomResource, KubeSchema};
|
||||
use kube::{Api, CELSchema, CustomResource};
|
||||
use queries::AttributeType;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -34,7 +33,7 @@ impl From<Type> for AttributeType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, KubeSchema)]
|
||||
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, CELSchema)]
|
||||
#[kube(
|
||||
kind = "UserAttribute",
|
||||
group = "lldap.huizinga.dev",
|
||||
@@ -52,11 +51,11 @@ impl From<Type> for AttributeType {
|
||||
printcolumn = r#"{"name":"Age", "type":"date", "jsonPath":".metadata.creationTimestamp"}"#
|
||||
)]
|
||||
#[kube(
|
||||
validation = Rule::new("self.spec == oldSelf.spec").message("User attributes are immutable"),
|
||||
validation = Rule::new("!self.spec.userEditable || self.spec.userVisible && self.spec.userEditable").message("Editable attribute must also be visible")
|
||||
rule = Rule::new("self.spec == oldSelf.spec").message("User attributes are immutable"),
|
||||
rule = Rule::new("!self.spec.userEditable || self.spec.userVisible && self.spec.userEditable").message("Editable attribute must also be visible")
|
||||
)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UserAttributeSpec {
|
||||
pub struct UesrAttributeSpec {
|
||||
r#type: Type,
|
||||
#[serde(default)]
|
||||
list: bool,
|
||||
@@ -71,7 +70,6 @@ pub struct UserAttributesStatus {
|
||||
pub synced: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Reconcile for UserAttribute {
|
||||
async fn reconcile(
|
||||
self: std::sync::Arc<Self>,
|
||||
|
||||
Reference in New Issue
Block a user