Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: implement package and cli tool for repairing oidc links - #26418

Merged
Emyrk merged 2 commits into
mainfrom
stevenmasley/reset_oidc
Jun 16, 2026
Merged

feat: implement package and cli tool for repairing oidc links#26418
Emyrk merged 2 commits into
mainfrom
stevenmasley/reset_oidc

Conversation

@Emyrk

@Emyrk Emyrk commented Jun 16, 2026

Copy link
Copy Markdown
Member

We can probably drop this cli command once the auto code (stacked on this) is defaulted to true.

$ coder server fix-oidc-links --issuer-url="http://localhost:4500"
Resolving OIDC issuer from "http://localhost:4500"...
Resolved OIDC issuer: "http://127.0.0.1:4500"

OIDC Link Analysis (issuer: http://127.0.0.1:4500)
  Total OIDC users:            1
  Correctly linked:            1
  Unlinked (empty linked_id):  0
  Linked to other issuers:     0

Nothing to do. All OIDC links match the expected issuer.

Emyrk commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

When changing oidc providers, all existing links need to be reset.
Comment on lines +72 to +106
// ResolveIssuer uses OIDC discovery to fetch the canonical issuer string
// from the provider's .well-known/openid-configuration endpoint.
// This does not require OIDC client credentials.
//
// This works the same as `oidc.NewProvider`. The `oidc` package does not
// expose a method to extract the Issuer. So we have to manually make the
// http request.
func ResolveIssuer(ctx context.Context, cli *http.Client, issuerURL string) (string, error) {
wellKnownURL := issuerURL + "/.well-known/openid-configuration"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, wellKnownURL, nil)
if err != nil {
return "", xerrors.Errorf("create discovery request: %w", err)
}

resp, err := cli.Do(req)
if err != nil {
return "", xerrors.Errorf("fetch OIDC discovery document: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", xerrors.Errorf("OIDC discovery returned HTTP %d", resp.StatusCode)
}

var discovery struct {
Issuer string `json:"issuer"`
}
if err := json.NewDecoder(resp.Body).Decode(&discovery); err != nil {
return "", xerrors.Errorf("decode OIDC discovery document: %w", err)
}
if discovery.Issuer == "" {
return "", xerrors.New("OIDC discovery document has empty issuer field")
}
return discovery.Issuer, nil
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is unfortunate, but the oidc package does not export the necessary fields to reuse it. We have to manually make the http request 😢

@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

📖 View docs preview for docs/reference/cli/server.md

@Emyrk
Emyrk force-pushed the stevenmasley/reset_oidc branch from 0fef740 to c88e154 Compare June 16, 2026 16:56
@Emyrk
Emyrk marked this pull request as ready for review June 16, 2026 16:59
@coderagents

coderagents Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/admin/users/oidc-auth/index.md - Add a troubleshooting or migration section mentioning coder server fix-oidc-links for administrators who switch OIDC providers and have users unable to re-authenticate due to mismatched issuer-linked IDs. The auto-generated CLI reference is present, but the main OIDC guide (where admins would look first) has no guidance on this scenario.

Automated review via Coder Agents

@Emyrk
Emyrk force-pushed the stevenmasley/reset_oidc branch from c88e154 to eb1149f Compare June 16, 2026 17:11
Comment thread coderd/authlink/authlink.go Outdated
-- and does not begin with the expected issuer prefix. This allows users to
-- re-authenticate under a new OIDC provider.
UPDATE user_links
SET linked_id = ''

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is there any benefit to letting these linger? Why not just delete these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You mean remove the row entirely?
If we remove the row, we lose their existing OIDC token. Which would break any existing access that token has until the user logs back in.

Our session tokens like a week or so. So new workspaces could be broken until they log out + log in.

@Emyrk
Emyrk force-pushed the stevenmasley/reset_oidc branch from eb1149f to 59b3caf Compare June 16, 2026 19:03
@Emyrk
Emyrk force-pushed the stevenmasley/reset_oidc branch from 59b3caf to 58b1963 Compare June 16, 2026 19:28
@Emyrk
Emyrk merged commit 1d03e63 into main Jun 16, 2026
32 checks passed
@Emyrk
Emyrk deleted the stevenmasley/reset_oidc branch June 16, 2026 19:46
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants