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

Authentication cleanup #1403

Merged
merged 8 commits into from
May 3, 2022
Merged

Authentication cleanup #1403

merged 8 commits into from
May 3, 2022

Conversation

enrichman
Copy link
Member

@enrichman enrichman commented Apr 28, 2022

Note

This PR needs the new users from this helm-charts PR

It would work also without it, but I guess it's better to merge that before.


This is a cleanup/refactor made before the authorization spike. It should not change the behaviour of the API.

The main changes are in the internal/auth/auth.go.

Some unused structs and func were removed:

  • PasswordAuth
  • HashBcrypt()
  • RandomPasswordAuth()

Then a new auth.User struct was added, and all the methods were adapted accordingly. This struct will match an Epinio User (or account maybe?), and it will be the one that will be returned from the different functions and package (I don't think we should move too much around with secrets and the kubernetes internal, generally speaking). This struct will be also the one that is going to be keep around in the context and session.

// User is a struct containing all the information of an Epinio User
type User struct {
	Username   string
	Password   string
	CreatedAt  time.Time
	Role       string
	Namespaces []string
}

So a NewUserFromSecret func was added, and the other GetUserAccounts, GetFirstUserAccount and GetUserSecretsByAge were updated accordingly.

It's probably easier to have a look at the result: https://github.com/epinio/epinio/blob/auth-cleanup/internal/auth/auth.go

Other important changes are in the internal/cli/server/server.go, so that now we are going to persist the auth.User in the session and context. I've also removed the BasicAuth header decoding, that can be done with just

username, password, ok = ctx.Request.BasicAuth()

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2022

Codecov Report

Merging #1403 (26afc0f) into main (c097bd4) will not change coverage.
The diff coverage is 0.00%.

@@          Coverage Diff          @@
##            main   #1403   +/-   ##
=====================================
  Coverage   7.75%   7.75%           
=====================================
  Files         69      69           
  Lines       7273    7273           
=====================================
  Hits         564     564           
  Misses      6669    6669           
  Partials      40      40           
Flag Coverage Δ
unittests 7.75% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/api/v1/application/create.go 0.00% <0.00%> (ø)
internal/api/v1/application/deploy.go 0.00% <0.00%> (ø)
internal/api/v1/application/importgit.go 0.00% <0.00%> (ø)
internal/api/v1/application/restart.go 0.00% <0.00%> (ø)
internal/api/v1/application/stage.go 0.00% <0.00%> (ø)
internal/api/v1/application/update.go 0.00% <0.00%> (ø)
internal/api/v1/application/upload.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c097bd4...26afc0f. Read the comment docs.

@enrichman enrichman self-assigned this Apr 29, 2022
@enrichman enrichman marked this pull request as ready for review April 29, 2022 10:53
@enrichman enrichman requested a review from a team as a code owner April 29, 2022 10:53
andreas-kupries
andreas-kupries previously approved these changes May 2, 2022
Copy link
Contributor

@andreas-kupries andreas-kupries left a comment

Choose a reason for hiding this comment

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

Look ok.

Copy link
Contributor

@andreas-kupries andreas-kupries left a comment

Choose a reason for hiding this comment

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

looks ok.

wondering however if our tests actually check the various code paths of auth, i.e. try to trigger the various auth failures.

@enrichman
Copy link
Member Author

enrichman commented May 3, 2022

Thanks @andreas-kupries! Actually yes, there are few tests that are checking the basic auth and session authentication (they failed me for a couple of things, so it was interesting to see that the auth is working fine!).

In the next PR I will add a couple of tests to check also the authorization.

@enrichman enrichman merged commit e914dfe into main May 3, 2022
@enrichman enrichman deleted the auth-cleanup branch May 3, 2022 07:41
@@ -18,13 +19,17 @@ type UserKey struct{}
type LoggerKey struct{}

// WithUser adds the user name to the context
func WithUser(ctx context.Context, val string) context.Context {
func WithUser(ctx context.Context, val auth.User) context.Context {
return context.WithValue(ctx, UserKey{}, val)
}

// User returns the user name from the context
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is now outdated (sorry for the post-merge review)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good catch, thanks. I will update it in the next PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants