Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: refactor codersdk to use SessionTokenProvider#19565

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

Merged
spikecurtis merged 3 commits intomainfromspike/refactor-sdk-session-token-provider
Aug 29, 2025

Conversation

@spikecurtis
Copy link
Contributor

@spikecurtisspikecurtis commentedAug 27, 2025
edited
Loading

Refactorscodersdk.Client's use of session tokens to use aSessionTokenProvider, which abstracts the obtaining and storing of the session token.

The main motiviation is to unify Agent authentication an an upstack PR, which can use cloud instance identity via token exchange, rather than a fixed session token.

However, the abstraction could also allow functionality like obtaining the session token from other external sources like the OS credential manager, or an external secret/key management system like Vault.

@spikecurtisGraphite App
Copy link
ContributorAuthor

spikecurtis commentedAug 27, 2025
edited
Loading

@spikecurtisspikecurtisforce-pushed thespike/refactor-sdk-session-token-provider branch 3 times, most recently from7789799 tod9ee61fCompareAugust 28, 2025 09:36
@spikecurtisspikecurtis marked this pull request as ready for reviewAugust 28, 2025 10:56
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

LGTM in general, just a few API design related suggestions.

tokenHeader=c.client.SessionTokenHeader
wsOptions:=&websocket.DialOptions{
HTTPClient:c.client.HTTPClient,
// Need to disable compression to avoid a data-race.
Copy link
Member

Choose a reason for hiding this comment

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

Is this something we could fix inwebsocket?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I actually don't know. That's just copied from the existing code; I wanted to limit my changes to just session token stuff.

mafredri reacted with thumbs up emoji
// SetSessionTokenreturns the currently set token for the client.
// SetSessionTokensets a fixed token for the client.
func (c*Client)SetSessionToken(tokenstring) {
c.SetSessionTokenProvider(FixedSessionTokenProvider{SessionToken:token})
Copy link
Member

Choose a reason for hiding this comment

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

I can see the logic here, but I think it would make more sense to call provider.SetSessionToken() and implement the method on FixedSessionTokenProvider. Other providers may choose to ignore it or do something else. If this, for example, was a file provider underneath, one may wish to write the token rather than have it be ephemeral.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I actually want to go the other direction and drop this method entirely. The abstraction here is a session tokenprovider, not a session tokenstore.

I kept the method around to keep this PR relatively minimal in size, but we are almost always* using this method to set a fixed session token at start of day. There just aren't really many circumstances where you find out the session token later.

  • 2 exceptions I can think of:
  1. coder login where we get the token pasted in, and then check it. But even in that case, you can create the Client after the token is pasted in. It's not really safe (and has not been) to useSetSessionToken() after the client has been referenced by other goroutines, so it's better to create a new Client.

  2. Token exchange based on VM identity credentials --- that is the subject of the PR stacked on top of this one. This is based on anonymousExchangeToken function callbacks that callSetSessionToken() before the PR above this one, but that's pretty fragile and not threadsafe.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, that makes sense to me and I'm fine with the approach. I'd like it if we could mark this method deprecated, however, and mention that it replaces the provider.

(IIRC the Go standard deprecation comment is, on a new line:// Deprecated: Use ... instead.

returnc.RequestNoSessionToken(ctx,method,path,body,opts...)
}

func (c*Client)RequestNoSessionToken(ctx context.Context,method,pathstring,bodyinterface{},opts...RequestOption) (*http.Response,error) {
Copy link
Member

Choose a reason for hiding this comment

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

Question: What's the use-case for this method?

Suggestion: Can we make it a private method? At least a comment would be good, and I'd suggest renamingNo ->NoSet/Without.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm happy to change the name.

The use-case for this method is in the PR stacked on top of this one.

Exchanging a VM identity document for a session token involves a call to Coderd. We need this option to call coderd without a session token to ensure we don't create a re-entrant loop in the token exchange code.

mafredri reacted with thumbs up emoji
// SetDialOption sets the session token on a websocket request via DialOptions
SetDialOption(options*websocket.DialOptions)
// GetSessionToken returns the session token as a string.
GetSessionToken()string
Copy link
Member

Choose a reason for hiding this comment

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

If we implementSet like proposed earlier, we can make theSessionToken field private and avoidGet here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

There are still some random bits of code that do oddball stuff like putting the session token in a Cookie jar, rather than using the custom header. Until that stuff is cleaned up we still need an escape hatch to just get the session token from the Client.

mafredri reacted with thumbs up emoji
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

No other remaining requests than updating theSetSessionToken comment and marking it deprecated, approved 👍🏻.

@spikecurtisspikecurtisforce-pushed thespike/refactor-sdk-session-token-provider branch from53e1b76 to7ea81d2CompareAugust 29, 2025 08:00
@spikecurtisspikecurtis merged commit192c81e intomainAug 29, 2025
27 checks passed
@spikecurtisspikecurtis deleted the spike/refactor-sdk-session-token-provider branchAugust 29, 2025 08:41
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 29, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@spikecurtisspikecurtis

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@spikecurtis@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp