feat: implement package and cli tool for repairing oidc links - #26418
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
When changing oidc providers, all existing links need to be reset.
fc01d2c to
2b0804e
Compare
| // 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 | ||
| } |
There was a problem hiding this comment.
This is unfortunate, but the oidc package does not export the necessary fields to reuse it. We have to manually make the http request 😢
Docs preview📖 View docs preview for |
0fef740 to
c88e154
Compare
Documentation CheckUpdates Needed
Automated review via Coder Agents |
c88e154 to
eb1149f
Compare
| -- 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 = '' |
There was a problem hiding this comment.
is there any benefit to letting these linger? Why not just delete these?
There was a problem hiding this comment.
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.
eb1149f to
59b3caf
Compare
59b3caf to
58b1963
Compare

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