Bug 33842 - Writing of config files should be an atomic operation
Writing of config files should be an atomic operation
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UCR
UCS 3.2
Other Linux
: P5 normal (vote)
: UCS 3.2-1
Assigned To: Stefan Gohmann
Philipp Hahn
:
: 33901 (view as bug list)
Depends on:
Blocks: 34241
  Show dependency treegraph
 
Reported: 2014-01-06 06:35 CET by Stefan Gohmann
Modified: 2014-03-04 12:56 CET (History)
2 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments
Testcase (1.33 KB, text/plain)
2014-02-14 13:31 CET, Philipp Hahn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Gohmann univentionstaff 2014-01-06 06:35:31 CET
Currently the writing of an UCR config file is not an atomic operation. If it is a large config file it could take some time writing this file. This could led to an incomplete config file. See also Bug #33050.

If this issue has been solved the workaround added with r46886 in ucs-test/tests/10_ldap/60failedldif should be removed.
Comment 1 Stefan Gohmann univentionstaff 2014-01-14 12:13:39 CET
*** Bug 33901 has been marked as a duplicate of this bug. ***
Comment 2 Stefan Gohmann univentionstaff 2014-02-13 21:50:25 CET
This also happens during the UCS 3.2-1 installation tests.
Comment 3 Stefan Gohmann univentionstaff 2014-02-14 07:08:31 CET
Changelog: r47802
Fixed in UCS 3.2-1: r47796 + r47797 + r47801

UCR now writes a temporary file first. The file is renamed to the target in a second step.

I've checked the permissions between the old and new version:

Old version:
$ rm /etc/ldap/slapd.conf ; ucr commit /etc/ldap/slapd.conf; ls -la /etc/ldap/slapd.conf
Multifile: /etc/ldap/slapd.conf
-rw-r--r-- 1 root root 15689 10. Feb 19:02 /etc/ldap/slapd.conf

$ chmod 600 /etc/ldap/slapd.conf; ucr commit /etc/ldap/slapd.conf; ls -la /etc/ldap/slapd.conf*
Multifile: /etc/ldap/slapd.conf
-rw------- 1 root root 15689 10. Feb 19:02 /etc/ldap/slapd.conf

$ rm /etc/hostname ; ucr commit /etc/hostname; ls -la /etc/hostname*
File: /etc/hostname
-rw-r--r-- 1 root root 10 10. Feb 19:02 /etc/hostname
$ chmod 600 /etc/hostname; ucr commit /etc/hostname; ls -la /etc/hostname 
File: /etc/hostname
-rw-r--r-- 1 root root 10 10. Feb 19:02 /etc/hostname

$ rm /etc/libnss-ldap.conf; ucr commit /etc/libnss-ldap.conf; ls -la /etc/libnss-ldap.conf
File: /etc/libnss-ldap.conf
-r--r----- 1 messagebus root 743 10. Feb 19:03 /etc/libnss-ldap.conf
$ chmod 777 /etc/libnss-ldap.conf; ucr commit /etc/libnss-ldap.conf; ls -la /etc/libnss-ldap.conf
File: /etc/libnss-ldap.conf
-r--r----- 1 messagebus root 743 10. Feb 19:04 /etc/libnss-ldap.conf


New version:

$ rm /etc/ldap/slapd.conf ; ucr commit /etc/ldap/slapd.conf; ls -la /etc/ldap/slapd.conf
Multifile: /etc/ldap/slapd.conf
-rw-r--r-- 1 root root 15927 Feb 14 00:28 /etc/ldap/slapd.conf
$ chmod 600 /etc/ldap/slapd.conf; ucr commit /etc/ldap/slapd.conf; ls -la /etc/ldap/slapd.conf*
Multifile: /etc/ldap/slapd.conf
-rw------- 1 root root 15927 Feb 14 00:28 /etc/ldap/slapd.conf

$ rm /etc/hostname ; ucr commit /etc/hostname; ls -la /etc/hostname*
File: /etc/hostname
-rw-r--r-- 1 root root 10 Feb 14 00:28 /etc/hostname
$ chmod 600 /etc/hostname; ucr commit /etc/hostname; ls -la /etc/hostname 
File: /etc/hostname
-rw-r--r-- 1 root root 10 Feb 14 00:29 /etc/hostname

$ rm /etc/libnss-ldap.conf; ucr commit /etc/libnss-ldap.conf; ls -la /etc/libnss-ldap.conf
File: /etc/libnss-ldap.conf
-r--r----- 1 messagebus root 743 Feb 14 00:31 /etc/libnss-ldap.conf
$ chmod 777 /etc/libnss-ldap.conf; ucr commit /etc/libnss-ldap.conf; ls -la /etc/libnss-ldap.conf
File: /etc/libnss-ldap.conf
-r--r----- 1 messagebus root 743 Feb 14 00:31 /etc/libnss-ldap.conf
Comment 4 Stefan Gohmann univentionstaff 2014-02-14 07:38:24 CET
It seems to be a problem with the python interface.
Comment 5 Stefan Gohmann univentionstaff 2014-02-14 09:25:46 CET
(In reply to Stefan Gohmann from comment #4)
> It seems to be a problem with the python interface.

That was a problem during the file register.

Two more commits: r47803 + r47804
Comment 6 Janek Walkenhorst univentionstaff 2014-02-14 10:25:36 CET
Temporary files should be created securely by using the tempfile module.
<http://docs.python.org/2/library/tempfile.html>
For example the mkstemp or NamedTemporaryFile functions. (Not mktemp!)
Comment 7 Philipp Hahn univentionstaff 2014-02-14 10:34:13 CET
(In reply to Janek Walkenhorst from comment #6)
> Temporary files should be created securely by using the tempfile module.
> <http://docs.python.org/2/library/tempfile.html>
> For example the mkstemp or NamedTemporaryFile functions. (Not mktemp!)

No, as already discussed with Stefan in private: UCR must handle any previously (not) existing file, umask setting, etc; using tempfile is a real pain here, as the file mode is always 0600.
Comment 8 Philipp Hahn univentionstaff 2014-02-14 13:22:25 CET
(r47796,47797,47801,47803,47804)

FAIL: self.to_file is not reset in at leas two error path.
FAIL: May leave behind temporary files on errors.
(these two errors are rather pedantic, but should be cleaned up - maybe as a follow up+cleanup instead of now?)

OK: ChangeLog
OK: ucs-test -s ucr -E dangerous
OK: ucr register 33842
Comment 9 Philipp Hahn univentionstaff 2014-02-14 13:31:42 CET
Created attachment 5796 [details]
Testcase

Create Single- and Multi-Template-File in all combinations → ucs-test?
Comment 10 Stefan Gohmann univentionstaff 2014-02-14 15:46:05 CET
(In reply to Philipp Hahn from comment #8)
> (r47796,47797,47801,47803,47804)
> 
> FAIL: self.to_file is not reset in at leas two error path.
> FAIL: May leave behind temporary files on errors.
> (these two errors are rather pedantic, but should be cleaned up - maybe as a
> follow up+cleanup instead of now?)

That should be fixed with r47817.
Comment 11 Philipp Hahn univentionstaff 2014-02-14 18:50:43 CET
OK: r47817
OK: univention-config-registry_9.0.6-4.452.201402141359
ADDED: ucs-test: 03_ucr/{51file_permissions,52atomic_ucr}
  r47831 | Bug #33842: test/ucr: Add atomic commit tests
  ucs-test-4.0.161-38.675.201402141844
OK: ucs-test -s ucr -E dangerous
Comment 12 Stefan Gohmann univentionstaff 2014-02-18 06:35:07 CET
UCS 3.2-1 has been released:
 http://docs.univention.de/release-notes-3.2-1-en.html
 http://docs.univention.de/release-notes-3.2-1-de.html

If this error occurs again, please use "Clone This Bug".