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

[WIP] feat(enterprise): encrypt external access tokens (oidc, git auth) in the database#9339

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

Closed
johnstcn wants to merge67 commits intomainfromcj/dbcrypt
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
67 commits
Select commitHold shift + click to select a range
6651fe1
feat: encrypt oidc and git auth tokens in the database
kylecarbsMay 30, 2023
b9251fd
Fix dbcrypt
kylecarbsJun 11, 2023
deb577b
Automatically delete rows when not encrypted
kylecarbsJun 12, 2023
faa20ad
gen
kylecarbsJun 12, 2023
2e19360
Merge branch 'main' into dbcrypt
kylecarbsJun 12, 2023
614065b
Merge branch 'main' into dbcrypt
kylecarbsJun 18, 2023
be996ba
Merge remote-tracking branch 'origin/dbcrypt' into cj/dbcrypt
johnstcnAug 22, 2023
2b99db9
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 22, 2023
7837f71
move cipher to dbcrypt package
johnstcnAug 22, 2023
82e7b35
fixup! move cipher to dbcrypt package
johnstcnAug 22, 2023
2b404d1
fixup! move cipher to dbcrypt package
johnstcnAug 22, 2023
02277a8
fixup! move cipher to dbcrypt package
johnstcnAug 22, 2023
3a21c5d
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 22, 2023
a4612c2
fixup! move cipher to dbcrypt package
johnstcnAug 22, 2023
8b1f835
update golden files
johnstcnAug 22, 2023
60d52f5
enforce 32-byte key length
johnstcnAug 22, 2023
dc69c4a
fix some failing tests
johnstcnAug 22, 2023
d9d050f
make DecryptionFailedError unwrap to sql.ErrNoRows
johnstcnAug 23, 2023
1cd4847
modify dbCrypt to not delete rows silently
johnstcnAug 23, 2023
832766c
add dbcrypt_sentinel table to determine encryption status
johnstcnAug 23, 2023
935f79f
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 23, 2023
05c0cf9
fix unused-receiver
johnstcnAug 23, 2023
6556269
move dbcrypt to enterprise
johnstcnAug 23, 2023
cbd776f
dbcrypt.New now marks database as encrypted
johnstcnAug 24, 2023
5929c96
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 24, 2023
22e7aeb
add hex digest of cipher to encrypted fields
johnstcnAug 24, 2023
3842fdd
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 24, 2023
9f71836
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 25, 2023
17e694c
fixup! Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 25, 2023
dbe6915
add previous external token encryption key deployment value
johnstcnAug 25, 2023
d4c74bf
support secondary cipher in dbcrypt
johnstcnAug 25, 2023
e14272c
fixup! support secondary cipher in dbcrypt
johnstcnAug 25, 2023
a71fbaf
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 25, 2023
15c4919
fix DeploymentValues.WithoutSecrets()
johnstcnAug 25, 2023
63fda96
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 28, 2023
09cad5b
export cli.connectToPostgres
johnstcnAug 28, 2023
dd4a94c
add queries to support rotating dbcrypt keys
johnstcnAug 28, 2023
75e4014
make gen
johnstcnAug 28, 2023
0c01b36
fixup! add queries to support rotating dbcrypt keys
johnstcnAug 28, 2023
a457307
flesh out unit test
johnstcnAug 28, 2023
4d28746
make the test pass
johnstcnAug 28, 2023
f64b7bb
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 29, 2023
67ee610
remove unused queries
johnstcnAug 29, 2023
5a0161c
refactor: add Ciphers to abstract over multiple ciphers
johnstcnAug 29, 2023
4142fb2
refactor dbcrypt: add Ciphers to wrap multiple AES256
johnstcnAug 29, 2023
7a64a4e
fixup! refactor dbcrypt: add Ciphers to wrap multiple AES256
johnstcnAug 29, 2023
600391f
fixup! refactor dbcrypt: add Ciphers to wrap multiple AES256
johnstcnAug 29, 2023
ae6f623
fixup! refactor dbcrypt: add Ciphers to wrap multiple AES256
johnstcnAug 29, 2023
8b07604
make gen
johnstcnAug 29, 2023
a2b7935
make fmt
johnstcnAug 29, 2023
e3dd4c0
make lint
johnstcnAug 29, 2023
db30bdd
update-golden-files
johnstcnAug 29, 2023
4c6a93f
fix logging
johnstcnAug 29, 2023
da8c984
appease the linter
johnstcnAug 29, 2023
e1a77a6
address some comments from original PR
johnstcnAug 29, 2023
552e425
fixup! address some comments from original PR
johnstcnAug 29, 2023
2e5b5c0
lint
johnstcnAug 29, 2023
ad44e1e
fixup! lint
johnstcnAug 29, 2023
128ad09
handle sentinel mismatch with a specific message
johnstcnAug 29, 2023
1851fff
fix build issue
johnstcnAug 29, 2023
6ad0904
add external token encryption keys to ./scripts/develop.sh by default
johnstcnAug 29, 2023
1b6e92e
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 29, 2023
fe21f26
fixup! add external token encryption keys to ./scripts/develop.sh by …
johnstcnAug 29, 2023
8cb07ba
decrypt fields when inserting and updating!
johnstcnAug 29, 2023
b6a8a83
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 29, 2023
fc4e2a6
Merge remote-tracking branch 'origin/main' into cj/dbcrypt
johnstcnAug 30, 2023
625a85f
add docs for encryption
johnstcnAug 30, 2023
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
4 changes: 2 additions & 2 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -685,7 +685,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
options.Database = dbfake.New()
options.Pubsub = pubsub.NewInMemory()
} else {
sqlDB, err :=connectToPostgres(ctx, logger, sqlDriver, vals.PostgresURL.String())
sqlDB, err :=ConnectToPostgres(ctx, logger, sqlDriver, vals.PostgresURL.String())
if err != nil {
return xerrors.Errorf("connect to postgres: %w", err)
}
Expand DownExpand Up@@ -1950,7 +1950,7 @@ func BuildLogger(inv *clibase.Invocation, cfg *codersdk.DeploymentValues) (slog.
}, nil
}

funcconnectToPostgres(ctx context.Context, logger slog.Logger, driver string, dbURL string) (*sql.DB, error) {
funcConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, dbURL string) (*sql.DB, error) {
logger.Debug(ctx, "connecting to postgresql")

// Try to connect for 30 seconds.
Expand Down
2 changes: 1 addition & 1 deletioncli/server_createadminuser.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ func (r *RootCmd) newCreateAdminUserCommand() *clibase.Cmd {
newUserDBURL = url
}

sqlDB, err :=connectToPostgres(ctx, logger, "postgres", newUserDBURL)
sqlDB, err :=ConnectToPostgres(ctx, logger, "postgres", newUserDBURL)
if err != nil {
return xerrors.Errorf("connect to postgres: %w", err)
}
Expand Down
8 changes: 8 additions & 0 deletionscli/testdata/coder_server_--help.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -458,6 +458,14 @@ These options are only available in the Enterprise Edition.
An HTTP URL that is accessible by other replicas to relay DERP
traffic. Required for high availability.

--external-token-encryption-keys string-array, $CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS
Encrypt OIDC and Git authentication tokens with AES-256-GCM in the
database. The value must be a comma-separated list of base64-encoded
keys. A maximum of two keys may be provided. Each key, when
base64-decoded, must be exactly 32 bytes in length. The first key will
be used to encrypt new values. Subsequent keys will be used as a
fallback when decrypting.

--scim-auth-header string, $CODER_SCIM_AUTH_HEADER
Enables SCIM and sets the authentication header for the built-in SCIM
server. New users are automatically created with OIDC authentication.
Expand Down
6 changes: 6 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 6 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

28 changes: 28 additions & 0 deletionscoderd/database/dbauthz/dbauthz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -828,6 +828,13 @@ func (q *querier) GetAuthorizationUserRoles(ctx context.Context, userID uuid.UUI
return q.db.GetAuthorizationUserRoles(ctx, userID)
}

func (q *querier) GetDBCryptSentinelValue(ctx context.Context) (string, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return "", err
}
return q.db.GetDBCryptSentinelValue(ctx)
}

func (q *querier) GetDERPMeshKey(ctx context.Context) (string, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return "", err
Expand DownExpand Up@@ -904,6 +911,13 @@ func (q *querier) GetGitAuthLink(ctx context.Context, arg database.GetGitAuthLin
return fetch(q.log, q.auth, q.db.GetGitAuthLink)(ctx, arg)
}

func (q *querier) GetGitAuthLinksByUserID(ctx context.Context, userID uuid.UUID) ([]database.GitAuthLink, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return nil, err
}
return q.db.GetGitAuthLinksByUserID(ctx, userID)
}

func (q *querier) GetGitSSHKey(ctx context.Context, userID uuid.UUID) (database.GitSSHKey, error) {
return fetch(q.log, q.auth, q.db.GetGitSSHKey)(ctx, userID)
}
Expand DownExpand Up@@ -1472,6 +1486,13 @@ func (q *querier) GetUserLinkByUserIDLoginType(ctx context.Context, arg database
return q.db.GetUserLinkByUserIDLoginType(ctx, arg)
}

func (q *querier) GetUserLinksByUserID(ctx context.Context, userID uuid.UUID) ([]database.UserLink, error) {
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
return nil, err
}
return q.db.GetUserLinksByUserID(ctx, userID)
}

func (q *querier) GetUsers(ctx context.Context, arg database.GetUsersParams) ([]database.GetUsersRow, error) {
// This does the filtering in SQL.
prep, err := prepareSQLFilter(ctx, q.auth, rbac.ActionRead, rbac.ResourceUser.Type)
Expand DownExpand Up@@ -2134,6 +2155,13 @@ func (q *querier) RegisterWorkspaceProxy(ctx context.Context, arg database.Regis
return updateWithReturn(q.log, q.auth, fetch, q.db.RegisterWorkspaceProxy)(ctx, arg)
}

func (q *querier) SetDBCryptSentinelValue(ctx context.Context, value string) error {
if err := q.authorizeContext(ctx, rbac.ActionUpdate, rbac.ResourceSystem); err != nil {
return err
}
return q.db.SetDBCryptSentinelValue(ctx, value)
}

func (q *querier) TryAcquireLock(ctx context.Context, id int64) (bool, error) {
return q.db.TryAcquireLock(ctx, id)
}
Expand Down
42 changes: 42 additions & 0 deletionscoderd/database/dbfake/dbfake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,7 @@ func New() database.Store {
organizationMembers: make([]database.OrganizationMember, 0),
organizations: make([]database.Organization, 0),
users: make([]database.User, 0),
dbcryptSentinelValue: nil,
gitAuthLinks: make([]database.GitAuthLink, 0),
groups: make([]database.Group, 0),
groupMembers: make([]database.GroupMember, 0),
Expand DownExpand Up@@ -116,6 +117,7 @@ type data struct {
// New tables
workspaceAgentStats []database.WorkspaceAgentStat
auditLogs []database.AuditLog
dbcryptSentinelValue *string
files []database.File
gitAuthLinks []database.GitAuthLink
gitSSHKey []database.GitSSHKey
Expand DownExpand Up@@ -1150,6 +1152,15 @@ func (q *FakeQuerier) GetAuthorizationUserRoles(_ context.Context, userID uuid.U
}, nil
}

func (q *FakeQuerier) GetDBCryptSentinelValue(_ context.Context) (string, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
if q.dbcryptSentinelValue == nil {
return "", sql.ErrNoRows
}
return *q.dbcryptSentinelValue, nil
}

func (q *FakeQuerier) GetDERPMeshKey(_ context.Context) (string, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand DownExpand Up@@ -1392,6 +1403,18 @@ func (q *FakeQuerier) GetGitAuthLink(_ context.Context, arg database.GetGitAuthL
return database.GitAuthLink{}, sql.ErrNoRows
}

func (q *FakeQuerier) GetGitAuthLinksByUserID(_ context.Context, userID uuid.UUID) ([]database.GitAuthLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
gals := make([]database.GitAuthLink, 0)
for _, gal := range q.gitAuthLinks {
if gal.UserID == userID {
gals = append(gals, gal)
}
}
return gals, nil
}

func (q *FakeQuerier) GetGitSSHKey(_ context.Context, userID uuid.UUID) (database.GitSSHKey, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand DownExpand Up@@ -2832,6 +2855,18 @@ func (q *FakeQuerier) GetUserLinkByUserIDLoginType(_ context.Context, params dat
return database.UserLink{}, sql.ErrNoRows
}

func (q *FakeQuerier) GetUserLinksByUserID(_ context.Context, userID uuid.UUID) ([]database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
uls := make([]database.UserLink, 0)
for _, ul := range q.userLinks {
if ul.UserID == userID {
uls = append(uls, ul)
}
}
return uls, nil
}

func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams) ([]database.GetUsersRow, error) {
if err := validateDatabaseType(params); err != nil {
return nil, err
Expand DownExpand Up@@ -4791,6 +4826,13 @@ func (q *FakeQuerier) RegisterWorkspaceProxy(_ context.Context, arg database.Reg
return database.WorkspaceProxy{}, sql.ErrNoRows
}

func (q *FakeQuerier) SetDBCryptSentinelValue(_ context.Context, value string) error {
q.mutex.Lock()
defer q.mutex.Unlock()
q.dbcryptSentinelValue = &value
return nil
}

func (*FakeQuerier) TryAcquireLock(_ context.Context, _ int64) (bool, error) {
return false, xerrors.New("TryAcquireLock must only be called within a transaction")
}
Expand Down
4 changes: 2 additions & 2 deletionscoderd/database/dbgen/dbgen.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -473,7 +473,7 @@ func UserLink(t testing.TB, db database.Store, orig database.UserLink) database.
LoginType: takeFirst(orig.LoginType, database.LoginTypeGithub),
LinkedID: takeFirst(orig.LinkedID),
OAuthAccessToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
OAuthRefreshToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
OAuthRefreshToken: takeFirst(orig.OAuthRefreshToken, uuid.NewString()),
OAuthExpiry: takeFirst(orig.OAuthExpiry, database.Now().Add(time.Hour*24)),
})

Expand All@@ -486,7 +486,7 @@ func GitAuthLink(t testing.TB, db database.Store, orig database.GitAuthLink) dat
ProviderID: takeFirst(orig.ProviderID, uuid.New().String()),
UserID: takeFirst(orig.UserID, uuid.New()),
OAuthAccessToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
OAuthRefreshToken: takeFirst(orig.OAuthAccessToken, uuid.NewString()),
OAuthRefreshToken: takeFirst(orig.OAuthRefreshToken, uuid.NewString()),
OAuthExpiry: takeFirst(orig.OAuthExpiry, database.Now().Add(time.Hour*24)),
CreatedAt: takeFirst(orig.CreatedAt, database.Now()),
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
Expand Down
28 changes: 28 additions & 0 deletionscoderd/database/dbmetrics/dbmetrics.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

59 changes: 59 additions & 0 deletionscoderd/database/dbmock/dbmock.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

14 changes: 14 additions & 0 deletionscoderd/database/dump.sql
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS dbcrypt_sentinel;
Loading

[8]ページ先頭

©2009-2025 Movatter.jp