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

Pam random cleanups and fixes #155

Merged
merged 16 commits into from
Jan 22, 2024
Merged

Conversation

3v1n0
Copy link
Collaborator

@3v1n0 3v1n0 commented Dec 15, 2023

Some cleanups and fixes as prerequisite of bigger gdm changes

@3v1n0 3v1n0 requested a review from a team as a code owner December 15, 2023 17:58
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2023

Codecov Report

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

Comparison is base (831edac) 82.89% compared to head (d7140e0) 82.56%.

Files Patch % Lines
pam/pam.go 40.62% 16 Missing and 3 partials ⚠️
pam/internal/adapter/authmodeselection.go 0.00% 9 Missing and 1 partial ⚠️
pam/main-cli.go 64.70% 5 Missing and 1 partial ⚠️
pam/internal/adapter/model.go 92.30% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   82.89%   82.56%   -0.34%     
==========================================
  Files          58       58              
  Lines        4800     4828      +28     
==========================================
+ Hits         3979     3986       +7     
- Misses        633      649      +16     
- Partials      188      193       +5     

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

Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Overall, they are fixing and bringing needed fixes to the project. I have few comments though on keeping the code idiomatic and how we avoid introducing the lifecycle in the proto files.

pam/model.go Outdated Show resolved Hide resolved
pam/authmodeselection.go Outdated Show resolved Hide resolved
pam/authmodeselection.go Outdated Show resolved Hide resolved
pam/model.go Outdated Show resolved Hide resolved
@3v1n0 3v1n0 force-pushed the pam-random-cleanups branch 5 times, most recently from 833b2ca to 653aa96 Compare January 11, 2024 19:13
@3v1n0 3v1n0 requested a review from didrocks January 11, 2024 19:13
@3v1n0 3v1n0 force-pushed the pam-random-cleanups branch 6 times, most recently from a03d1a9 to 8396e82 Compare January 13, 2024 20:18
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

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

Nice work, all makes sense to me :) the atomic commits make for an easier review

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.

Looks good to me! Just a minor comment about a missing comment, but it's easily addressable.

pam/pam.go Outdated Show resolved Hide resolved
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.

Nice work!

@3v1n0
Copy link
Collaborator Author

3v1n0 commented Jan 15, 2024

I'll wait merging this until #173 decision on package name is finalized.

@3v1n0 3v1n0 force-pushed the pam-random-cleanups branch 3 times, most recently from a11594b to 572f2a0 Compare January 15, 2024 17:07
@3v1n0
Copy link
Collaborator Author

3v1n0 commented Jan 15, 2024

Ok rebased on main.

@didrocks this is ready too from my POV, so feel free to merge if you're fine with it too.

Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Here we go. I’m surprised by the changes in golden files which make me think that the diff in the previous PR wasn’t really looked at. I suggest a double look at the "weird cases" I am currently spotting now.

Also, ensuring that we don’t stutter the error to the user is important. That could be only the CLI text rendering, but please double check those.

Then, the rest are minor small changes.

pam/internal/adapter/pam.proto Outdated Show resolved Hide resolved
pam/main-cli.go Outdated Show resolved Hide resolved
pam/pam.go Outdated Show resolved Hide resolved
pam/pam.go Outdated Show resolved Hide resolved
@3v1n0
Copy link
Collaborator Author

3v1n0 commented Jan 17, 2024

I've also added an extra change to introduce adapter.PamClientType, as I'd need to extend that, plus I had to move (again) the pam.proto file to another pam/internal/proto package to avoid a circular dependency that could raise otherwise in future:

  • The structs defined by such proto are used by the model but also by the gdm package (it's already the case in main).
  • So when including gdm in model... boom!

Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Answered the comments + a new one in the newly introduced code.

pam/pam.go Show resolved Hide resolved
…om the UI

This is not happening right now since our UI implements some modes, but
it may happen that a remote implementation (gdm) may not.
…ilable

We should not ignore the fact that no authentication modes are available
so return a proper error instead of ignoring it.
This was supposed to be a logic or, not a bitwise one.

As per this, update the golden files to reflect the expected output.
Mimic the behavior that we have with authentication
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Ok, there is the initial state that should be working and not unknown that is remaining to be fixed as discussed.

The rest of the changes looks good. Thanks for making the golden files way easier to read!

In some implementations (e.g. gdm) we need to communicate with the UI
the stage that is expected to be shown. Since we have the same already
defined in the PAM module for local implementation, we can just expose
the same values in a newly defined pam protocol so that can be reused by
gdm too.

As per this, add a Stage enum type to the protocol and reuse these
values inside the pam module.

We just need to also define an undefined state to have an invalid value.
Avoid repeating the same operations multiple times or handling change
stage messages when not needed.

To make this to work we need to ensure that the initial state is not
marked as user selection. We do not define a new stage value since it
would be unused, and that's good that is not.
This makes the output of the golden files clearer and it makes explicit
the Pam status code that is returned.
Print it once authenticated so that we are sure that the expected user
is passed to the pam stack.
Our model may handle multiple pam client types, and depending on them it
could behave differently, so indicate this through an enum instead of a
simple boolean, since we will have multiple types not just interactive
and non interactive clients.

As for now, just return an error if a non-interactive client is used,
since that's the only thing we support right now.
If an error occurred we need to also return the model, otherwise we'd
end up on a invalid memory address or nil pointer dereference in
bubbletea
@3v1n0
Copy link
Collaborator Author

3v1n0 commented Jan 22, 2024

Thanks @didrocks, rebased and squashed, so feel free to merge now.

@didrocks didrocks merged commit 1112253 into ubuntu:main Jan 22, 2024
4 checks passed
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.

5 participants