Skip to content

Commit

Permalink
Actually parse CLI args in krb5-provision-keytab
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Oct 23, 2024
1 parent 92fab5c commit 547b5d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/krb5-provision-keytab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ krb5 = { path = "../krb5" }
stackable-secret-operator-crd-utils = { path = "../crd-utils" }

byteorder.workspace = true
clap.workspace = true
futures.workspace = true
ldap3.workspace = true
native-tls.workspace = true
Expand Down
6 changes: 2 additions & 4 deletions rust/krb5-provision-keytab/src/active_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct AdAdmin<'a> {

impl<'a> AdAdmin<'a> {
pub async fn connect(
cluster_info_opts: &KubernetesClusterInfoOpts,
ldap_server: &str,
krb: &'a KrbContext,
ldap_tls_ca_secret: SecretReference,
Expand All @@ -103,10 +104,7 @@ impl<'a> AdAdmin<'a> {
schema_distinguished_name: String,
generate_sam_account_name: Option<ActiveDirectorySamAccountNameRules>,
) -> Result<AdAdmin<'a>> {
// We don't have the usual operator (e.g. CLI or env) options available here, so we can not pass in any special
// options that can be set. An off-the-shelf Kubernetes client is sufficient here.
let cluster_info_opts = KubernetesClusterInfoOpts::default();
let kube = stackable_operator::client::initialize_operator(None, &cluster_info_opts)
let kube = stackable_operator::client::initialize_operator(None, cluster_info_opts)
.await
.context(KubeInitSnafu)?;
let ldap_tls = native_tls::TlsConnector::builder()
Expand Down
11 changes: 11 additions & 0 deletions rust/krb5-provision-keytab/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use std::{
io::{stdin, BufReader},
};

use clap::Parser;
use krb5::{Keyblock, Keytab};
use snafu::{ResultExt, Snafu};
use stackable_krb5_provision_keytab::{AdminBackend, Request, Response};
use stackable_operator::utils::cluster_info::KubernetesClusterInfoOpts;
use tracing::info;

mod active_directory;
Expand Down Expand Up @@ -67,12 +69,20 @@ enum Error {
RemoveDummyFromKeytab { source: krb5::Error },
}

#[derive(clap::Parser)]
pub struct Args {
#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
}

enum AdminConnection<'a> {
Mit(mit::MitAdmin<'a>),
ActiveDirectory(active_directory::AdAdmin<'a>),
}

async fn run() -> Result<Response, Error> {
let args = Args::parse();

let req = serde_json::from_reader::<_, Request>(BufReader::new(stdin().lock()))
.context(DeserializeRequestSnafu)?;
info!("initing context");
Expand All @@ -97,6 +107,7 @@ async fn run() -> Result<Response, Error> {
generate_sam_account_name,
} => AdminConnection::ActiveDirectory(
active_directory::AdAdmin::connect(
&args.cluster_info_opts,
&ldap_server,
&krb,
ldap_tls_ca_secret,
Expand Down

0 comments on commit 547b5d2

Please sign in to comment.