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

Commitbc18f6c

Browse files
authored
fix: addCODER_AGENT_TAILNET_LISTEN_PORT for specifying a static tailnet port (#6980)
Fixes#5175.
1 parent4ee01dc commitbc18f6c

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

‎agent/agent.go‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type Options struct {
8282
Logger slog.Logger
8383
AgentPortsmap[int]string
8484
SSHMaxTimeout time.Duration
85+
TailnetListenPortuint16
8586
}
8687

8788
typeClientinterface {
@@ -118,6 +119,7 @@ func New(options Options) io.Closer {
118119
}
119120
ctx,cancelFunc:=context.WithCancel(context.Background())
120121
a:=&agent{
122+
tailnetListenPort:options.TailnetListenPort,
121123
reconnectingPTYTimeout:options.ReconnectingPTYTimeout,
122124
logger:options.Logger,
123125
closeCancel:cancelFunc,
@@ -139,12 +141,13 @@ func New(options Options) io.Closer {
139141
}
140142

141143
typeagentstruct {
142-
logger slog.Logger
143-
clientClient
144-
exchangeTokenfunc(ctx context.Context) (string,error)
145-
filesystem afero.Fs
146-
logDirstring
147-
tempDirstring
144+
logger slog.Logger
145+
clientClient
146+
exchangeTokenfunc(ctx context.Context) (string,error)
147+
tailnetListenPortuint16
148+
filesystem afero.Fs
149+
logDirstring
150+
tempDirstring
148151
// ignorePorts tells the api handler which ports to ignore when
149152
// listing all listening ports. This is helpful to hide ports that
150153
// are used by the agent, that the user does not care about.
@@ -606,9 +609,10 @@ func (a *agent) trackConnGoroutine(fn func()) error {
606609

607610
func (a*agent)createTailnet(ctx context.Context,derpMap*tailcfg.DERPMap) (_*tailnet.Conn,errerror) {
608611
network,err:=tailnet.NewConn(&tailnet.Options{
609-
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP,128)},
610-
DERPMap:derpMap,
611-
Logger:a.logger.Named("tailnet"),
612+
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP,128)},
613+
DERPMap:derpMap,
614+
Logger:a.logger.Named("tailnet"),
615+
ListenPort:a.tailnetListenPort,
612616
})
613617
iferr!=nil {
614618
returnnil,xerrors.Errorf("create tailnet: %w",err)

‎cli/agent.go‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ import (
3030

3131
func (r*RootCmd)workspaceAgent()*clibase.Cmd {
3232
var (
33-
authstring
34-
logDirstring
35-
pprofAddressstring
36-
noReapbool
37-
sshMaxTimeout time.Duration
33+
authstring
34+
logDirstring
35+
pprofAddressstring
36+
noReapbool
37+
sshMaxTimeout time.Duration
38+
tailnetListenPortint64
3839
)
3940
cmd:=&clibase.Cmd{
4041
Use:"agent",
@@ -187,9 +188,10 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
187188
}
188189

189190
closer:=agent.New(agent.Options{
190-
Client:client,
191-
Logger:logger,
192-
LogDir:logDir,
191+
Client:client,
192+
Logger:logger,
193+
LogDir:logDir,
194+
TailnetListenPort:uint16(tailnetListenPort),
193195
ExchangeToken:func(ctx context.Context) (string,error) {
194196
ifexchangeToken==nil {
195197
returnclient.SDK.SessionToken(),nil
@@ -248,6 +250,13 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
248250
Description:"Specify the max timeout for a SSH connection.",
249251
Value:clibase.DurationOf(&sshMaxTimeout),
250252
},
253+
{
254+
Flag:"tailnet-listen-port",
255+
Default:"0",
256+
Env:"CODER_AGENT_TAILNET_LISTEN_PORT",
257+
Description:"Specify a static port for Tailscale to use for listening.",
258+
Value:clibase.Int64Of(&tailnetListenPort),
259+
},
251260
}
252261

253262
returncmd

‎cli/testdata/coder_agent_--help.golden‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ Starts the Coder workspace agent.
1818
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 0)
1919
Specify the max timeout for a SSH connection.
2020

21+
--tailnet-listen-port int, $CODER_AGENT_TAILNET_LISTEN_PORT (default: 0)
22+
Specify a static port for Tailscale to use for listening.
23+
2124
---
2225
Run `coder --help` for a list of global options.

‎tailnet/conn.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Options struct {
5959
// If so, only DERPs can establish connections.
6060
BlockEndpointsbool
6161
Logger slog.Logger
62+
ListenPortuint16
6263
}
6364

6465
// NewConn constructs a new Wireguard server that will accept connections from the addresses provided.
@@ -137,6 +138,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
137138
wireguardEngine,err:=wgengine.NewUserspaceEngine(Logger(options.Logger.Named("wgengine")), wgengine.Config{
138139
LinkMonitor:wireguardMonitor,
139140
Dialer:dialer,
141+
ListenPort:options.ListenPort,
140142
})
141143
iferr!=nil {
142144
returnnil,xerrors.Errorf("create wgengine: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp