-
Notifications
You must be signed in to change notification settings - Fork 104
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
Adds implementation for Auth Server Using Goth #315
Conversation
api/cmd/auth/auth.go
Outdated
key := "" // Replace with your SESSION_SECRET or similar | ||
maxAge := 86400 * 30 // 30 days | ||
isProd := false // Set to true when serving over https | ||
|
||
store := sessions.NewCookieStore([]byte(key)) | ||
store.MaxAge(maxAge) | ||
store.Options.Path = "/" | ||
store.Options.HttpOnly = true // HttpOnly should always be enabled | ||
store.Options.Secure = isProd | ||
|
||
gothic.Store = store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now we are adding this to avoid the comment from the goth library while running the auth server
ce9cbf3
to
468ae1e
Compare
api/cmd/auth/auth.go
Outdated
|
||
logger.Info(fmt.Sprintf("listening on %s", AUTH_BASE_URL)) | ||
|
||
logger.Fatal(http.ListenAndServe(":4200", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having this as separate dir, does it means it will have a separate image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is possible we should try to run this on different port but with the existing api server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
running this server as a thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maintaining different images not a good idea if we can package in one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it will have a separate image
I think the ultimate aim of having a separate auth server is it's reusability and transparency from api server, running it in existing api server with different port might break this. Also if someone just wants the auth server, but building the image would also have the api in it, which would be of no use for the user
Also do you mean adding it in existing server means designing the api endpoints for auth using GOA,
If yes then for auth we have used Gorilla mux, the reason behind using gorilla was Goth library which we are using for authentication requires http.ResponseWriter and http.Request, which were not able to access using GOA
api/pkg/auth/auth.go
Outdated
|
||
var UI_URL = os.Getenv("UI_URL") | ||
params := req.URL.Query() | ||
if err = r.insertData(ghUser, params.Get("code")); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is code
available with all provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the primary info across all platform? mail id could be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is code available with all provider?
yes
what is the primary info across all platform? mail id could be
Yes we can have mail as primary for all the platforms but saying that we need to keep in mind for the users who are already logged in before we add that
468ae1e
to
0c9b913
Compare
5b32506
to
715b24b
Compare
bda882e
to
a9491cd
Compare
1467005
to
b03b080
Compare
f581371
to
6b82ad9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple of comments else looks fine from my side.
go func() { | ||
// start the web server on port and accept requests | ||
logger.Infof("AUTH server listening on port %q", authPort) | ||
logger.Fatal(http.ListenAndServe(":"+authPort, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes if auth server returns error at some point then the api server would still be in running state.
2021-11-15T20:44:36.247+0530 INFO log/logger.go:33 HTTP Request {"service": "http", "id": "aq_UyPLp", "status": 200, "bytes": 611, "time": "1.071069ms"}
2021-11-15T20:44:36.247+0530 ERROR service/auth.go:143 hello world error {"service": "auth"}
github.com/tektoncd/hub/api/pkg/auth/service.(*service).HubAuthenticate
/home/vj/go/src/github.com/tektoncd/hub/api/pkg/auth/service/auth.go:143
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2049
github.com/gorilla/mux.(*Router).ServeHTTP
/home/vj/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210
github.com/gorilla/handlers.(*cors).ServeHTTP
/home/vj/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/cors.go:138
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go:2867
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go:1932
2021-11-15T20:44:36.248+0530 INFO log/logger.go:33 HTTP Request {"service": "http", "id": "FCXdNplQ", "req": "GET /v1/catalogs", "from": "::1"}
2021-11-15T20:44:36.248+0530 INFO log/logger.go:33 HTTP Request {"service": "http", "id": "kYJJ0u5Q", "req": "GET /resources", "from": "::1"}
2021-11-15T20:44:36.249+0530 INFO app/gorm_logger.go:85 /home/vj/go/src/github.com/tektoncd/hub/api/v1/service/catalog/catalog.go:46
[1.664ms] [rows:1] SELECT * FROM "catalogs" WHERE "catalogs"."deleted_at" IS NULL ORDER BY id {"service": "catalog", "id": "FCXdNplQ"}
If you see the above case I manually logged the error randomly in one of the auth functions, the API server still worked
I think that should be the case only right, I mean if ui is showing the error for auth then api server should be still running right ??
api/pkg/auth/base.go
Outdated
|
||
key := "" // Replace with your SESSION_SECRET or similar | ||
maxAge := 86400 * 30 // 30 days | ||
isProd := false // Set to true when serving over https |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should configure this on the basis of env variable ENVIRONMENT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about when we read providers from env ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isProd := false
we will be serving over https right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we adding an env in config? How we are changing it?
api/pkg/auth/service/auth.go
Outdated
// Provides a list of git provider present in auth server | ||
func List(res http.ResponseWriter, req *http.Request) { | ||
providers := authApp.ProviderList{ | ||
Data: []authApp.Provider{ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a TODO
comment over here to configure these values dynamically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we want to add a new provide let say google? will there be code change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the logic for adding the provider for auth
/cc @piyush-garg @sm43 |
api/pkg/service/admin/admin.go
Outdated
@@ -24,13 +24,13 @@ import ( | |||
"github.com/tektoncd/hub/api/pkg/app" | |||
"github.com/tektoncd/hub/api/pkg/db/initializer" | |||
"github.com/tektoncd/hub/api/pkg/db/model" | |||
"github.com/tektoncd/hub/api/pkg/service/auth" | |||
"github.com/tektoncd/hub/api/pkg/service/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service named utils
😅 ?
authSvc := auth.New(api) | ||
|
||
// Return name and status of the services | ||
r.HandleFunc("/", auth.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we have !
- Removes the design for auth - Updates the test for admin, catalog, rating, user Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
4ff850d
to
324c971
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
324c971
to
596c143
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
596c143
to
5ec7359
Compare
/lgtm |
/approve |
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sm43 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
make api-check
make ui-check
See the contribution guide for more details.