Skip to content

Commit d681e24

Browse files
committed
Merge remote-tracking branch 'origin/main' into agent-metadata
2 parents e8cd58e + a6fa8ca commit d681e24

File tree

74 files changed

+1686
-1124
lines changed

Some content is hidden

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

74 files changed

+1686
-1124
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ jobs:
302302
helm repo index build/helm --url https://helm.coder.com/v2 --merge build/helm/index.yaml
303303
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2
304304
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2
305+
gsutil -h "Cache-Control:no-cache,max-age=0" cp helm/artifacthub-repo.yml gs://helm.coder.com/v2
305306
306307
- name: Upload artifacts to actions (if dry-run)
307308
if: ${{ inputs.dry_run }}

cli/create_test.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7-
"net/url"
87
"os"
98
"regexp"
109
"testing"
1110
"time"
1211

1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
15-
"golang.org/x/oauth2"
1614

1715
"github.com/coder/coder/cli/clitest"
1816
"github.com/coder/coder/coderd/coderdtest"
19-
"github.com/coder/coder/coderd/database"
2017
"github.com/coder/coder/coderd/gitauth"
2118
"github.com/coder/coder/codersdk"
2219
"github.com/coder/coder/provisioner/echo"
@@ -768,7 +765,7 @@ func TestCreateWithGitAuth(t *testing.T) {
768765

769766
client := coderdtest.New(t, &coderdtest.Options{
770767
GitAuthConfigs: []*gitauth.Config{{
771-
OAuth2Config: &oauth2Config{},
768+
OAuth2Config: &testutil.OAuth2Config{},
772769
ID: "github",
773770
Regex: regexp.MustCompile(`github\.com`),
774771
Type: codersdk.GitProviderGitHub,
@@ -836,31 +833,3 @@ func createTestParseResponseWithDefault(defaultValue string) []*proto.Parse_Resp
836833
},
837834
}}
838835
}
839-
840-
type oauth2Config struct{}
841-
842-
func (*oauth2Config) AuthCodeURL(state string, _ ...oauth2.AuthCodeOption) string {
843-
return "/?state=" + url.QueryEscape(state)
844-
}
845-
846-
func (*oauth2Config) Exchange(context.Context, string, ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
847-
return &oauth2.Token{
848-
AccessToken: "token",
849-
RefreshToken: "refresh",
850-
Expiry: database.Now().Add(time.Hour),
851-
}, nil
852-
}
853-
854-
func (*oauth2Config) TokenSource(context.Context, *oauth2.Token) oauth2.TokenSource {
855-
return &oauth2TokenSource{}
856-
}
857-
858-
type oauth2TokenSource struct{}
859-
860-
func (*oauth2TokenSource) Token() (*oauth2.Token, error) {
861-
return &oauth2.Token{
862-
AccessToken: "token",
863-
RefreshToken: "refresh",
864-
Expiry: database.Now().Add(time.Hour),
865-
}, nil
866-
}

cli/server.go

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import (
8585
"github.com/coder/coder/provisionersdk"
8686
sdkproto "github.com/coder/coder/provisionersdk/proto"
8787
"github.com/coder/coder/tailnet"
88+
"github.com/coder/wgtunnel/tunnelsdk"
8889
)
8990

9091
// ReadGitAuthProvidersFromEnv is provided for compatibility purposes with the
@@ -538,34 +539,25 @@ flags, and YAML configuration. The precedence is as follows:
538539
return xerrors.Errorf("configure http client: %w", err)
539540
}
540541

