After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688041 - Don't let temporary accounts accumulate in accounts.conf and the keyring
Don't let temporary accounts accumulate in accounts.conf and the keyring
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: Kerberos
3.6.x
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-11-10 15:23 UTC by Debarshi Ray
Modified: 2016-07-22 12:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Clean up temporary accounts (eg., Kerberos) when they are stale (14.53 KB, patch)
2012-11-10 15:48 UTC, Debarshi Ray
none Details | Review
daemon, utils: Simplify saving a GKeyFile to a path (7.14 KB, patch)
2016-05-04 15:33 UTC, Debarshi Ray
committed Details | Review
media-server: Don't touch the keyring (2.78 KB, patch)
2016-05-05 15:49 UTC, Debarshi Ray
committed Details | Review
daemon: Clean up temporary accounts (eg., Kerberos) from accounts.conf (1.42 KB, patch)
2016-05-05 15:49 UTC, Debarshi Ray
none Details | Review
daemon: Don't store empty entries in the keyring (2.17 KB, patch)
2016-05-05 15:50 UTC, Debarshi Ray
none Details | Review
daemon: Move object_path_to_group to its own area (1.78 KB, patch)
2016-05-06 18:38 UTC, Debarshi Ray
committed Details | Review
daemon: Rename the variable 'group' to 'id' (1.90 KB, patch)
2016-05-06 18:38 UTC, Debarshi Ray
committed Details | Review
daemon: Refactor code to get ID from group name into a function (1.78 KB, patch)
2016-05-06 18:39 UTC, Debarshi Ray
committed Details | Review
daemon, utils: Rename goa_utils_delete_credentials_sync (3.07 KB, patch)
2016-05-06 18:40 UTC, Debarshi Ray
committed Details | Review
utils: Add goa_utils_delete_credentials_for_id_sync helper (3.35 KB, patch)
2016-05-06 18:40 UTC, Debarshi Ray
committed Details | Review
daemon: Clean up temporary accounts (eg., Kerberos) (3.75 KB, patch)
2016-05-06 18:41 UTC, Debarshi Ray
committed Details | Review
daemon: Don't store empty entries in the keyring (2.04 KB, patch)
2016-05-06 18:41 UTC, Debarshi Ray
committed Details | Review
daemon: Ensure temporary accounts are really removed from the keyring (1.60 KB, patch)
2016-07-18 13:04 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2012-11-10 15:23:14 UTC
Temporary accounts (IsTemporary=true) are specific to the machine/session and are silently disregarded after logout. eg., Kerberos accounts. They should not be allowed to accumulate in accounts.conf and the keyring.

We can get rid of all stale accounts from accounts.conf during daemon startup, and as for the keyring we can store the  credentials in the session keyring instead of the default one.
Comment 1 Debarshi Ray 2012-11-10 15:48:08 UTC
Created attachment 228625 [details] [review]
Clean up temporary accounts (eg., Kerberos) when they are stale
Comment 2 Stef Walter 2012-11-12 12:59:12 UTC
Review of attachment 228625 [details] [review]:

I don't know enough about account staleness, and the way accounts.conf works, to review this effectively.
Comment 3 Ray Strode [halfline] 2012-11-12 16:19:12 UTC
Review of attachment 228625 [details] [review]:

Fixes make sense to me.  It might be nice if the keyring stuff was a separate commit.  A few more comments below:

::: src/daemon/goadaemon.c
@@ +356,2 @@
 static void
+write_config_file (GKeyFile *key_file, const gchar *path)

having this as a separate function makes sense, I think. Though, it would be good if all the other callers of g_key_file_to_data called this new function.

@@ +452,3 @@
                       goa_debug ("ignoring account \"%s\" in file %s because it's stale",
                                  groups[n], path);
+                      g_key_file_remove_group (key_file, groups[n], NULL);

