Skip to content
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

Use SQLite instead of bbolt #779

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Use SQLite instead of bbolt #779

wants to merge 10 commits into from

Conversation

adombeck
Copy link
Contributor

@adombeck adombeck commented Feb 6, 2025

Our database requirements are better met by a relational database than a key value store, so we now use SQLite instead of bbolt.

UDENG-4890

Changes done by running:

   git rm "internal/*/testdata/golden/*"
   TESTS_UPDATE_GOLDEN=1 go test ./internal/...
   git add -A
We don't use our database as a cache anymore. It's time to reflect this
in the package name.
We can't use the "AAAAATIME" placeholders anymore when using SQLite,
because the schema only allows actual timestamps.
These files were forgotten in 5555836.

Also simplify the testdata for the "pam_unix_non_existent" test case,
because we don't need multiple users and groups for that test case.
@adombeck adombeck force-pushed the UDENG-4890-use-sqlite branch from 763b8ed to 99bfaab Compare February 6, 2025 18:10
Comment on lines +65 to +73
// TODO: I don't see why we should fail here instead of just fixing the permissions.
fileInfo, err := os.Stat(dbPath)
if err != nil {
return nil, fmt.Errorf("can't stat database file: %v", err)
}
perm := fileInfo.Mode().Perm()
if perm != 0600 {
return nil, fmt.Errorf("wrong file permission for %s: %o", dbPath, perm)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the reviewer: I copied this from the old code but added this TODO comment:

	// TODO: I don't see why we should fail here instead of just fixing the permissions.

Is there a good reason for failing or should we just fix the permissions?

Comment on lines +33 to +41
// It prevents leaking of lastLogin, which is only relevant to the database.
// TODO: The only consumer of this package is the users manager, which converts the UserDB into a types.UserEntry anyway,
//
// so there is no need to hide the lastLogin field (which complicates the code).
type userRow struct {
UserDB `yaml:",inline"`
// TODO: Why do we store the last login time in the database? It's not used anywhere.
LastLogin time.Time `yaml:"last_login,omitempty"`
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@didrocks @denisonbarbosa: Do you remember why we store the last login time even though it's not used?

@adombeck adombeck changed the title Use SQLite Use SQLite instead of bbolt Feb 7, 2025
Comment on lines +1 to +12
CREATE TABLE IF NOT EXISTS users (
name TEXT NOT NULL UNIQUE,
uid INTEGER NOT NULL UNIQUE,
gid INTEGER NOT NULL,
gecos TEXT DEFAULT "",
home TEXT DEFAULT "",
shell TEXT DEFAULT "/bin/bash",
last_login DATE,
broker_id TEXT DEFAULT "",
PRIMARY KEY(uid)
);
CREATE UNIQUE INDEX "idx_user_name" ON users ("name");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jibel You mentioned in a call that you would prefer to not use the UNIQUE constraint in the schema, but I did not understand the reasoning. Can you please explain it again, so that I can update the schema and add a code comment with the reasoning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant