-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor/nullable repo key #3826
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
a0e5316
2a0dc9d
44c37bf
616d2a6
7ee53d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,13 @@ func (d *SqlDb) ApplyMigration(migration db.Migration) error { | |
| } | ||
| } | ||
|
|
||
| if d.GetDialect() == util.DbDriverSQLite { | ||
| _, err = d.Sql().Exec("PRAGMA foreign_keys = OFF") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Medium — integrity / defense-in-depth
Impact: After a failed migration, subsequent operations on the same pool connection can insert/update rows that violate FK constraints, weakening DB integrity and complicating exploitation of other bugs. Fix direction: |
||
| if err != nil { | ||
|
Comment on lines
+193
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SQLite foreign keys are turned off before starting the transaction, but turned back on only after a successful commit. Several earlier return paths in this function (e.g., begin failure, pre/post-apply errors, insert failure) bypass the re-enable step, so a migration error can leave the process with foreign key enforcement disabled. Useful? React with 👍 / 👎. |
||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| tx, err := d.Sql().Begin() | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -249,7 +256,16 @@ func (d *SqlDb) ApplyMigration(migration db.Migration) error { | |
|
|
||
| fmt.Println() | ||
|
|
||
| return tx.Commit() | ||
| res := tx.Commit() | ||
|
|
||
| if d.GetDialect() == util.DbDriverSQLite { | ||
| _, err = d.Sql().Exec("PRAGMA foreign_keys = ON") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| return res | ||
| } | ||
|
|
||
| // TryRollbackMigration attempts to rollback the database to an earlier version if a rollback exists | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- do nothing | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The rollback loader resolves files as Useful? React with 👍 / 👎. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| {{if .Sqlite}} | ||
| create table project__repository_dg_tmp | ||
| ( | ||
| id INTEGER | ||
| primary key autoincrement, | ||
| project_id INTEGER not null | ||
| references project | ||
| on delete cascade, | ||
| git_url TEXT not null, | ||
| ssh_key_id INTEGER | ||
| references access_key, | ||
| name VARCHAR(255), | ||
| git_branch VARCHAR(255) default '' not null | ||
| ); | ||
|
|
||
| insert into project__repository_dg_tmp(id, project_id, git_url, ssh_key_id, name, git_branch) | ||
| select id, project_id, git_url, ssh_key_id, name, git_branch | ||
| from project__repository; | ||
|
|
||
| drop table project__repository; | ||
|
|
||
| alter table project__repository_dg_tmp rename to project__repository; | ||
|
|
||
| create index project__repository__project_id on project__repository (project_id); | ||
|
|
||
| create index project__repository__ssh_key_id on project__repository (ssh_key_id); | ||
| {{else if .Mysql}} | ||
| alter table project__repository modify ssh_key_id int null; | ||
| {{else if .Postgresql}} | ||
| alter table public.project__repository alter column ssh_key_id drop not null; | ||
| {{end}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,12 +42,14 @@ func (c GoGitClient) getAuthMethod(r GitRepository) (transport.AuthMethod, error | |
| switch r.Repository.SSHKey.Type { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Severity: Medium — denial of service (availability)
Impact: Process panic → denial of service for the Semaphore instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Severity: High (availability / DoS)
Fix direction: Guard the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Medium — denial of service (nil dereference) Repositories can now have Impact: Any user who can create/update a repo to omit the key (or any code path that loads such a row) can trigger repeated crashes against endpoints using the Go Git client (e.g. branch listing), affecting availability. Fix direction: Guard at the top of |
||
| case db.AccessKeySSH: | ||
|
|
||
| install, err := c.keyInstaller.Install(r.Repository.SSHKey, db.AccessKeyRoleGit, r.Logger) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if r.Repository.SSHKey != nil { | ||
| install, err := c.keyInstaller.Install(*r.Repository.SSHKey, db.AccessKeyRoleGit, r.Logger) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| defer install.Destroy() | ||
| defer install.Destroy() | ||
| } | ||
|
|
||
| var sshKeyBuff = r.Repository.SSHKey.SshKey.PrivateKey | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Severity: Medium — denial of service / unsafe git URL handling
For
RepositoryHTTP,GetGitURL(false)usesr.SSHKey.Typeandr.SSHKey.LoginPasswordwithout checkingSSHKey != nil. With nullablessh_key_id,SSHKeycan be nil when this runs (e.g. cmd-gitGetGitURL(false)), causing a nil pointer panic or undefined behavior.Impact: Same DoS class as
GoGitClient.getAuthMethod; also risks incorrect clone URLs if execution continued without crashing.