So, I think my original (wrong) thinking here was that by the end of the load, the hash table that was built up in this function would get used to scrub the keyfile right before serialization in process_config_entries. That was a mistake, the keyfile isn't serialized in process_config_entries, and looking now, that wasn't even the intent of the code, because the code is structured to allow multiple cascading config files (even though, at the moment, there's only one).

g_key_file_remove_group here seems right.

@@ +906,3 @@
               guid = g_dbus_connection_get_guid (daemon->connection);
               g_key_file_set_string (key_file, group, "SessionId", guid);
+              collection = SECRET_COLLECTION_SESSION; /* session keyring */

So this change is interesting.  We don't actually have a password to store in the keyring for temporary accounts (at the moment at least) because they're added implicitly from noticing the ccache has changed.  Certainly, if having a keyring is important, then the keyring should be a transient session keyring for temporary accounts.  I suspect the motivation for this change was stale entries getting added to the keyring? I wonder if it would make more sense to do see if credentials is empty with g_variant_n_children (or so) and avoid calling into the keyring at all?  Or maybe doing what you do here and avoiding when possible makes sense?
Comment 4 Debarshi Ray 2016-05-04 15:32:45 UTC
(In reply to Ray Strode [halfline] from comment #3)
> ::: src/daemon/goadaemon.c
> @@ +356,2 @@
>  static void
> +write_config_file (GKeyFile *key_file, const gchar *path)
> 
> having this as a separate function makes sense, I think. Though, it would be
> good if all the other callers of g_key_file_to_data called this new function.

Turns out that g_key_file_save_to_file became a thing almost a year after I wrote this code.
Comment 5 Debarshi Ray 2016-05-04 15:33:14 UTC
Created attachment 327305 [details] [review]
daemon, utils: Simplify saving a GKeyFile to a path
Comment 6 Debarshi Ray 2016-05-05 15:49:27 UTC
Created attachment 327353 [details] [review]
media-server: Don't touch the keyring
Comment 7 Debarshi Ray 2016-05-05 15:49:56 UTC
Created attachment 327354 [details] [review]
daemon: Clean up temporary accounts (eg., Kerberos) from accounts.conf
Comment 8 Debarshi Ray 2016-05-05 15:50:17 UTC
Created attachment 327355 [details] [review]
daemon: Don't store empty entries in the keyring
Comment 9 Debarshi Ray 2016-05-06 18:27:21 UTC
(In reply to Ray Strode [halfline] from comment #3)
> Review of attachment 228625 [details] [review] [review]:
> @@ +906,3 @@
>                guid = g_dbus_connection_get_guid (daemon->connection);
>                g_key_file_set_string (key_file, group, "SessionId", guid);
> +              collection = SECRET_COLLECTION_SESSION; /* session keyring */
> 
> So this change is interesting.  We don't actually have a password to store
> in the keyring for temporary accounts (at the moment at least) because
> they're added implicitly from noticing the ccache has changed.  Certainly,
> if having a keyring is important, then the keyring should be a transient
> session keyring for temporary accounts.  I suspect the motivation for this
> change was stale entries getting added to the keyring? I wonder if it would
> make more sense to do see if credentials is empty with g_variant_n_children
> (or so) and avoid calling into the keyring at all?  Or maybe doing what you
> do here and avoiding when possible makes sense?

On second thoughts, neither SECRET_COLLECTION_SESSION nor checking for empty credentials will be enough because they won't clean up the stale keyring entries that are already there. I think we need to use libsecret API to actually remove them.

We can certainly avoid storing empty credentials GVariants in the keyring, but that would be more of a cosmetic thing.
Comment 10 Debarshi Ray 2016-05-06 18:29:31 UTC
Review of attachment 327305 [details] [review]:

This looks straightforward, so I am going to push it to master. Let me know if I made a mistake.
Comment 11 Debarshi Ray 2016-05-06 18:38:31 UTC
Created attachment 327411 [details] [review]
daemon: Move object_path_to_group to its own area
Comment 12 Debarshi Ray 2016-05-06 18:38:59 UTC
Created attachment 327412 [details] [review]
daemon: Rename the variable 'group' to 'id'
Comment 13 Debarshi Ray 2016-05-06 18:39:28 UTC
Created attachment 327413 [details] [review]
daemon: Refactor code to get ID from group name into a function
Comment 14 Debarshi Ray 2016-05-06 18:40:23 UTC
Created attachment 327414 [details] [review]
daemon, utils: Rename goa_utils_delete_credentials_sync
Comment 15 Debarshi Ray 2016-05-06 18:40:53 UTC
Created attachment 327415 [details] [review]
utils: Add goa_utils_delete_credentials_for_id_sync helper
Comment 16 Debarshi Ray 2016-05-06 18:41:21 UTC
Created attachment 327416 [details] [review]
daemon: Clean up temporary accounts (eg., Kerberos)
Comment 17 Debarshi Ray 2016-05-06 18:41:48 UTC
Created attachment 327417 [details] [review]
daemon: Don't store empty entries in the keyring
Comment 18 Debarshi Ray 2016-05-06 18:50:21 UTC
I must say that I don't like the various scenarios in which goa_daemon_reload_configuration is called. For example, cleaning up the GKeyFile and committing it to disk while reloading the configuration means the GFileMonitor will call it again. Similarly, we change accounts.conf while adding or removing an account, then call goa_daemon_reload_configuration, which will end up being called once more by the GFileMonitor.

It would be nice to avoid these, but then file I/O is inherently racy. I would rather repeat a few things than miss some event from GFileMonitor, or fail to update the D-Bus objects before completing the add or remove call.
Comment 19 Ray Strode [halfline] 2016-05-09 14:05:40 UTC
Review of attachment 327411 [details] [review]:

++
Comment 20 Ray Strode [halfline] 2016-05-09 14:06:34 UTC
Review of attachment 327412 [details] [review]:

should say "Rename the variable 'group' from 'id'"
Comment 21 Ray Strode [halfline] 2016-05-09 14:42:35 UTC
Review of attachment 327413 [details] [review]:

++
Comment 22 Ray Strode [halfline] 2016-05-09 14:43:25 UTC
Review of attachment 327414 [details] [review]:

makes sense to me
Comment 23 Ray Strode [halfline] 2016-05-09 14:45:13 UTC
Review of attachment 327415 [details] [review]:

i like how incremental this patchset is.
Comment 24 Ray Strode [halfline] 2016-05-09 14:57:51 UTC
Review of attachment 327353 [details] [review]:

yay for cutting out unnecessary code!
Comment 25 Debarshi Ray 2016-05-09 16:56:50 UTC
Comment on attachment 327353 [details] [review]
media-server: Don't touch the keyring

Thanks for the reviews, halfline. Pushed to master.
Comment 26 Debarshi Ray 2016-05-09 17:01:23 UTC
(In reply to Ray Strode [halfline] from comment #20)
> Review of attachment 327412 [details] [review] [review]:
> 
> should say "Rename the variable 'group' from 'id'"

Oh, yes. Of course. Thanks for catching it.
Comment 27 Ray Strode [halfline] 2016-05-13 18:52:33 UTC
Review of attachment 327417 [details] [review]:

seems nice to me.
Comment 28 Ray Strode [halfline] 2016-05-13 19:28:59 UTC
Review of attachment 327416 [details] [review]:

I think this is okay, but I also agree with comment 18.  Right now it looks like we call reload_configuration in init, which saves the file, which will trigger the file monitor to reload the configuration again.  We could try to prevent the second reload by recording the st_mtim.tv_nsec of the file after save and only only doing the reload if it's different.  That be a little cumbersome since there is more than one config file.

Another idea is we could create the file monitor a little later after we reload configuration in init.  That would help prevent it from firing from our own writes.  Note, that after the first reload, subsequent reloads aren't likely to write to the config file.  

anyway patch looks good to me.
Comment 29 Debarshi Ray 2016-05-18 14:13:03 UTC
Comment on attachment 327414 [details] [review]
daemon, utils: Rename goa_utils_delete_credentials_sync

Pushed to master.
Comment 30 Debarshi Ray 2016-05-18 15:22:32 UTC
(In reply to Ray Strode [halfline] from comment #28)

Thanks for the review, halfline!

> Review of attachment 327416 [details] [review] [review]:
> Another idea is we could create the file monitor a little later after we
> reload configuration in init.  That would help prevent it from firing from
> our own writes.

Creating the monitor after the initial goa_daemon_reload_configuration call can cause us to miss some changes. In practice it shouldn't be a problem, but the possibility does exist, no?

> Note, that after the first reload, subsequent reloads
> aren't likely to write to the config file.  

That's a good point. This observation significantly reduces my urge to fix things. :)

> anyway patch looks good to me.

Pushed everything to master.
Comment 31 Debarshi Ray 2016-07-18 13:04:16 UTC
Created attachment 331704 [details] [review]
daemon: Ensure temporary accounts are really removed from the keyring
Comment 32 Debarshi Ray 2016-07-22 12:34:10 UTC
Comment on attachment 331704 [details] [review]
daemon: Ensure temporary accounts are really removed from the keyring

Pushed to master.