Skip to content

fix: accept legacy redirect HTTP environment variables #10748

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 1 commit into from
Nov 17, 2023

Conversation

spikecurtis
Copy link
Contributor

@spikecurtis spikecurtis commented Nov 17, 2023

Can someone help me understand the differences between these env variables:

CODER_REDIRECT_TO_ACCESS_URL
CODER_TLS_REDIRECT_HTTP_TO_HTTPS
CODER_TLS_REDIRECT_HTTP

Oh man, what a mess. It looks like CODER_TLS_REDIRECT_HTTP appears in our config docs. Maybe that was the initial name for the environment variable?

At some point, both the flag and the environment variable were --tls-redirect-http-to-https and CODER_TLS_REDIRECT_HTTP_TO_HTTPS. CODER_TLS_REDIRECT_HTTP did nothing.

However, then we introduced CODER_REDIRECT_TO_ACCESS_URL, we put in some deprecation code that was maybe fat-fingered such that we accept the environment variable CODER_TLS_REDIRECT_HTTP but the flag --tls-redirect-http-to-https. Our docs still refer to CODER_TLS_REDIRECT_HTTP at https://coder.com/docs/v2/latest/admin/configure#address

So, I think what we gotta do is still accept CODER_TLS_REDIRECT_HTTP since it was working and in an example doc, but also fix the deprecation code to accept CODER_TLS_REDIRECT_HTTP_TO_HTTPS environment variable.

Copy link
Contributor Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

cli/server.go Outdated
// corresponding flag!) "CODER_TLS_REDIRECT_HTTP", and it appeared in a configuration
// example, so we keep accepting it to not break backward compat.
func redirectHTTPToHTTPSDeprecation(ctx context.Context, logger slog.Logger, inv *clibase.Invocation, cfg *codersdk.DeploymentValues) {
if inv.Environ.Get("CODER_TLS_REDIRECT_HTTP") == "true" ||
Copy link
Member

Choose a reason for hiding this comment

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

Should probably use strconv.ParseBool as well instead of comparing the raw values.

cli/server.go Outdated
if inv.Environ.Get("CODER_TLS_REDIRECT_HTTP") == "true" ||
inv.Environ.Get("CODER_TLS_REDIRECT_HTTP_TO_HTTPS") == "true" ||
inv.ParsedFlags().Changed("tls-redirect-http-to-https") {
logger.Warn(ctx, "--tls-redirect-http-to-https is deprecated, please use --redirect-to-access-url instead")
Copy link
Member

Choose a reason for hiding this comment

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

This may sound silly, but adding some ⚠️ emojis might make this more visible?

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

What a mess indeed! Couple of suggestions.

@spikecurtis spikecurtis force-pushed the spike/http-redirect-vars branch from 30f40f1 to 1e1f734 Compare November 17, 2023 11:03
@spikecurtis spikecurtis merged commit 71f87d0 into main Nov 17, 2023
@spikecurtis spikecurtis deleted the spike/http-redirect-vars branch November 17, 2023 11:09
Copy link
Contributor Author

Merge activity

@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants