-
Notifications
You must be signed in to change notification settings - Fork 129
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(Session cookie support for Auth to Admin Server) #545
Conversation
utils/cookiejarparser.go
Outdated
@@ -0,0 +1,114 @@ | |||
package utils | |||
|
|||
// Code from https://github.com/ssgelm/cookiejarparser under MIT License |
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.
Any reason we are copying this code rather than using it as a dependency?
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.
Seemed very small and not sure if it would be maintained. So felt it is better to copy instead of import
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 we are not modifying any part of the dependency code, let's introduce the dependency.
Copying code in here is a new pattern and I'd recommend not deviating from current practices (other and future maintainers will wonder why this exception).
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.
Done
utils/types.go
Outdated
@@ -94,6 +94,11 @@ type KongClientConfig struct { | |||
HTTPClient *http.Client | |||
|
|||
Timeout int | |||
|
|||
SessionFilePath string |
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.
SessionFilePath string | |
CookieJarPath string |
Cookies can do more than sessions.
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.
Done
cmd/root.go
Outdated
@@ -123,6 +123,13 @@ func init() { | |||
viper.BindPFlag("skip-workspace-crud", | |||
rootCmd.PersistentFlags().Lookup("skip-workspace-crud")) | |||
|
|||
// Support for Session Cookie | |||
rootCmd.PersistentFlags().String("kong-session-cookie-path", "", |
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.
rootCmd.PersistentFlags().String("kong-session-cookie-path", "", | |
rootCmd.PersistentFlags().String("kong-cookie-jar-path", "", |
Let's avoid the word 'session' in here since the functionality is more generic than that.
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.
Done
cmd/root.go
Outdated
// Support for Session Cookie | ||
rootCmd.PersistentFlags().String("kong-session-cookie-path", "", | ||
"Absolute path for the session-cookie file for auth with Admin Server.\n"+ | ||
"You may also need to pass in as header the User-Agent that was used to create the session.") |
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.
Update this text as well.
Please mention the format of the cookie file path (netscape cookie format I think).
Question: what happens if the user-agent is not specified?
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.
It gives a 401. This took me a while to figure out. Looks like Kong associates sessions and user-agent. My guess is that when Kong sees a different user agent, it assumes that the session was hijacked and sends a 401
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.
Yikes. That may introduce additional friction that we can't solve for. Let's ship this and come back here if this PR doesn't achieve the desired outcome for our customers.
utils/types.go
Outdated
SessionFilePath string | ||
|
||
// Whether to initialize the Http client with a cookie jar or not | ||
ISSessionClient bool |
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 this required? Why not check if the SessionFilePath != ""?
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.
Yeah, I could do that, felt that the boolean could satisfy multiple flags, so left it. I can remove it
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.
Done
Codecov Report
@@ Coverage Diff @@
## main #545 +/- ##
==========================================
- Coverage 51.98% 51.96% -0.02%
==========================================
Files 73 73
Lines 7714 7730 +16
==========================================
+ Hits 4010 4017 +7
- Misses 3354 3363 +9
Partials 350 350
Continue to review full report at Codecov.
|
cmd/root.go
Outdated
@@ -123,6 +123,13 @@ func init() { | |||
viper.BindPFlag("skip-workspace-crud", | |||
rootCmd.PersistentFlags().Lookup("skip-workspace-crud")) | |||
|
|||
// Support for Session Cookie | |||
rootCmd.PersistentFlags().String("kong-cookie-jar-path", "", | |||
"Absolute path for cookie-jar file in Netscape file format for auth with Admin Server.\n"+ |
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.
"Absolute path for cookie-jar file in Netscape file format for auth with Admin Server.\n"+ | |
"Absolute path to a cookie-jar file in the Netscape cookie format for auth with Admin Server.\n"+ |
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.
done
utils/types.go
Outdated
if opt.CookieJarPath != "" { | ||
jar, err := LoadCookieJarFile(opt.CookieJarPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize cookie-jar:%w", err) |
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.
return nil, fmt.Errorf("failed to initialize cookie-jar:%w", err) | |
return nil, fmt.Errorf("failed to initialize cookie-jar: %w", err) |
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.
done
Adding support for session cookie file in Netscape cookie file format to use in cookie jar. Depending on the User Agent that was used to generate the cookie file, the User-Agent header in deck may need to be over-ridden