Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: use JWT ticket to avoid DB queries on apps#6148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deansheather merged 18 commits intomainfromdean/app-tickets
Mar 7, 2023

Conversation

deansheather
Copy link
Member

@deansheatherdeansheather commentedFeb 10, 2023
edited
Loading

Issues a JWT ticket on the first request with a short expiry that contains details about which workspace/agent/app combo the ticket is valid for. This lets us avoid the ~5 DB queries on each app request, and reduces them to ~5 per minute.

Large dev server apps will often make hundreds of requests to get bundles, which strains the database. The goal of this PR is to alleviate DB strain in large deployments that heavily lean on workspace apps.

Refactors the workspace app auth logic into workspaceappsauth.go.

Disables usingme as the username in workspace app requests. For subdomains we never used this, but it's possible that it has been used for path apps, so path apps will redirect to contain the correct username.

TODO:

  • Generate a secret key on first start, store in DB, cache in memory
  • JWT signing and parsing
  • Path-cookies for path apps
  • New workspace auth internal tests
  • Test for path appme username redirect
  • Test for no port proxying allowed in paths
  • TODOs in the code
  • Fix bugs that break existing tests

Closes#6361

WIPIssue a JWT ticket on the first request with a short expiry thatcontains details about which workspace/agent/app combo the ticket isvalid for.Refactor the workspace app auth logic into workspaceappsauth.go.
@github-actions
Copy link

This Pull Request is becoming stale. In order to minimize WIP, prevent merge conflicts and keep the tracker readable, I'm going close to this PR in 3 days if there isn't more activity.

@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelFeb 19, 2023
@deansheatherdeansheather removed the staleThis issue is like stale bread. labelFeb 20, 2023
@deansheather
Copy link
MemberAuthor

I've decided to not make the ticket expiry configurable yet until a customer asks us to make it configurable.

@deansheather
Copy link
MemberAuthor

I apologize for the large line count in this PR, the majority of the code is in two filesauth.go andticket.go, and the rest of the changed lines are moved code and tests.

@deansheatherdeansheather marked this pull request as ready for reviewFebruary 28, 2023 19:41
@deansheatherdeansheather requested a review fromsreyaMarch 2, 2023 17:25
Copy link
Member

@mafredrimafredri left a comment
edited
Loading

Choose a reason for hiding this comment

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

Given the size of this PR, another pair of eyes on the auth stuff might be good, but other than the minor things I commented on, this looks OK to me!

if _, ok := tx.fakeQuerier.locks[id]; ok {
return false, nil
}
tx.fakeQuerier.locks[id] = struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Should this be protected or use sync.Map? Otherwise we may have concurrent map read/writes between goroutines.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I wouldn't expect a transaction to be used concurrently from two places at once (and I don't think that even works anyways) but I can add this

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

For example, the lock on the underlying data struct is replaced with a noop lock in a tx, so concurrent database read/writes may panic

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I've actually decided against this for the above reason.

httpmw.RedirectToLogin(rw, r, httpmw.SignedOutErrorMessage)
mw.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
user := httpmw.UserParam(r)
http.Redirect(rw, r, strings.Replace(r.URL.Path, "@me", "@"+user.Username, 1), http.StatusTemporaryRedirect)
Copy link
Member

Choose a reason for hiding this comment

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

If we will never support@me for these apps, we could consider using permanent redirect perceived performance gain. Temporary is more future proof though.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Problem with permanent redirect is if you login to a different user and have a similar workspace it'll always hit the wrong one.

Copy link
Collaborator

@sreyasreya left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@deansheatherdeansheather requested a review fromsreyaMarch 7, 2023 18:26
@deansheatherdeansheatherenabled auto-merge (squash)March 7, 2023 19:08
@deansheatherdeansheather merged commit1bdd2ab intomainMar 7, 2023
@deansheatherdeansheather deleted the dean/app-tickets branchMarch 7, 2023 19:38
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 7, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

@sreyasreyasreya approved these changes

@kylecarbskylecarbsAwaiting requested review from kylecarbs

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Use JWT signatures for app requests to avoid db load on request-heavy apps
3 participants
@deansheather@mafredri@sreya

[8]ページ先頭

©2009-2025 Movatter.jp