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

feat: add local groups support #122

Merged
merged 15 commits into from
Nov 30, 2023
Merged

feat: add local groups support #122

merged 15 commits into from
Nov 30, 2023

Conversation

didrocks
Copy link
Member

This PR adds local group support by adding and update the local group list so that any remotely created user can be part of local groups.

For this, the broker specificies groups with only the group name and no ugid. Then, the group is considered local and the user added to it. If the local group doesn’t exist, then the group is simply ignored (only an info is triggered).
We are using gpasswd which doesn’t enforce the user to be in /etc/passwd.

UDENG-1444

@codecov-commenter
Copy link

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (2a2b732) 87.36% compared to head (14d905f) 87.65%.

Files Patch % Lines
internal/users/users.go 93.25% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #122      +/-   ##
==========================================
+ Coverage   87.36%   87.65%   +0.28%     
==========================================
  Files          29       30       +1     
  Lines        2114     2212      +98     
==========================================
+ Hits         1847     1939      +92     
- Misses        205      209       +4     
- Partials       62       64       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@didrocks
Copy link
Member Author

FYI, this created 2 more cards, for local group purge (on invalid cache and when user is purged) and also empty groups/empty data policy:
UDENG-1864 and UDENG-1865.

@didrocks didrocks changed the title Add local groups support feat: add local groups support Nov 30, 2023
@didrocks didrocks marked this pull request as ready for review November 30, 2023 10:23
@didrocks didrocks requested a review from a team as a code owner November 30, 2023 10:23
Copy link
Member

@denisonbarbosa denisonbarbosa left a comment

Choose a reason for hiding this comment

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

A few comments, but everything looks great!

internal/cache/db_test.go Outdated Show resolved Hide resolved
internal/users/users.go Outdated Show resolved Hide resolved
internal/users/users.go Outdated Show resolved Hide resolved
internal/users/users.go Outdated Show resolved Hide resolved
internal/users/users.go Show resolved Hide resolved
internal/users/users.go Outdated Show resolved Hide resolved
This is our way to communicate that this is a system/local group.
Those are now a pointer as they can be nil to signify this is az local group.
This test ensure that all groups without gid are filtered and not stored
in the cache.
@didrocks
Copy link
Member Author

and here we go! In addition to the fixes, as discussed, there are 2 changes I wanted to do:

  • assert on gpasswd being called or not by the presence of the file. Check the commit message itself, I think we should at some point having it as a golden file helper, but we need to mixing some sorting optional capability.
  • add one line missing coverage that we can cover.
  • change the use case for triggering an error in the service, not relying on an invalid group file.

Copy link
Member

@denisonbarbosa denisonbarbosa left a comment

Choose a reason for hiding this comment

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

LGTM!

This package will be used to add/remove users from local groups as this
information is not part of the cache.
Adapt imports and tests for the new struct location.
Parse local group files and sync current authd user groups with the list
provided by the broker.
Add the user to sudo in the example broker to articulate the local goup
functionality.
Add tests for local group supports. Mock gpasswd binary to achieve this
as we can’t change the prefix but only can chroot which requires running
tests as root.
Commit the golden files, being the gpasswd output when called with given
arguments and not returning an error.
We will need it in other places for integration tests. Make it then
exportable on its own package, using the linkname to change set
global defaults as we don’t want to leak the With* tests helpers
throughout the stack.

However, the tests using those won’t be able to be run in parallel.
Allow the broker mock to return multiple groups, including local ones,
still producing valid JSON.
Those tests needs to reuse the helper to change the default and thus,
we can’t run run those tests in parallel.
Now, we are going to not pre-create gpasswd output file but only create
it once the mock is called. That allows us to separate it being called
or not.
This functionality will be better in testutils, but it needs to all
post-treatment for the file to be idemnpotent and I didn't find an
elegant way for it.

Then, we can replace the LoadWithUpdateFromGolden with something
treating files (or maybe take back the tree comparison).
This suppresses all gpasswd.output files for tests not calling it.
Do not rely on the file content itself, but on its existence.
@didrocks didrocks merged commit 75084c6 into main Nov 30, 2023
5 checks passed
@didrocks didrocks deleted the add_system_groups branch November 30, 2023 14:59
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