Skip to content

Conversation

@jreidinger
Copy link
Contributor

Problem

When user do not configure first user and try to export profile or do agama config edit and do not touch user section it failed to load with invalid user that cannot be empty.

Solution

Skip exporting user if it is not defined.

Testing

  • Tested manually

#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
/// Whether the password is hashed or is plain text
#[serde(skip_serializing_if = "Option::is_none")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is one tricky point as it does not work together with https://github.com/agama-project/agama/pull/2238/files#diff-7680a69ef487f58ca65b770c64fb4205ea33f19d9081eb44d5b0bed8d8e8e14cR58
If we want never return false value here we can have own method for skipping. Just please tell me if you agree to never export hash_password: false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is fine with me.

Copy link
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the user key still exported?

}

// small helper to convert dbus empty string to None
fn optional_string(value: String) -> Option<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
/// Whether the password is hashed or is plain text
#[serde(skip_serializing_if = "Option::is_none")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is fine with me.


impl RootUserSettings {
pub fn skip_export(&self) -> bool {
self.password.is_none() && self.hashed_password.is_none() && self.ssh_public_key.is_none()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imobachgs sadly here we have identical problem to first user with hashed password...but here it is even more tricky as password and hashed_password are always skipped during deserializing, so unless ssh_public_key is set, then it is always empty....but on other hand we want somehow indicate user that they need to set it in root user.
So I am not sure how to proceed here. Of course I can change it to something like self.hashed_password == Some(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw if hashed_password is set to true, should we really omit serialization of password to profile?

// sadly for boolean we do not have on dbus way to set it to not_set
hashed_password: Some(first_user.hashed_password),
};
let first_user = if first_user.skip_export() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could extend the D-Bus API with information about whether the user or the root was set instead of checking many conditions here.

@dgdavid
Copy link
Contributor

dgdavid commented Apr 2, 2025

@imobachgs, @jreidinger

Please, excuse me for the noise since this comment is not strictly related to the changes proposed here, but they somehow reminded me a concern about optional fields I found when reworking authentication forms in the web interface: an empty string has to be sent for unset a value, see

if (!activeMethods.password) {
data.password = "";
data.hashedPassword = false;

Just in case this rings a bell now that you're touching the users code. It might be worth creating a card with the details to address this behavior in the future. Sending empty values to represent 'no value' feels a bit awkward.

@jreidinger
Copy link
Contributor Author

@dgdavid yeap, it basically exposing dbus API which use empty string as unset. So it can be also addressed, I am just not sure if it is better to send patch, delete or something else ( I think json allows even sending null ).

@imobachgs
Copy link
Contributor

Replaced with #2462.

@imobachgs imobachgs closed this Jun 10, 2025
@dgdavid
Copy link
Contributor

dgdavid commented Jun 11, 2025

Replaced with #2462.

Did you mean #2461?

@jreidinger jreidinger deleted the fix_users_export branch October 7, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants