Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c29377013 | |||
07123a92a9 | |||
ac15ce1d38 | |||
5a7652f3a4 | |||
95ad229077 | |||
e9673211c1 | |||
f0bf60c78a |
|
@ -7,83 +7,9 @@ on:
|
|||
tags:
|
||||
- v*.*.*
|
||||
|
||||
env:
|
||||
OCI_REPO: git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name}}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
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: 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 /')
|
||||
uses: dreaded_x/workflows/.gitea/workflows/rust-kubernetes.yaml@66ab50c3ac239dbdd1e42e6276ec2e65b6a79379
|
||||
with:
|
||||
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
||||
secrets: inherit
|
||||
|
|
107
Cargo.lock
generated
107
Cargo.lock
generated
|
@ -173,6 +173,60 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "axum"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"itoa",
|
||||
"matchit",
|
||||
"memchr",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_path_to_error",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"sync_wrapper",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.71"
|
||||
|
@ -1630,6 +1684,16 @@ dependencies = [
|
|||
"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]]
|
||||
name = "libc"
|
||||
version = "0.2.172"
|
||||
|
@ -1700,6 +1764,12 @@ dependencies = [
|
|||
"regex-automata 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchit"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
|
@ -1712,6 +1782,29 @@ version = "2.7.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
|
@ -2769,6 +2862,16 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_path_to_error"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
|
@ -2862,6 +2965,7 @@ dependencies = [
|
|||
name = "siranga"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"bytes",
|
||||
"clap",
|
||||
"clio",
|
||||
|
@ -2874,6 +2978,7 @@ dependencies = [
|
|||
"hyper",
|
||||
"hyper-util",
|
||||
"ldap3",
|
||||
"leon",
|
||||
"pin-project-lite",
|
||||
"rand 0.8.5",
|
||||
"ratatui",
|
||||
|
@ -3231,6 +3336,7 @@ dependencies = [
|
|||
"tokio",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3251,6 +3357,7 @@ version = "0.1.41"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
|
|
|
@ -5,6 +5,7 @@ default-run = "siranga"
|
|||
license = "AGPL-3.0-only"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8.3"
|
||||
bytes = "1.10.1"
|
||||
clap = { version = "4.5.35", features = ["derive"] }
|
||||
clio = { version = "0.3.5", features = ["clap-parse"] }
|
||||
|
@ -17,6 +18,7 @@ http-body-util = { version = "0.1.3", features = ["full"] }
|
|||
hyper = { version = "1.6.0", features = ["full"] }
|
||||
hyper-util = { version = "0.1.11", features = ["full"] }
|
||||
ldap3 = "0.11.5"
|
||||
leon = "3.0.2"
|
||||
pin-project-lite = "0.2.16"
|
||||
rand = "0.8.5"
|
||||
ratatui = { version = "0.29.0", features = ["unstable-backend-writer"] }
|
||||
|
|
|
@ -31,8 +31,12 @@ spec:
|
|||
cpu: 50m
|
||||
memory: 100Mi
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
- containerPort: 2222
|
||||
- name: ssh
|
||||
containerPort: 2222
|
||||
- name: http
|
||||
containerPort: 3000
|
||||
- name: metrics
|
||||
containerPort: 4000
|
||||
volumeMounts:
|
||||
- name: credentials
|
||||
readOnly: true
|
||||
|
@ -51,12 +55,23 @@ spec:
|
|||
value: ldap://lldap.lldap.svc.cluster.local:3890
|
||||
- name: LDAP_BASE
|
||||
value: ou=people,dc=huizinga,dc=dev
|
||||
- name: LDAP_SEARCH_FILTER
|
||||
value: (uid={username})
|
||||
- name: LDAP_BIND_DN
|
||||
value: uid=siranga.siranga,ou=people,dc=huizinga,dc=dev
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: siranga-lldap-credentials
|
||||
key: bind_dn
|
||||
- name: LDAP_PASSWORD_FILE
|
||||
value: /secrets/credentials/password
|
||||
- name: PRIVATE_KEY_FILE
|
||||
value: /secrets/key/private.pem
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: metrics
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 3
|
||||
volumes:
|
||||
- name: credentials
|
||||
secret:
|
||||
|
|
|
@ -6,6 +6,7 @@ spec:
|
|||
ports:
|
||||
- name: http
|
||||
port: 3000
|
||||
targetPort: http
|
||||
selector:
|
||||
app: siranga
|
||||
---
|
||||
|
@ -20,6 +21,6 @@ spec:
|
|||
ports:
|
||||
- name: ssh
|
||||
port: 22
|
||||
targetPort: 2222
|
||||
targetPort: ssh
|
||||
selector:
|
||||
app: siranga
|
||||
|
|
36
src/ldap.rs
36
src/ldap.rs
|
@ -1,4 +1,5 @@
|
|||
use ldap3::{LdapConnAsync, SearchEntry};
|
||||
use leon::{Template, vals};
|
||||
use russh::keys::PublicKey;
|
||||
use tokio::select;
|
||||
use tokio::task::JoinHandle;
|
||||
|
@ -9,6 +10,7 @@ use tracing::{debug, error};
|
|||
pub struct Ldap {
|
||||
base: String,
|
||||
ldap: ldap3::Ldap,
|
||||
search_filter: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -21,6 +23,10 @@ pub enum LdapError {
|
|||
MissingEnvironmentVariable(&'static str),
|
||||
#[error("Could not read password file: {0}")]
|
||||
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 {
|
||||
|
@ -33,11 +39,14 @@ impl Ldap {
|
|||
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_BASE"))?;
|
||||
let bind_dn = std::env::var("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(
|
||||
|_| {
|
||||
std::env::var("LDAP_PASSWORD")
|
||||
.map_err(|_| LdapError::MissingEnvironmentVariable("LDAP_PASSWORD"))
|
||||
std::env::var("LDAP_PASSWORD").map_err(|_| {
|
||||
LdapError::MissingEnvironmentVariable("LDAP_PASSWORD or LDAP_PASSWORD_FILE")
|
||||
})
|
||||
},
|
||||
|path| {
|
||||
std::fs::read_to_string(path)
|
||||
|
@ -65,20 +74,39 @@ impl Ldap {
|
|||
|
||||
ldap.simple_bind(&bind_dn, &password).await?.success()?;
|
||||
|
||||
Ok((Self { base, ldap }, handle))
|
||||
Ok((
|
||||
Self {
|
||||
base,
|
||||
ldap,
|
||||
search_filter,
|
||||
},
|
||||
handle,
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn get_ssh_keys(
|
||||
&mut self,
|
||||
user: impl AsRef<str>,
|
||||
) -> 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
|
||||
.ldap
|
||||
.search(
|
||||
&self.base,
|
||||
ldap3::Scope::Subtree,
|
||||
// TODO: Make this not hardcoded
|
||||
&format!("(uid={})", user.as_ref()),
|
||||
&search_filter,
|
||||
vec!["sshkeys"],
|
||||
)
|
||||
.await?
|
||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -4,6 +4,8 @@ use std::net::SocketAddr;
|
|||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use axum::routing::get;
|
||||
use axum::{Json, Router};
|
||||
use color_eyre::eyre::Context;
|
||||
use dotenvy::dotenv;
|
||||
use rand::rngs::OsRng;
|
||||
|
@ -54,6 +56,10 @@ async fn shutdown_task(token: CancellationToken) {
|
|||
}
|
||||
}
|
||||
|
||||
async fn axum_graceful_shutdown(token: CancellationToken) {
|
||||
token.cancelled().await;
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> color_eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
@ -85,12 +91,18 @@ async fn main() -> color_eyre::Result<()> {
|
|||
russh::keys::PrivateKey::random(&mut OsRng, russh::keys::Algorithm::Ed25519)?
|
||||
};
|
||||
|
||||
let http_port = std::env::var("HTTP_PORT")
|
||||
.map(|port| port.parse().wrap_err_with(|| format!("HTTP_PORT={port}")))
|
||||
.unwrap_or(Ok(3000))?;
|
||||
let ssh_port = std::env::var("SSH_PORT")
|
||||
.map(|port| port.parse().wrap_err_with(|| format!("SSH_PORT={port}")))
|
||||
.unwrap_or(Ok(2222))?;
|
||||
let http_port = std::env::var("HTTP_PORT")
|
||||
.map(|port| port.parse().wrap_err_with(|| format!("HTTP_PORT={port}")))
|
||||
.unwrap_or(Ok(3000))?;
|
||||
let metrics_port = std::env::var("METRICS_PORT")
|
||||
.map(|port| {
|
||||
port.parse()
|
||||
.wrap_err_with(|| format!("METRICS_PORT={port}"))
|
||||
})
|
||||
.unwrap_or(Ok(4000))?;
|
||||
|
||||
let domain =
|
||||
std::env::var("TUNNEL_DOMAIN").unwrap_or_else(|_| format!("localhost:{http_port}"));
|
||||
|
@ -114,8 +126,15 @@ async fn main() -> color_eyre::Result<()> {
|
|||
let http_task = service.serve(http_listener, token.clone());
|
||||
info!("HTTP is available on {http_addr}");
|
||||
|
||||
let metrics_app = Router::new().route("/health", get(async || Json("healthy")));
|
||||
let metrics_addr = SocketAddr::from(([0, 0, 0, 0], metrics_port));
|
||||
let metrics_listener = TcpListener::bind(metrics_addr).await?;
|
||||
let metrics = axum::serve(metrics_listener, metrics_app)
|
||||
.with_graceful_shutdown(axum_graceful_shutdown(token.clone()));
|
||||
info!("Metrics are available on {http_addr}");
|
||||
|
||||
select! {
|
||||
_ = join!(ldap_handle, ssh_task, http_task) => {
|
||||
_ = join!(ldap_handle, ssh_task, http_task, metrics.into_future()) => {
|
||||
info!("Shutdown gracefully");
|
||||
}
|
||||
_ = shutdown_task(token.clone()) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user