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

Skip to content

Commit cf3afd4

Browse files
committed
Merge remote-tracking branch 'origin/main' into jjs/consistent-notification-format
2 parents 7e31a34 + 288df75 commit cf3afd4

File tree

147 files changed

+7144
-7595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+7144
-7595
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ gen/mark-fresh:
537537
tailnet/tailnettest/coordinatormock.go \
538538
tailnet/tailnettest/coordinateemock.go \
539539
tailnet/tailnettest/multiagentmock.go \
540-
"
540+
"
541+
541542
for file in $$files; do
542543
echo "$$file"
543544
if [ ! -f "$$file" ]; then
@@ -629,7 +630,10 @@ coderd/rbac/object_gen.go: scripts/rbacgen/rbacobject.gotmpl scripts/rbacgen/mai
629630
go run scripts/rbacgen/main.go rbac > coderd/rbac/object_gen.go
630631

631632
codersdk/rbacresources_gen.go: scripts/rbacgen/codersdk.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go coderd/rbac/policy/policy.go
632-
go run scripts/rbacgen/main.go codersdk > codersdk/rbacresources_gen.go
633+
# Do no overwrite codersdk/rbacresources_gen.go directly, as it would make the file empty, breaking
634+
# the `codersdk` package and any parallel build targets.
635+
go run scripts/rbacgen/main.go codersdk > /tmp/rbacresources_gen.go
636+
mv /tmp/rbacresources_gen.go codersdk/rbacresources_gen.go
633637

634638
site/src/api/rbacresourcesGenerated.ts: scripts/rbacgen/codersdk.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go coderd/rbac/policy/policy.go
635639
go run scripts/rbacgen/main.go typescript > "$@"

agent/agent.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ type Options struct {
8282
SSHMaxTimeout time.Duration
8383
TailnetListenPort uint16
8484
Subsystems []codersdk.AgentSubsystem
85-
Addresses []netip.Prefix
8685
PrometheusRegistry *prometheus.Registry
8786
ReportMetadataInterval time.Duration
8887
ServiceBannerRefreshInterval time.Duration
@@ -180,7 +179,6 @@ func New(options Options) Agent {
180179
announcementBannersRefreshInterval: options.ServiceBannerRefreshInterval,
181180
sshMaxTimeout: options.SSHMaxTimeout,
182181
subsystems: options.Subsystems,
183-
addresses: options.Addresses,
184182
syscaller: options.Syscaller,
185183
modifiedProcs: options.ModifiedProcesses,
186184
processManagementTick: options.ProcessManagementTick,
@@ -250,7 +248,6 @@ type agent struct {
250248
lifecycleLastReportedIndex int // Keeps track of the last lifecycle state we successfully reported.
251249

252250
network *tailnet.Conn
253-
addresses []netip.Prefix
254251
statsReporter *statsReporter
255252
logSender *agentsdk.LogSender
256253

@@ -1112,15 +1109,14 @@ func (a *agent) updateCommandEnv(current []string) (updated []string, err error)
11121109
return updated, nil
11131110
}
11141111

1115-
func (a *agent) wireguardAddresses(agentID uuid.UUID) []netip.Prefix {
1116-
if len(a.addresses) == 0 {
1117-
return []netip.Prefix{
1118-
// This is the IP that should be used primarily.
1119-
netip.PrefixFrom(tailnet.IPFromUUID(agentID), 128),
1120-
}
1112+
func (*agent) wireguardAddresses(agentID uuid.UUID) []netip.Prefix {
1113+
return []netip.Prefix{
1114+
// This is the IP that should be used primarily.
1115+
tailnet.TailscaleServicePrefix.PrefixFromUUID(agentID),
1116+
// We'll need this address for CoderVPN, but aren't using it from clients until that feature
1117+
// is ready
1118+
tailnet.CoderServicePrefix.PrefixFromUUID(agentID),
11211119
}
1122-
1123-
return a.addresses
11241120
}
11251121

11261122
func (a *agent) trackGoroutine(fn func()) error {

agent/agent_test.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"path/filepath"
2020
"regexp"
2121
"runtime"
22+
"strconv"
2223
"strings"
2324
"sync"
2425
"sync/atomic"
@@ -1814,20 +1815,45 @@ func TestAgent_Dial(t *testing.T) {
18141815

18151816
go func() {
18161817
defer close(done)
1817-
c, err := l.Accept()
1818-
if assert.NoError(t, err, "accept connection") {
1819-
defer c.Close()
1820-
testAccept(ctx, t, c)
1818+
for range 2 {
1819+
c, err := l.Accept()
1820+
if assert.NoError(t, err, "accept connection") {
1821+
testAccept(ctx, t, c)
1822+
_ = c.Close()
1823+
}
18211824
}
18221825
}()
18231826

1827+
agentID := uuid.UUID{0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}
18241828
//nolint:dogsled
1825-
agentConn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
1829+
agentConn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{
1830+
AgentID: agentID,
1831+
}, 0)
18261832
require.True(t, agentConn.AwaitReachable(ctx))
18271833
conn, err := agentConn.DialContext(ctx, l.Addr().Network(), l.Addr().String())
18281834
require.NoError(t, err)
1829-
defer conn.Close()
18301835
testDial(ctx, t, conn)
1836+
err = conn.Close()
1837+
require.NoError(t, err)
1838+
1839+
// also connect via the CoderServicePrefix, to test that we can reach the agent on this
1840+
// IP. This will be required for CoderVPN.
1841+
_, rawPort, _ := net.SplitHostPort(l.Addr().String())
1842+
port, _ := strconv.ParseUint(rawPort, 10, 16)
1843+
ipp := netip.AddrPortFrom(tailnet.CoderServicePrefix.AddrFromUUID(agentID), uint16(port))
1844+
1845+
switch l.Addr().Network() {
1846+
case "tcp":
1847+
conn, err = agentConn.Conn.DialContextTCP(ctx, ipp)
1848+
case "udp":
1849+
conn, err = agentConn.Conn.DialContextUDP(ctx, ipp)
1850+
default:
1851+
t.Fatalf("unknown network: %s", l.Addr().Network())
1852+
}
1853+
require.NoError(t, err)
1854+
testDial(ctx, t, conn)
1855+
err = conn.Close()
1856+
require.NoError(t, err)
18311857
})
18321858
}
18331859
}
@@ -1880,7 +1906,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
18801906
// Setup a client connection.
18811907
newClientConn := func(derpMap *tailcfg.DERPMap, name string) *workspacesdk.AgentConn {
18821908
conn, err := tailnet.NewConn(&tailnet.Options{
1883-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
1909+
Addresses: []netip.Prefix{tailnet.TailscaleServicePrefix.RandomPrefix()},
18841910
DERPMap: derpMap,
18851911
Logger: logger.Named(name),
18861912
})
@@ -2372,7 +2398,7 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
23722398
_ = agnt.Close()
23732399
})
23742400
conn, err := tailnet.NewConn(&tailnet.Options{
2375-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
2401+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.TailscaleServicePrefix.RandomAddr(), 128)},
23762402
DERPMap: metadata.DERPMap,
23772403
Logger: logger.Named("client"),
23782404
})

