Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: PR comments
  • Loading branch information
deansheather committed Mar 7, 2023
commit 189eecf2aa53f94c01b8a8dd98d585434d2ae694
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
err = options.Database.InTx(func(tx database.Store) error {
// This will block until the lock is acquired, and will be
// automatically released when the transaction ends.
err := tx.AcquireLock(ctx, database.LockID("deployment_startup"))
err := tx.AcquireLock(ctx, database.LockIDDeploymentSetup)
if err != nil {
return xerrors.Errorf("acquire lock: %w", err)
}
Expand Down
8 changes: 0 additions & 8 deletions coderd/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"context"
"database/sql"
"errors"
"hash/fnv"
"time"

"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -104,10 +103,3 @@ func (q *sqlQuerier) InTx(function func(Store) error, txOpts *sql.TxOptions) err
}
return nil
}

// LockID hashes the given string into an int64 to use with lock functions.
func LockID(name string) int64 {
hash := fnv.New64()
_, _ = hash.Write([]byte(name))
return int64(hash.Sum64())
}
8 changes: 8 additions & 0 deletions coderd/database/lock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package database

// Well-known lock IDs for lock functions in the database. These should not
// change. If locks are deprecated, they should be kept to avoid reusing the
// same ID.
const (
LockIDDeploymentSetup = iota + 1
)
4 changes: 0 additions & 4 deletions coderd/workspaceapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func (api *API) workspaceAppsProxyPath(rw http.ResponseWriter, r *http.Request)
},
RedirectToLogin: true,
DisableSessionExpiryRefresh: api.DeploymentConfig.DisableSessionExpiryRefresh.Value,
// Optional is true to allow for public apps. If an
// authorization check fails and the user is not authenticated,
// they will be redirected to the login page below.
Optional: false,
}),
httpmw.ExtractUserParam(api.Database, true),
})
Expand Down
17 changes: 9 additions & 8 deletions coderd/workspaceapps/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
// TODO: configurable expiry
// TODO(@deansheather): configurable expiry
TicketExpiry = time.Minute

// RedirectURIQueryParam is the query param for the app URL to be passed
Expand Down Expand Up @@ -90,14 +90,15 @@ func (p *Provider) ResolveRequest(rw http.ResponseWriter, r *http.Request, appRe
ticketOK = false
)
httpmw.ExtractAPIKey(httpmw.ExtractAPIKeyConfig{
DB: p.Database,
OAuth2Configs: p.OAuth2Configs,
// Optional is true to allow for public apps. If an authorization check
// fails and the user is not authenticated, they will be redirected to
// the login page below.
DB: p.Database,
OAuth2Configs: p.OAuth2Configs,
RedirectToLogin: false,
DisableSessionExpiryRefresh: p.DeploymentConfig.DisableSessionExpiryRefresh.Value,
Optional: true,
// Optional is true to allow for public apps. If an authorization check
// fails and the user is not authenticated, they will be redirected to
// the login page using code below (not the redirect from the
// middleware itself).
Optional: true,
})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get user.
var (
Expand Down Expand Up @@ -486,7 +487,7 @@ func (p *Provider) writeWorkspaceApp500(rw http.ResponseWriter, r *http.Request,
slog.F("app_name_or_port", appReq.AppSlugOrPort),
)
}
p.Logger.Warn(r.Context(),
p.Logger.Warn(ctx,
"workspace app auth server error: "+msg,
slog.Error(err),
)
Expand Down
4 changes: 2 additions & 2 deletions coderd/workspaceapps/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

// Provider provides authentication and authorization for workspace apps.
// TODO: also provide workspace apps as a whole to remove all app code from
// coderd.
// TODO(@deansheather): also provide workspace apps as a whole to remove all app
// code from coderd.
type Provider struct {
Logger slog.Logger

Expand Down