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

chore: override codersdk.SessionTokenCookie in develop.sh#18991

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
johnstcn merged 7 commits intomainfromcj/dev-session-token-cookie-prefix
Jul 23, 2025

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedJul 22, 2025
edited
Loading

Enables viewing the Coder UI proxied by Coder.
Exposes an environment variableCODER_DEV_SESSION_TOKEN_COOKIE_PREFIX which allows adding a prefix to the name of the session token cookie. This only works for development builds.

$ CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX=dev ./scripts/develop.sh
$ curl 'https://3000--dev--nonix--cian--apps.dev.coder.com/api/v2/users/me' -H "Cookie: dev_coder_session_token=$(cat .coderv2/session)"{"id":"fddc81ff-7924-4628-a146-b799d2fb81b4","username":"admin","name":"Admin User","email":"admin@coder.com","created_at":"2025-07-22T13:39:16.670833+01:00","updated_at":"2025-07-22T17:49:38.313364+01:00","last_seen_at":"2025-07-22T16:49:38.313364Z","status":"active","login_type":"password","organization_ids":["c56e87ca-effa-43a6-a464-f25840a47483"],"roles":[{"name":"owner","display_name":"Owner"}]}

EDIT: I tried an alternative implementation instead using-ldflags -X that removes the need for most changes in codersdk.

@johnstcnjohnstcn self-assigned thisJul 22, 2025
@johnstcnjohnstcn changed the titleCj/dev session token cookie prefixchore: add CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX in development modeJul 22, 2025
},
},
allowedHosts:[".coder"],
allowedHosts:[".coder",".dev.coder.com"],
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

review: also updatedallowedHosts for dev URLs.


cdroot
DEBUG_DELVE="${debug}" start_cmd API"""${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url"${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode"$@"
DEBUG_DELVE="${debug}"CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX="${CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX}"start_cmd API"""${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url"${CODER_DEV_ACCESS_URL}" --dangerous-allow-cors-requests=true --enable-terraform-debug-mode"$@"
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

review: I'm setting the prefix todev_ by default indevelop.sh.

Copy link
Member

@code-ashercode-asher 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.

I tried it out and it is glorious we can run Coder over dev URLs now 🎉

Too bad we cannot get rid ofcodersdk.SessionTokenCookie or set it dynamically (at least not as a const), but what can ya do.

Comment on lines 109 to 116
funcGetSessionTokenCookie()string {
ifbuildinfo.IsDev() {
ifpfx,found:=os.LookupEnv("CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX");found&&pfx!="" {
returnpfx+"_"+SessionTokenCookie
}
}
returnSessionTokenCookie
}
Copy link
Member

Choose a reason for hiding this comment

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

ShouldSessionTokenCookie just be avar? And a function updates the var?

At the very least,SessionTokenCookie should probably not be exported. Just this function

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah I was thinking of doing that but didn't want to make a breaking API change.
But you got me thinking... what do we do forbuildinfo.tag?
If I changeSessionTokenCookie to avar we can just do the-ldflags -X trick and not have to change anything else :)

@bpmct
Copy link
Member

woooooooooo!!!!

Comment on lines -2703 to -2705
// From codersdk/client.go
exportconstSessionTokenCookie="coder_session_token";

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This isn't intentional; I need to figure out how to keep this around.
@Emyrk think it's possible to modify this behaviour inapitypings?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

For now I'm manually vendoring this intoapi.ts.

Comment on lines +153 to +158
if [["$develop_in_coder"== 1 ]];then
echo"INFO : Overriding codersdk.SessionTokenCookie as we are developing inside a Coder workspace."
ldflags+=(
-X"'github.com/coder/coder/v2/codersdk.SessionTokenCookie=dev_coder_session_token'"
)
fi
Copy link
MemberAuthor

@johnstcnjohnstcnJul 22, 2025
edited
Loading

Choose a reason for hiding this comment

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

I decided to try this way instead. It's a little more involved but requires less code changes incodersdk. I can remove the echo message if it's annoying.

code-asher reacted with heart emoji
@johnstcnjohnstcn changed the titlechore: add CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX in development modechore: override codersdk.SessionTokenCookie in develop.shJul 22, 2025
Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

Excellent!!

Comment on lines +110 to +115
/**
* Originally from codersdk/client.go.
* The below declaration is required to stop Knip from complaining.
*@public
*/
exportconstSessionTokenCookie="coder_session_token";
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

TIL

@johnstcnjohnstcn merged commitbb83071 intomainJul 23, 2025
65 of 71 checks passed
@johnstcnjohnstcn deleted the cj/dev-session-token-cookie-prefix branchJuly 23, 2025 11:48
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 23, 2025
CODER_DELVE_DEBUG_BIN=$(realpath"./build/coder_debug_${GOOS}_${GOARCH}")
popd

if [-n"${CODER_AGENT_URL}" ];then
Copy link
Member

Choose a reason for hiding this comment

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

We could also check ifCODER=true. That's what I do in my dotfiles.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I forgot about that one!

Copy link
Member

@code-ashercode-asherJul 24, 2025
edited
Loading

Choose a reason for hiding this comment

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

Should also maybe be"${CODER_AGENT_URL:-}" in case the env var is not set, on account of theset -u.

Copy link
MemberAuthor

@johnstcnjohnstcnJul 25, 2025
edited
Loading

Choose a reason for hiding this comment

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

I did that here above (L13) but missed it indevelop.sh. Will push a separate PR 👍

#19043

Copy link
Member

Choose a reason for hiding this comment

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

Oh right oops! I got lost in what script I was looking at lol

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@EmyrkEmyrkEmyrk left review comments

@matifalimatifalimatifali left review comments

@code-ashercode-ashercode-asher approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@johnstcn@bpmct@Emyrk@matifali@mtojek@code-asher

[8]ページ先頭

©2009-2025 Movatter.jp