541-
var (
542-
ctxTunnel, closeTunnel = context.WithCancel(ctx)
543-
tunnel *devtunnel.Tunnel
544-
tunnelErr <-chan error
545-
)
546-
defer closeTunnel()
547-
548542
// If the access URL is empty, we attempt to run a reverse-proxy
549543
// tunnel to make the initial setup really simple.
544+
var (
545+
tunnel *tunnelsdk.Tunnel
546+
tunnelDone <-chan struct{} = make(chan struct{}, 1)
547+
)
550548
if cfg.AccessURL.String() == "" {
551549
cmd.Printf("Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
552-
tunnel, tunnelErr, err = devtunnel.New(ctxTunnel, logger.Named("devtunnel"))
550+
tunnel, err = devtunnel.New(ctx, logger.Named("devtunnel"), cfg.WgtunnelHost.String())
553551
if err != nil {
554552
return xerrors.Errorf("create tunnel: %w", err)
555553
}
556-
err = cfg.AccessURL.Set(tunnel.URL)
557-
if err != nil {
558-
return xerrors.Errorf("set access url: %w", err)
559-
}
554+
defer tunnel.Close()
555+
tunnelDone = tunnel.Wait()
556+
cfg.AccessURL = clibase.URL(*tunnel.URL)
560557

561558
if cfg.WildcardAccessURL.String() == "" {
562-
u, err := parseURL(tunnel.URL)
563-
if err != nil {
564-
return xerrors.Errorf("parse tunnel url: %w", err)
565-
}
566-
567559
// Suffixed wildcard access URL.
568-
u, err = url.Parse(fmt.Sprintf("*--%s", u.Hostname()))
560+
u, err := url.Parse(fmt.Sprintf("*--%s", tunnel.URL.Hostname()))
569561
if err != nil {
570562
return xerrors.Errorf("parse wildcard url: %w", err)
571563
}
@@ -1090,10 +1082,8 @@ flags, and YAML configuration. The precedence is as follows:
10901082
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Bold.Render(
10911083
"Interrupt caught, gracefully exiting. Use ctrl+\\ to force quit",
10921084
))
1093-
case exitErr = <-tunnelErr:
1094-
if exitErr == nil {
1095-
exitErr = xerrors.New("dev tunnel closed unexpectedly")
1096-
}
1085+
case <-tunnelDone:
1086+
exitErr = xerrors.New("dev tunnel closed unexpectedly")
10971087
case exitErr = <-errCh:
10981088
}
10991089
if exitErr != nil && !xerrors.Is(exitErr, context.Canceled) {
@@ -1162,8 +1152,8 @@ flags, and YAML configuration. The precedence is as follows:
11621152
// Close tunnel after we no longer have in-flight connections.
11631153
if tunnel != nil {
11641154
cmd.Println("Waiting for tunnel to close...")
1165-
closeTunnel()
1166-
<-tunnelErr
1155+
_ = tunnel.Close()
1156+
<-tunnel.Wait()
11671157
cmd.Println("Done waiting for tunnel")
11681158
}
11691159

@@ -1241,22 +1231,6 @@ flags, and YAML configuration. The precedence is as follows:
12411231
return root
12421232
}
12431233

1244-
// parseURL parses a string into a URL.
1245-
func parseURL(u string) (*url.URL, error) {
1246-
hasScheme := strings.HasPrefix(u, "http:") || strings.HasPrefix(u, "https:")
1247-
1248-
if !hasScheme {
1249-
return nil, xerrors.Errorf("URL %q must have a scheme of either http or https", u)
1250-
}
1251-
1252-
parsed, err := url.Parse(u)
1253-
if err != nil {
1254-
return nil, err
1255-
}
1256-
1257-
return parsed, nil
1258-
}
1259-
12601234
// isLocalURL returns true if the hostname of the provided URL appears to
12611235
// resolve to a loopback address.
12621236
func isLocalURL(ctx context.Context, u *url.URL) (bool, error) {

coderd/apidoc/docs.go

Lines changed: 56 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: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/audit/request.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
154154
if ResourceID(req.Old) == uuid.Nil && ResourceID(req.New) == uuid.Nil {
155155
// If the request action is a login or logout, we always want to audit it even if
156156
// there is no diff. This is so we can capture events where an API Key is never created
157-
// because an unknown user fails to login.
158-
// TODO: introduce the concept of an anonymous user so we always have a userID even
159-
// when dealing with a mystery user. https://github.com/coder/coder/issues/6054
157+
// because a known user fails to login.
160158
if req.params.Action != database.AuditActionLogin && req.params.Action != database.AuditActionLogout {
161159
return
162160
}
@@ -185,8 +183,13 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
185183
key, ok := httpmw.APIKeyOptional(p.Request)
186184
if ok {
187185
userID = key.UserID
188-
} else {
186+
} else if req.UserID != uuid.Nil {
189187
userID = req.UserID
188+
} else {
189+
// if we do not have a user associated with the audit action
190+
// we do not want to audit
191+
// (this pertains to logins; we don't want to capture non-user login attempts)
192+
return
190193
}
191194

192195
ip := parseIP(p.Request.RemoteAddr)

coderd/coderd.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ func New(options *Options) *API {
500500
httpmw.ExtractTemplateVersionParam(options.Database),
501501
)
502502
r.Get("/", api.templateVersion)
503+
r.Patch("/", api.patchTemplateVersion)
503504
r.Patch("/cancel", api.patchCancelTemplateVersion)
504505
r.Get("/schema", api.templateVersionSchema)
505506
r.Get("/parameters", api.templateVersionParameters)
@@ -833,18 +834,14 @@ func (api *API) CreateInMemoryProvisionerDaemon(ctx context.Context, debounce ti
833834

834835
mux := drpcmux.New()
835836

836-
gitAuthProviders := make([]string, 0, len(api.GitAuthConfigs))
837-
for _, cfg := range api.GitAuthConfigs {
838-
gitAuthProviders = append(gitAuthProviders, cfg.ID)
839-
}
840837
err = proto.DRPCRegisterProvisionerDaemon(mux, &provisionerdserver.Server{
841838
AccessURL: api.AccessURL,
842839
ID: daemon.ID,
843840
OIDCConfig: api.OIDCConfig,
844841
Database: api.Database,
845842
Pubsub: api.Pubsub,
846843
Provisioners: daemon.Provisioners,
847-
GitAuthProviders: gitAuthProviders,
844+
GitAuthConfigs: api.GitAuthConfigs,
848845
Telemetry: api.Telemetry,
849846
Tags: tags,
850847
QuotaCommitter: &api.QuotaCommitter,

0 commit comments

Comments
 (0)