Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
// These cookies are Coder-specific. If a new one is added or changed, the name
// shouldn't be likely to conflict with any user-application set cookies.
// Be sure to strip additional cookies in httpapi.StripCoderCookies!
// SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in.
// NOTE: This is declared as a var so that we can override it in `develop.sh` if required.
var SessionTokenCookie = "coder_session_token"

const (
// SessionTokenCookie represents the name of the cookie or query parameter the API key is stored in.
SessionTokenCookie = "coder_session_token"
// SessionTokenHeader is the custom header to use for authentication.
SessionTokenHeader = "Coder-Session-Token"
// OAuth2StateCookie is the name of the cookie that stores the oauth2 state.
Expand Down
8 changes: 8 additions & 0 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
dylib=0
windows_resources="${CODER_WINDOWS_RESOURCES:-0}"
debug=0
develop_in_coder="${DEVELOP_IN_CODER:-0}"

bin_ident="com.coder.cli"

Expand Down Expand Up @@ -149,6 +150,13 @@ if [[ "$debug" == 0 ]]; then
ldflags+=(-s -w)
fi

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
Comment on lines +153 to +158
Copy link
Member Author

@johnstcn johnstcn Jul 22, 2025

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 in codersdk. I can remove the echo message if it's annoying.


# We use ts_omit_aws here because on Linux it prevents Tailscale from importing
# github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary.
TS_EXTRA_SMALL="ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube"
Expand Down
10 changes: 8 additions & 2 deletions scripts/coder-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ source "${SCRIPT_DIR}/lib.sh"

GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
CODER_AGENT_URL="${CODER_AGENT_URL:-}"
DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}"
DEBUG_DELVE="${DEBUG_DELVE:-0}"
BINARY_TYPE=coder-slim
if [[ ${1:-} == server ]]; then
Expand All @@ -35,16 +37,20 @@ CODER_DEV_DIR="$(realpath ./.coderv2)"
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 if CODER=true. That's what I do in my dotfiles.

Copy link
Member Author

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-asher code-asher Jul 24, 2025

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 the set -u.

Copy link
Member Author

@johnstcn johnstcn Jul 25, 2025

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 in develop.sh. Will push a separate PR 👍

#19043

DEVELOP_IN_CODER=1
fi

case $BINARY_TYPE in
coder-slim)
# Ensure the coder slim binary is always up-to-date with local
# changes, this simplifies usage of this script for development.
# NOTE: we send all output of `make` to /dev/null so that we do not break
# scripts that read the output of this command.
if [[ -t 1 ]]; then
make -j "${RELATIVE_BINARY_PATH}"
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}"
else
make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "${RELATIVE_BINARY_PATH}" >/dev/null 2>&1
fi
;;
coder)
Expand Down
9 changes: 7 additions & 2 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ source "${SCRIPT_DIR}/lib.sh"
set -euo pipefail

CODER_DEV_ACCESS_URL="${CODER_DEV_ACCESS_URL:-http://127.0.0.1:3000}"
DEVELOP_IN_CODER="${DEVELOP_IN_CODER:-0}"
debug=0
DEFAULT_PASSWORD="SomeSecurePassword!"
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
Expand Down Expand Up @@ -66,6 +67,10 @@ if [ "${CODER_BUILD_AGPL:-0}" -gt "0" ] && [ "${multi_org}" -gt "0" ]; then
echo '== ERROR: cannot use both multi-organizations and APGL build.' && exit 1
fi

if [ -n "${CODER_AGENT_URL}" ]; then
DEVELOP_IN_CODER=1
fi

# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
dependencies curl git go make pnpm
curl --fail http://127.0.0.1:3000 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
Expand All @@ -75,7 +80,7 @@ curl --fail http://127.0.0.1:8080 >/dev/null 2>&1 && echo '== ERROR: something i
# node_modules if necessary.
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
make -j "build/coder_${GOOS}_${GOARCH}"
DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" make -j "build/coder_${GOOS}_${GOARCH}"

# Use the coder dev shim so we don't overwrite the user's existing Coder config.
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
Expand Down Expand Up @@ -150,7 +155,7 @@ fatal() {
trap 'fatal "Script encountered an error"' ERR

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}" DEVELOP_IN_CODER="${DEVELOP_IN_CODER}" 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 "$@"

echo '== Waiting for Coder to become ready'
# Start the timeout in the background so interrupting this script
Expand Down
7 changes: 7 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ const getMissingParameters = (
return missingParameters;
};

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

Choose a reason for hiding this comment

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

TIL


/**
* @param agentId
* @returns {OneWayWebSocket} A OneWayWebSocket that emits Server-Sent Events.
Expand Down
3 changes: 0 additions & 3 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion site/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default defineConfig({
secure: process.env.NODE_ENV === "production",
},
},
allowedHosts: [".coder"],
allowedHosts: [".coder", ".dev.coder.com"],
Copy link
Member Author

Choose a reason for hiding this comment

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

review: also updated allowedHosts for dev URLs.

},
resolve: {
alias: {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy