Skip to content

Conversation

@stataru8
Copy link

@stataru8 stataru8 commented Sep 20, 2024

https://issues.apache.org/jira/browse/KARAF-5014

This issue is quite old and only affects those who directly modify the users file. I'm not sure if it is still relevant, or if the current behaviour should be considered acceptable.

Current behaviour:

  • the first role in a group is ignored
  • when a group is created via jaas commands, the password/role group is added by default

Proposal:

  • consider the first role in a group
  • when a group is created using jaas commands, add password/role "" by default, leaving the group information empty
  • ignore empty roles in both users and groups

@AndreVirtimo
Copy link
Contributor

Hi @stataru8 , thank you for picking up this issue.

Why do you propose "when a group is created using jaas commands, add an empty role by default"? Is this because there is no role which could be assigned during creation? Is it not possible to have an empty group?

Regards
Andre

@jbonofre jbonofre self-requested a review September 27, 2024 12:15
@jbonofre
Copy link
Member

jbonofre commented Sep 27, 2024

I think @stataru8 meant add empty password for role (as a role doesn't have password).

A group can be empty without problem though.

throw new IllegalArgumentException("Prefix not permitted: " + GROUP_PREFIX);

addUserInternal(username, password);
addUserInternal(username, encryptionSupport.encrypt(password));
Copy link
Member

Choose a reason for hiding this comment

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

Why forcing encryption here ? It's an optional feature.

Copy link
Author

@stataru8 stataru8 Sep 27, 2024

Choose a reason for hiding this comment

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

I just moved this call from its original location in addUserInternal:

The call is only needed when adding a user and shouldn't be made when adding a group:

addUserInternal(groupName, ""); // groups don't have password
There is the risk of encrypting "", which with the defaults, results in {CRYPT}ABC...{CRYPT}. After jaas:group-add karaf newGrup,
jaas:user-list will return

User Name | Group   | Role
----------+---------+-------------------------------------------------------------------------------
karaf     | newGrup | {CRYPT}ABC...{CRYPT}

Maybe at this point, we should create another addUserInternal with just the username as an argument: private void addUserInternal(String username), or another function just for groups...

if (role.equals(rp.getName())) {
return;

// groups don't have password and empty should be ignored
Copy link
Member

Choose a reason for hiding this comment

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

A group can be empty (no role, no group, no user).

Copy link
Author

Choose a reason for hiding this comment

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

My original comment was a bit misleading, what I meant is:

  • If a user info is empty, we shouldn't replace "" by role, or else role becomes the user's password.
  • If a group info is empty, we should replace "" by role.

@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch 2 times, most recently from dac3692 to c01d0bc Compare September 27, 2024 16:07
@stataru8
Copy link
Author

Hello @AndreVirtimo, as far as I know, we have two commands that allow us to create groups:

  • jaas:group-add user myGroup1
  • jaas:group-create myGroup2

In both cases, there is no mandatory argument for the role. Today, the role/password group is added by default. The proposal is to add "" instead, leaving the group information empty.

@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from c01d0bc to a30ea9d Compare November 7, 2024 17:44
@jbonofre
Copy link
Member

jbonofre commented Nov 8, 2024

Sorry for the delay in the review/comment. I want to provide some context.

The idea of the first "role" in a group definition, it's not actually a role but just a "prefix" (group,) to indicate that we are in a group.

That's why be default, in etc/users.properties you have:

_g_\:admingroup = group,admin,manager,viewer,systembundles,ssh

You can see that group here is not actually a role in admingroup but a "prefix flag".

I agree it's confusing (including the documentation), but if we "change" to remove the prefix, it means that group would be considered as a role in admingroup.

Copy link
Member

@jbonofre jbonofre left a comment

Choose a reason for hiding this comment

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

Can you please update default etc/users.properties to remove group as it's not actually a role ?

@stataru8
Copy link
Author

stataru8 commented Nov 8, 2024

I just realized that group is also used as a "prefix flag" in keys.properties. I wonder if the changes need to be propagated in this login module as well:

Let me know if is that's too much for this PR or out of scope.

If all these changes are too risky, just making the documentation clearer about the "prefix flag" is also an option...

@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from a30ea9d to 5bef795 Compare November 8, 2024 18:43
@jbonofre
Copy link
Member

jbonofre commented Nov 9, 2024

@stataru8 yes, historically, we use this "flag" in all group/role definition (users, keys, ...). So, we can consider this as a breaking change for users (if we remove the group prefix).
I wonder what's the best option:

  1. Documenting clearly the group prefix (but I wonder if it's still useful to have this prefix)
  2. Remove the use of group prefix for Karaf 4.5.0 (as it's a breaking change)
    Thoughts ?

@AndreVirtimo
Copy link
Contributor

I don't think we need a flag in the value. Because we already have g in the key.

So I am in favor of a change. I think the risk is low. If users don't migrate their configuration, they get an additional role “group”, which shouldn't hurt.

@jbonofre
Copy link
Member

@AndreVirtimo i agree. However this PR should be completed to keys file.

@stataru8
Copy link
Author

stataru8 commented Nov 11, 2024

I'll try to commit the changes for keys.properties this week or next. Will request a re-review once it's done.

UPDATE: I'll need more time to test this.

@stataru8 stataru8 marked this pull request as draft November 20, 2024 15:07
@stataru8
Copy link
Author

I see some duplicate code in jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java and jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngine.java.
Should we take this opportunity to refactor? Is it safe to do so? I was thinking of creating a parent class named AbstractPropertiesBackingEngine or FileBasedBackingEngine...

@jbonofre
Copy link
Member

@stataru8 as we target that for 4.5.x, I don't have problem if we include a refactoring (especially a cleanup one 😄 ).

@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from b9efb56 to c7947db Compare April 18, 2025 09:52
@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch 2 times, most recently from 3b86039 to 3c20e27 Compare April 19, 2025 13:33
@stataru8
Copy link
Author

Hello again, one more question, should the PR also include changes to the .adoc files?

_g_\:admingroup = group,admin,manager,viewer,ssh

@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from 3c20e27 to ea7e507 Compare May 1, 2025 09:33
table.addRow().addContent(userName, group.getName(), roleName);
}
} else {
table.addRow().addContent(userName, group.getName(), "");
Copy link
Author

Choose a reason for hiding this comment

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

I don't know if this proposal makes sense. I can revert.

Setup: user foo without any groups or roles declared.

Current behaviour

karaf@trun()> jaas:group-add foo g1
karaf@trun()> jaas:update
karaf@trun()> jaas:realm-manage --realm karaf --module org.apache.karaf.jaas.modules.properties.PropertiesLoginModule
karaf@trun()> jaas:user-list
User Name │ Group      │ Role
──────────┼────────────┼──────────────
foo       │            │

Proposal

karaf@trun()> jaas:group-add foo g1
karaf@trun()> jaas:update
karaf@trun()> jaas:realm-manage --realm karaf --module org.apache.karaf.jaas.modules.properties.PropertiesLoginModule
karaf@trun()> jaas:user-list
User Name │ Group      │ Role
──────────┼────────────┼──────────────
foo       │ g1         │

Proposal - more tests

karaf@trun()> jaas:role-add foo r1
karaf@trun()> jaas:update
karaf@trun()> jaas:realm-manage --realm karaf --module org.apache.karaf.jaas.modules.properties.PropertiesLoginModule
karaf@trun()> jaas:user-list
User Name │ Group      │ Role
──────────┼────────────┼──────────────
foo       │ g1         │
foo       │            │ r1
karaf@trun()> jaas:group-role-add g1 r1
karaf@trun()> jaas:update
karaf@trun()> jaas:realm-manage --realm karaf --module org.apache.karaf.jaas.modules.properties.PropertiesLoginModule
karaf@trun()> jaas:user-list
User Name │ Group      │ Role
──────────┼────────────┼──────────────
foo       │ g1         │ r1

Copy link
Author

Choose a reason for hiding this comment

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

Maybe it makes sense for the last output to be

User Name │ Group      │ Role
──────────┼────────────┼──────────────
foo       │ g1         │ r1
foo       │            │ r1

@stataru8 stataru8 marked this pull request as ready for review May 1, 2025 16:49
@stataru8
Copy link
Author

stataru8 commented May 1, 2025

PR is ready for review again.
Edit: just discovered another small issue, will have to re-test
Edit2: OK, now PR should be good for review, I added the last commit because roles in nested groups are already discoverable

@stataru8 stataru8 marked this pull request as draft May 1, 2025 18:11
…s and roles with the underlying baking engine
@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from fa2ab89 to 7d542e9 Compare May 2, 2025 16:21
@stataru8 stataru8 force-pushed the stataru/fix/KARAF-5014 branch from 7d542e9 to 27b9946 Compare May 2, 2025 17:05
@stataru8 stataru8 marked this pull request as ready for review May 2, 2025 17:44
@mattrpav
Copy link
Contributor

mattrpav commented May 8, 2025

This should be karaf 4.5.x (or higher) and clearly called out in a Release Notes / Migration Guide.

Make a security-related change to the file and presume the extra role 'group' would not be an issue is not a good practice.

@jbonofre
Copy link
Member

jbonofre commented May 8, 2025

I asked the question of breaking change. For now I consider a 4.5.x thing.

@mattrpav
Copy link
Contributor

mattrpav commented Jul 28, 2025

Is the bug here really the JAAS karaf commands / Encryption Support need to handle the 'group' placeholder better?

keys.properties, and ability to support other security providers with a similar file format is useful -- this would allow for sharing of JAAS commands to be able to resolve group/role info for non-local security providers, etc.

For example: LDAP support could be improved to move the group/role mapping out of the LDAP config and simply into a properties file of the same format that maps userDN'groupDN to roles, etc.

I'm trying to understand what the real 'problem' is with the current solution? Perhaps the Karaf JAAS commands simply need to be fixed?

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