-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix "Login Failed: Unable to find a valid CSRF token. Please try again." #1717
Conversation
1c679b2
to
0d74d66
Compare
Apps Proxy Kubernetes Diff [CI]Between Expand--- /tmp/artifacts/test-k8s-state.old.json.processed.kv 2024-04-22 20:56:48.384645664 +0000
+++ /tmp/artifacts/test-k8s-state.new.json.processed.kv 2024-04-22 20:56:48.504646690 +0000
@@ -105 +105 @@
-<Deployment/apps-proxy>.spec.template.spec.containers[0].image = "docker.io/keboola/apps-proxy:9c1d694";
+<Deployment/apps-proxy>.spec.template.spec.containers[0].image = "docker.io/keboola/apps-proxy:0d74d66";
@@ -461,3 +461,3 @@
-<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:9c1d694";
-<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:9c1d694";
-<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:9c1d694";
+<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:0d74d66";
+<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:0d74d66";
+<Pod/apps-proxy-<hash>>.spec.containers[0].image = "docker.io/keboola/apps-proxy:0d74d66";
@@ -879 +879 @@
-<ReplicaSet/apps-proxy-<hash>>.spec.template.spec.containers[0].image = "docker.io/keboola/apps-proxy:9c1d694";
+<ReplicaSet/apps-proxy-<hash>>.spec.template.spec.containers[0].image = "docker.io/keboola/apps-proxy:0d74d66";
(see artifacts in the Github Action for more information) |
@@ -0,0 +1,3 @@ | |||
package config | |||
|
|||
const InternalPrefix = "/_proxy" |
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.
Now it is only one place where /_proxy
prefix is defined.
// CookieDomain without port for cookies. | ||
func (c AppConfig) CookieDomain(publicURL *url.URL) string { | ||
return c.Domain() + "." + publicURL.Hostname() | ||
} | ||
|
||
// BaseURL of the app. | ||
func (c AppConfig) BaseURL(publicURL *url.URL) *url.URL { | ||
return &url.URL{ | ||
Scheme: publicURL.Scheme, | ||
Host: c.Domain() + "." + publicURL.Host, | ||
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.
New helper methods.
@@ -21,6 +23,7 @@ import ( | |||
type appHandler struct { | |||
manager *Manager | |||
app api.AppConfig | |||
baseURL *url.URL |
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.
Added baseURL
field, so it is cached.
// Redirect request to canonical host to match cookies domain | ||
if req.Host != h.baseURL.Host { | ||
w.Header().Set("Location", h.baseURL.ResolveReference(&url.URL{Path: req.URL.Path}).String()) | ||
w.WriteHeader(http.StatusPermanentRedirect) | ||
return 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.
{ | ||
name: "redirect-to-canonical-host", | ||
run: func(t *testing.T, client *http.Client, m []*mockoidc.MockOIDC, appServer *testutil.AppServer, service *testutil.DataAppsAPI, dnsServer *dnsmock.Server) { | ||
// Redirect to the canonical URL (match cookies domain) | ||
request, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://foo-bar-123.hub.keboola.local/some/data/app/url?foo=bar", nil) | ||
require.NoError(t, err) | ||
response, err := client.Do(request) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusPermanentRedirect, response.StatusCode) | ||
location := response.Header.Get("Location") | ||
assert.Equal(t, location, "https://public-123.hub.keboola.local/some/data/app/url") | ||
}, | ||
expectedNotifications: map[string]int{}, | ||
expectedWakeUps: map[string]int{}, | ||
}, |
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.
New test.
loggerWriter := logging.NewLoggerWriter(d.Logger(), "info") | ||
loggerWriter := logging.NewLoggerWriter(d.Logger().WithComponent("oauth2proxy"), "info") | ||
oautproxylogger.SetOutput(loggerWriter) |
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.
// Get style.css | ||
rec = httptest.NewRecorder() | ||
req = httptest.NewRequest("GET", "https://hub.keboola.local/_proxy/assets/style.css", nil) | ||
handler.ServeHTTP(rec, req) | ||
require.Equal(t, http.StatusOK, rec.Code) | ||
assert.NotEmpty(t, rec.Body.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.
Petr, you could have deleted it yourself when you added new assets.
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 didn't remove that, because I wanted to have some test for an asset that exists. Yes, I could use favicon.ico instead style.css
@@ -193,38 +193,6 @@ func TestAppProxyHandler(t *testing.T) { | |||
} | |||
], | |||
}, | |||
{ |
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.
Removed style.css
request.
ctx, span := l.telemetry.Tracer().Start(ctx, "keboola.go.apps-proxy.appconfig.Loader.GetConfig") | ||
defer span.End(&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.
New span.
args_bin = [] | ||
args_bin = ["--sandboxes-api-url", "http://localhost:1234", "--sandboxes-api-token", "my-token", "--api-public-url", "http://localhost:8000"] | ||
cmd = "make build-apps-proxy" |
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.
Minimal config to run the proxy locally (without any sandboxes api).
<h1> | ||
{{.App.IDAndName}} | ||
</h1> | ||
<h1>Application {{.App.IDAndName}}</h1> | ||
{{ if .App.ProjectID }} <h2>Project {{.App.ProjectID}}</h2>{{ end }} | ||
{{ end }} | ||
</header> | ||
<main> |
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.
Jira: https://keboola.atlassian.net/browse/PSGO-553
Changes: