- Notifications
You must be signed in to change notification settings - Fork1k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
}, | ||
}, | ||
allowedHosts:[".coder"], | ||
allowedHosts:[".coder",".dev.coder.com"], |
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.
review: also updatedallowedHosts
for dev URLs.
scripts/develop.sh Outdated
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"$@" |
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.
review: I'm setting the prefix todev_
by default indevelop.sh
.
code-asher left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 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.
codersdk/client.go Outdated
funcGetSessionTokenCookie()string { | ||
ifbuildinfo.IsDev() { | ||
ifpfx,found:=os.LookupEnv("CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX");found&&pfx!="" { | ||
returnpfx+"_"+SessionTokenCookie | ||
} | ||
} | ||
returnSessionTokenCookie | ||
} |
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.
ShouldSessionTokenCookie
just be avar
? And a function updates the var?
At the very least,SessionTokenCookie
should probably not be exported. Just this function
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 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 :)
woooooooooo!!!! |
// From codersdk/client.go | ||
exportconstSessionTokenCookie="coder_session_token"; | ||
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.
This isn't intentional; I need to figure out how to keep this around.
@Emyrk think it's possible to modify this behaviour inapitypings
?
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 I'm manually vendoring this intoapi.ts
.
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 |
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 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.
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.
Excellent!!
/** | ||
* Originally from codersdk/client.go. | ||
* The below declaration is required to stop Knip from complaining. | ||
*@public | ||
*/ | ||
exportconstSessionTokenCookie="coder_session_token"; |
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.
TIL
bb83071
intomainUh oh!
There was an error while loading.Please reload this page.
CODER_DELVE_DEBUG_BIN=$(realpath"./build/coder_debug_${GOOS}_${GOARCH}") | ||
popd | ||
if [-n"${CODER_AGENT_URL}" ];then |
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.
We could also check ifCODER=true
. That's what I do in my dotfiles.
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 forgot about that one!
code-asherJul 24, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 also maybe be"${CODER_AGENT_URL:-}"
in case the env var is not set, on account of theset -u
.
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 did that here above (L13) but missed it indevelop.sh
. Will push a separate PR 👍
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.
Oh right oops! I got lost in what script I was looking at lol
Uh oh!
There was an error while loading.Please reload this page.
Enables viewing the Coder UI proxied by Coder.
Exposes an environment variable
CODER_DEV_SESSION_TOKEN_COOKIE_PREFIX
which allows adding a prefix to the name of the session token cookie. This only works for development builds.EDIT: I tried an alternative implementation instead using
-ldflags -X
that removes the need for most changes in codersdk.