coderd/apidoc/docs.go

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ type Options struct {
248248

249249
// IDPSync holds all configured values for syncing external IDP users into Coder.
250250
IDPSync idpsync.IDPSync
251+
252+
// OneTimePasscodeValidityPeriod specifies how long a one time passcode should be valid for.
253+
OneTimePasscodeValidityPeriod time.Duration
251254
}
252255

253256
// @title Coder API
@@ -387,6 +390,9 @@ func New(options *Options) *API {
387390
v := schedule.NewAGPLUserQuietHoursScheduleStore()
388391
options.UserQuietHoursScheduleStore.Store(&v)
389392
}
393+
if options.OneTimePasscodeValidityPeriod == 0 {
394+
options.OneTimePasscodeValidityPeriod = 20 * time.Minute
395+
}
390396

391397
if options.StatsBatcher == nil {
392398
panic("developer error: options.StatsBatcher is nil")
@@ -984,6 +990,8 @@ func New(options *Options) *API {
984990
// This value is intentionally increased during tests.
985991
r.Use(httpmw.RateLimit(options.LoginRateLimit, time.Minute))
986992
r.Post("/login", api.postLogin)
993+
r.Post("/otp/request", api.postRequestOneTimePasscode)
994+
r.Post("/otp/change-password", api.postChangePasswordWithOneTimePasscode)
987995
r.Route("/oauth2", func(r chi.Router) {
988996
r.Route("/github", func(r chi.Router) {
989997
r.Use(

coderd/coderd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestDERP(t *testing.T) {
8383
},
8484
},
8585
}
86-
w1IP := tailnet.IP()
86+
w1IP := tailnet.TailscaleServicePrefix.RandomAddr()
8787
w1, err := tailnet.NewConn(&tailnet.Options{
8888
Addresses: []netip.Prefix{netip.PrefixFrom(w1IP, 128)},
8989
Logger: logger.Named("w1"),
@@ -92,7 +92,7 @@ func TestDERP(t *testing.T) {
9292
require.NoError(t, err)
9393

9494
w2, err := tailnet.NewConn(&tailnet.Options{
95-
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
95+
Addresses: []netip.Prefix{tailnet.TailscaleServicePrefix.RandomPrefix()},
9696
Logger: logger.Named("w2"),
9797
DERPMap: derpMap,
9898
})

0 commit comments

Comments
 (0)