Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl save time ldap user #90

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Changelog for binary "usermgmt" and library "usermgmt_lib".

### Added

- Added conf field "ldap_add_created_at" to opt in for creating LDAP users with creation date
Note: the field value field "ldapAttributes" under the array field "objectclass_common" is needed
within the config file. Otherwise one gets an error while creating an user within LDAP""
- Added configuration field "ldap_default_user". Allows to define username for LDAP login used by default.
- Added CLI option to specify the configuration file
- Logging also performed to logging file
Expand Down
9 changes: 6 additions & 3 deletions Cargo.lock

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

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ usermgmt generate-config > /home/foo/conf.toml
The `conf.toml` file looks as follows:

```toml
# If true, a timestamp is created within the LDAP database.
# Timestamp is when an user was created within LDAP database user entry
# Make sure to also include the field "'ldapAttributes'" under the array "objectclass_common"
# Within the config file. Otherwise one gets an error while creating an user within LDAP.
# The timestamp is saved in the format of rfc 3339 with the UTC time zone.
# Example of date and time 'year: 2024, month: may, day: 9 and hour: 10, minutes: 49 and seconds: 34'
# 2024-05-09T10:49:34.545686277+00:00
# Link: To this rfc 3339 => https://www.rfc-editor.org/rfc/rfc3339
ldap_add_created_at = true
# Default value of the Slurm default QOS for the student group
student_default_qos = 'basic'
# Default value of the Slurm default QOS for the staff group
Expand Down Expand Up @@ -403,6 +412,16 @@ This project currently consists of 3 crates:

## Tips and advanced usage

### LDAP: Create users with a date of their creation

There is a feature of this tool in which a creation date is added to the LDAP user upon creation.
To preserve the backwards compatibility with earlier versions, this features must be opted in.

You can opt in by the following steps:

1. Set the field value "ldap_add_created_at" to `true` within the configuration file.
2. Add the value "ldapAttributes" to the array value "objectclass_common" within the configuration file.

### Use SSH agent for ssh authentication

To save yourself entering password for ssh authentication again and again,
Expand Down
2 changes: 2 additions & 0 deletions conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# ldap bind for user is cn=admin,dc=example,dc=org in docker set up

ldap_add_created_at = true
student_default_qos = 'basic'
staff_default_qos = 'advanced'
student_qos = ['interactive', 'basic']
Expand All @@ -17,6 +18,7 @@ objectclass_common = [
'posixAccount',
'shadowAccount',
'slurmRole',
'ldapAttributes',
'top',
]
compute_nodes = ['m0.host.de', 'ml1.host.de']
Expand Down
13 changes: 13 additions & 0 deletions docker/bootstrap_lidfs/02_scheme_ldap_attr.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dn: cn=ldap_specs,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: ldap_specs
olcAttributeTypes: {0}( 1.3.6.1.4.1.49213.1.1.30 NAME 'createdAt'
DESC 'When the user was added to the LDAP database'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE
)
olcObjectClasses: {0}( 1.3.6.1.4.1.24552.500.200.1.2.17 NAME 'ldapAttributes' SUP top AUXILIARY
DESC 'Specific attributes releated to LDAP'
MUST ( createdAt )
)
3 changes: 2 additions & 1 deletion usermgmt_gui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

All changes to the GUI Frontend of the usermgmt project.
All changes to the GUI Front-End of the usermgmt project.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Expand All @@ -11,6 +11,7 @@ Changelog for binary "usermgmt_gui".

### Added

- Added an edit field for "objectclass_common" of configuration file within the configuration window.
- Logging also performed to logging file
- Ssh key pair can be provided by field within configuration

Expand Down
2 changes: 2 additions & 0 deletions usermgmt_gui/src/drawing/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ fn construct_fields(config: &mut MgmtConfig, map: CacheForConfFields) -> Vec<Con
}

let mut fields: Vec<ConfiField> = vec![
create_conf_field!(objectclass_common),
create_conf_field!(ldap_add_created_at),
create_conf_field!(student_default_qos),
create_conf_field!(staff_default_qos),
create_conf_field!(default_ssh_user),
Expand Down
1 change: 1 addition & 0 deletions usermgmt_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [
"deref",
] }
flexi_logger = { version = "0.27.4", features = ["async"] }
chrono = { version = "0.4.38", features = ["alloc"] }

[dev-dependencies]
insta = { version = "1.35.1", features = ["yaml"] }
2 changes: 2 additions & 0 deletions usermgmt_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct MgmtConfig {
pub ldap_readonly_user_prefix: Option<String>,
pub ldap_bind_prefix: Option<String>,
pub ldap_bind_org_unit: Option<String>,
pub ldap_add_created_at: bool,
pub home_host: String,
pub nfs_host: String,
pub head_node: String,
Expand Down Expand Up @@ -83,6 +84,7 @@ impl MgmtConfig {
impl Default for MgmtConfig {
fn default() -> Self {
MgmtConfig {
ldap_add_created_at: false,
student_default_qos: "basic".to_string(),
staff_default_qos: "advanced".to_string(),
student_qos: vec!["interactive".to_string(), "basic".to_string()],
Expand Down
74 changes: 50 additions & 24 deletions usermgmt_lib/src/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod ldap_session;
mod ldap_simple_credential;
pub mod text_list_output;

use chrono::Utc;
pub use ldap_config::LDAPConfig;
pub use ldap_credential::LdapCredential;
pub use ldap_search_result::LdapSearchResult;
Expand Down Expand Up @@ -91,6 +92,24 @@ where
where
T: LdapCredential,
{
fn add_fields<T>(
connection: &mut LdapConn,
entity: &NewEntity,
ldap_config: &LDAPConfig<T>,
fields: Vec<(&str, HashSet<&str>)>,
) -> AppResult
where
T: LdapCredential,
{
let result_from_adding = connection.add(
&format!("uid={},{}", entity.username, ldap_config.base()),
fields,
);

ldap_is_success(result_from_adding).context("Unable to create LDAP user!")?;
Ok(())
}

let un = entity.username.as_ref().as_str();
let gid = entity.group.gid().to_string();
let uid = uid.to_string();
Expand All @@ -115,30 +134,36 @@ where
.unwrap_or("");

ldap_session.action(|connection, ldap_config| {
let result_form_adding = connection.add(
&format!("uid={},{}", entity.username, ldap_config.base()),
vec![
("cn", hashset! {un}),
(
"objectClass",
hashset_from_vec_str(&config.objectclass_common).to_owned(),
),
("gidNumber", hashset! {gid.as_str()}),
("uidNumber", hashset! {uid.as_str()}),
("uid", hashset! {un}),
("sn", hashset! {ln}),
("givenName", hashset! {gn}),
("mail", hashset! {mail}),
("slurmDefaultQos", hashset! {def_qos}),
("homeDirectory", hashset! {home.as_str()}),
("slurmQos", qos),
("sshPublicKey", hashset! {pubkey}),
("loginShell", hashset! {config.login_shell.as_str()}),
],
);

ldap_is_success(result_form_adding).context("Unable to create LDAP user!")?;
Ok(())
let mut fields = vec![
("cn", hashset! {un}),
(
"objectClass",
hashset_from_vec_str(&config.objectclass_common).to_owned(),
),
("gidNumber", hashset! {gid.as_str()}),
("uidNumber", hashset! {uid.as_str()}),
("uid", hashset! {un}),
("sn", hashset! {ln}),
("givenName", hashset! {gn}),
("mail", hashset! {mail}),
("slurmDefaultQos", hashset! {def_qos}),
("homeDirectory", hashset! {home.as_str()}),
("slurmQos", qos),
("sshPublicKey", hashset! {pubkey}),
("loginShell", hashset! {config.login_shell.as_str()}),
];

if config.ldap_add_created_at {
let created_at = Utc::now().to_rfc3339();
let attr = hashset! {created_at.as_str()};
fields.push(("createdAt", attr));

add_fields(connection, entity, ldap_config, fields)?;
Ok(())
} else {
add_fields(connection, entity, ldap_config, fields)?;
Ok(())
}
})
}
}
Expand Down Expand Up @@ -522,6 +547,7 @@ static SORTED_LDAP_LISTING_ATTRIBUTES: Lazy<Vec<&str>> = Lazy::new(|| {
"mail",
"slurmDefaultQos",
"slurmQos",
"createdAt",
];
to_sort.sort();
to_sort
Expand Down
1 change: 1 addition & 0 deletions usermgmt_lib/src/ldap/ldap_search_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl LdapSearchResult {
pub fn headers(&self) -> Vec<&str> {
self.header.iter().map(|string| string.as_str()).collect()
}

pub fn fields(&self) -> Vec<Vec<Vec<&str>>> {
self.fields
.as_slice()
Expand Down
Loading