Skip to content

Commit

Permalink
Fix DCONF policy manager removing userdb on empty policy (#1070)
Browse files Browse the repository at this point in the history
We decided to go for this approach to support the `purge` command. Since
it's not yet fully functional and this change is breaking user sessions
that do not have at least one DCONF-related policy applied, we should
revert this change for now and consider a better way of removing the
leftover files in the future.

Closes #1002.

UDENG-3732.
  • Loading branch information
denisonbarbosa authored Aug 28, 2024
2 parents 258c929 + 8a473d6 commit db591d9
Show file tree
Hide file tree
Showing 64 changed files with 94 additions and 54 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
17 changes: 1 addition & 16 deletions internal/policies/dconf/dconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,12 @@ func (m *Manager) ApplyPolicy(ctx context.Context, objectName string, isComputer
dbsPath := filepath.Join(dconfDir, "db")
dbPath := filepath.Join(dbsPath, objectName+".d")

if !isComputer && len(entries) > 0 {
if !isComputer {
if _, err := os.Stat(filepath.Join(dbsPath, "machine.d", "locks", "adsys")); err != nil {
return errors.New(gotext.Get("machine dconf database is required before generating a policy for an user. This one returns: %v", err))
}
}

// Only clean up user databases/profiles if there are no entries to apply.
// We don't clean up the machine database because we don't know if there's any user GPO depending on it.
if !isComputer && len(entries) == 0 {
if err := os.RemoveAll(dbPath); err != nil {
return errors.New(gotext.Get("can't remove user dconf database directory: %v", err))
}
if er := os.RemoveAll(filepath.Join(dbsPath, objectName)); er != nil {
return errors.New(gotext.Get("can't remove user dconf binary database: %v", err))
}
if err := os.RemoveAll(filepath.Join(profilesPath, objectName)); err != nil {
return errors.New(gotext.Get("can't remove user dconf profile: %v", err))
}
return nil
}

// Create profiles for users only
if !isComputer {
//nolint:gosec // G301 - Profile must be readable by everyone
Expand Down
25 changes: 11 additions & 14 deletions internal/policies/dconf/dconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func TestApplyPolicy(t *testing.T) {
"Update user disabled key with value": {entries: []entry.Entry{
{Key: "com/ubuntu/category/key-s", Value: "'onekey-s-othervalue'", Meta: "s"}},
existingDconfDir: "user-with-disabled-value"},
"User empty state, with existing machine policy": {entries: []entry.Entry{}, existingDconfDir: "existing-user"},
"User empty state": {entries: []entry.Entry{}, existingDconfDir: "-"},

// Machine cases
"First boot": {entries: []entry.Entry{
Expand All @@ -57,7 +55,10 @@ func TestApplyPolicy(t *testing.T) {
"Update machine disabled key with value": {entries: []entry.Entry{
{Key: "com/ubuntu/category/key-s", Value: "'onekey-s-othervalue'", Meta: "s"}},
isComputer: true, existingDconfDir: "machine-with-disabled-value"},
"Machine empty state": {entries: []entry.Entry{}, isComputer: true, existingDconfDir: "-"},

// We still need to create an empty database even if there is no policy, otherwise DCONF will block any writes
// due to missing database profile stack file.
"No policy still generates a valid db": {entries: nil},

"Multiple keys same category": {entries: []entry.Entry{
{Key: "com/ubuntu/category/key-s", Value: "'onekey-s-othervalue'", Meta: "s"},
Expand Down Expand Up @@ -143,19 +144,19 @@ func TestApplyPolicy(t *testing.T) {
}},

// Profiles tests
"Update existing correct profile stays unchanged": {
"Update existing correct profile stays unchanged": {entries: nil,
existingDconfDir: "existing-user"},
"Update existing correct profile with trailing spaces are removed": {
"Update existing correct profile with trailing spaces are removed": {entries: nil,
existingDconfDir: "existing-user-with-trailing-spaces"},
"Update existing profile without needed db append them": {
"Update existing profile without needed db append them": {entries: nil,
existingDconfDir: "existing-user-no-adsysdb"},
"Update existing profile without needed db, trailine lines are removed": {
"Update existing profile without needed db, trailine lines are removed": {entries: nil,
existingDconfDir: "existing-user-no-adsysdb-trailing-newlines"},
"Update existing profile with partial db append them without repetition": {
"Update existing profile with partial db append them without repetition": {entries: nil,
existingDconfDir: "existing-user-one-adsysdb-partial"},
"Update existing profile with wrong order appends them in correct order": {
"Update existing profile with wrong order appends them in correct order": {entries: nil,
existingDconfDir: "existing-user-one-adsysdb-reversed-end"},
"Update existing profile eliminates adsys DB repetitions": {
"Update existing profile eliminates adsys DB repetitions": {entries: nil,
existingDconfDir: "existing-user-adsysdb-repetitions"},

// non adsys content
Expand Down Expand Up @@ -194,10 +195,6 @@ func TestApplyPolicy(t *testing.T) {

dconfDir := t.TempDir()

if tc.entries == nil {
tc.entries = []entry.Entry{{Key: "com/ubuntu/category/key-s", Value: "'onekey-s-othervalue'", Meta: "s"}}
}

if tc.existingDconfDir == "" {
tc.existingDconfDir = "machine-base"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:ubuntu
system-db:machine
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[com/ubuntu/category]
key-s='onekey-s-othervalue'

Original file line number Diff line number Diff line change
@@ -1 +1 @@
/com/ubuntu/category/key-s

This file was deleted.

This file was deleted.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine

0 comments on commit db591d9

Please sign in to comment.