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: implement CoderVPN client & tunnel#15612

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
ethanndickson merged 1 commit intomainfromethan/vpn-client
Dec 5, 2024

Conversation

ethanndickson
Copy link
Member

@ethanndicksonethanndickson commentedNov 21, 2024
edited
Loading

Addresses#14734.

This PR wires uptunnel.go to atailnet.Conn via the new/tailnet endpoint, with all the necessary controllers such that a VPN connection can be started, stopped and inspected via the CoderVPN protocol.

@ethanndicksonGraphite App
Copy link
MemberAuthor

ethanndickson commentedNov 21, 2024
edited
Loading

stringapi_token=3;
// Additional HTTP headers added to all requests
messageHeader {
stringname=1;
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Deliberately not a map to support repeated headers

spikecurtis reacted with thumbs up emoji
"github.com/coder/coder/v2/vpn"
)

funcTestClient_WorkspaceUpdates(t*testing.T) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This test might be a bit much, but I wanted to test the Client without spinning up a wholecoderd, and it turns out that takes a bit of code.

Copy link
Member

Choose a reason for hiding this comment

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

This is a lot. Is there any particular reason to not spin up coderd (other than wanting to be lean I guess) to avoid all this boilerplate?


typeConninterface {
CurrentWorkspaceState()*proto.WorkspaceUpdate
Close()error
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I suspect this interface will grow with whatever functions fromtailnet.Conn we end up needing.

@ethanndicksonethanndickson marked this pull request as ready for reviewNovember 22, 2024 05:40
@ethanndicksonethanndickson changed the titlechore: implement vpn client & dylib tunnelchore: implement CoderVPN client & tunnelNov 22, 2024
vpn/tunnel.go Outdated
fori,agent:=rangeupdate.UpsertedAgents {
out.UpsertedAgents[i]=&Agent{
Id:agent.Id,
Name:agent.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

missing workspace_id, fqdn.

Also missing ip address and last handshake, but we can save those for another PR.

ethanndickson reacted with eyes emoji
Comment on lines +82 to +93
// TODO: Wait for the reply to be sent before closing the speaker.
// err := t.speaker.Close()
// if err != nil {
// t.logger.Error(t.ctx, "failed to close speaker", slog.Error(err))
// }
Copy link
Member

Choose a reason for hiding this comment

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

I think our tunnel may need a mutex or sync.Once to handle being closed properly?

ethanndickson reacted with eyes emoji
Comment on lines +256 to +260
ifoptions.TUNDev==nil {
dialer.NetstackDialTCP=func(ctx context.Context,dst netip.AddrPort) (net.Conn,error) {
returnnetStack.DialContextTCP(ctx,dst)
}
netStack.ProcessLocalIPs=true
Copy link
Member

Choose a reason for hiding this comment

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

Can we consolidate the places we do this check onoptions.TUNDev?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm not sure if changing some of the ordering here breaks anything, may need to revisit cleaning this up once we have tests that pass in a real TUN fd. Theconn.go changes I just copied from Spike's prototype branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, ordering does matter here in general. It might be possible to do it better.

func (wworkspace)addAllDNSNames(namesmap[dnsname.FQDN][]netip.Addr,ownerstring)error {
for_,a:=rangew.agents {
// updateDNSNames updates the DNS names for all agents in the workspace.
func (w*Workspace)updateDNSNames()error {
Copy link
MemberAuthor

@ethanndicksonethanndicksonNov 25, 2024
edited
Loading

Choose a reason for hiding this comment

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

Including all the FQDNs as part of an outgoing workspace update was kinda tricky, particularly because of thelen(agents) == 1 alias.

This solution just has this function update the hosts on each agent, and then store all the agents and workspaces as pointers. This lets us build our workspace update as we apply the diff to the state, and then before sending, we fill in all the correct FQDNs, which applies to both the state, and the outgoing update.

func (t*tunnelUpdater)updateDNSNames()map[dnsname.FQDN][]netip.Addr {
names:=make(map[dnsname.FQDN][]netip.Addr)
for_,w:=ranget.workspaces {
err:=w.addAllDNSNames(names,t.ownerUsername)
Copy link
MemberAuthor

@ethanndicksonethanndicksonNov 25, 2024
edited
Loading

Choose a reason for hiding this comment

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

I moved theownerUsername from an argument when updating a workspace to a private field on theWorkspace, as it made more sense for future-proofing w.r.t. shared workspaces.

deansheather reacted with thumbs up emoji
Comment on lines 156 to 177
funcUseAsRouter()TunnelOption {
returnfunc(t*Tunnel) {
t.router=NewRouter(t)
}
}

funcUseAsLogger()TunnelOption {
returnfunc(t*Tunnel) {
t.logger=t.logger.AppendSinks(t)
}
}

funcUseAsDNSConfig()TunnelOption {
returnfunc(t*Tunnel) {
t.dnsConfigurator=NewDNSConfigurator(t)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever not want these things? They should just be the default and we should removeTunnelOption until the need arises

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Spike suggested earlier:#15612 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I honestly prefer the separate build tag files that do the implementations for each of these on each platform but to each their own

@ethanndicksonethanndickson merged commitba48069 intomainDec 5, 2024
31 checks passed
@ethanndicksonethanndickson deleted the ethan/vpn-client branchDecember 5, 2024 02:30
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@johnstcnjohnstcnjohnstcn left review comments

@deansheatherdeansheatherdeansheather approved these changes

@spikecurtisspikecurtisAwaiting requested review from spikecurtisspikecurtis is a code owner

Assignees

@ethanndicksonethanndickson

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@ethanndickson@johnstcn@spikecurtis@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp