Bug 51608 - Wrong file ownership for serviceprovider_enabled_groups.json
Wrong file ownership for serviceprovider_enabled_groups.json
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: SAML
UCS 4.4
All Linux
: P5 normal (vote)
: UCS 4.4-6-errata
Assigned To: Erik Damrose
Felix Botner
https://git.knut.univention.de/univen...
:
: 51837 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2020-07-03 18:09 CEST by Frederik Spiegel
Modified: 2020-10-14 14:11 CEST (History)
5 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.257
Enterprise Customer affected?: Yes
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2020090821000357
Bug group (optional): Regression
Max CVSS v3 score:
best: Patch_Available+


Attachments
patch (1017 bytes, patch)
2020-07-03 23:24 CEST, Florian Best
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederik Spiegel 2020-07-03 18:09:05 CEST
The new listener script univention-saml-groups.py which creates / updates the "SAML SP to LDAP groups" mapping in /etc/simplesamlphp/serviceprovider_enabled_groups.json first creates a temporary file in /tmp/ where it sets the correct file permissions and ownership and then uses shutil.move() to move that to the final destination in /etc/simplesamlphp/

This only works correctly if the /tmp/ and /etc/simplesamlphp/ directories are on the same filesystem, because shutl.move() uses os.rename() in this case, which keeps all file metadata.
Hoever, if these two directories are on separat filesystems, shutil.move() by default uses shutil.copy2() to copy the file to the new location and then deletes the source file.
According to the python documentation "copy2() uses copystat() to copy the file metadata." which in turn states that it doesn't copy the file owners.
("Copy the permission bits, last access time, last modification time, and flags from src to dst. On Linux, copystat() also copies the “extended attributes” where possible. The file contents, owner, and group are unaffected.")

So the target file gets created with default owner and user, in our cases this was "root.nogroup".
This has the effect that simplesamlphp process cannot read the file, as the following syslog entries show:

simplesamlphp[21022]: 3 [5bf27ee2ac] SimpleSAML_Error_Exception: Error 2 - file_get_contents(/etc/simplesamlphp/serviceprovider_enabled_groups.json): failed to open stream: Permission denied


Our hotfix was to change the variable "tmp_path" in univention-saml-groups.py as follows:
tmp_path = path + ".tmp"

So it creates the temporary file in the same directory as the final .json file and then just moves it inside that directory, keeping mode and ownership.
Comment 1 Florian Best univentionstaff 2020-07-03 23:24:33 CEST
Created attachment 10414 [details]
patch

Thank you for the detailed bug report!
Comment 3 Erik Damrose univentionstaff 2020-09-10 14:45:55 CEST
*** Bug 51837 has been marked as a duplicate of this bug. ***
Comment 4 Erik Damrose univentionstaff 2020-10-06 14:21:45 CEST
9c973f65 + 8679cb86 Fix owner for SAML group permission file
e6612975 yaml
univention-saml 6.0.2-56A~4.4.0.202010061414
Comment 5 Erik Damrose univentionstaff 2020-10-06 14:38:30 CEST
7d1d1301 ucs-test 9.0.5-11
Comment 6 Erik Damrose univentionstaff 2020-10-06 14:53:23 CEST
841e9976 Set correct permissions in postinst
univention-saml 6.0.2-57A~4.4.0.202010061451
Comment 7 Erik Damrose univentionstaff 2020-10-06 15:07:11 CEST
1900ff37 Fix styling
univention-saml 6.0.2-58A~4.4.0.202010061504
Comment 8 Felix Botner univentionstaff 2020-10-06 15:59:26 CEST
TODO merge request

OK - yaml
OK - update (permissions fixed)

before
ls -la /etc/simplesamlphp/serviceprovider_enabled_groups.json 
-rwxrwxrwx 1 samlcgi samlcgi 184 Okt  6 15:01 /etc/simplesamlphp/serviceprovider_enabled_groups.json
after
ls -al /etc/simplesamlphp/serviceprovider_enabled_groups.json 
-rw------- 1 samlcgi samlcgi 184 Okt  6 15:01 /etc/simplesamlphp/serviceprovider_enabled_groups.json

OK - installation (permissions correct)
OK - test
Comment 10 Felix Botner univentionstaff 2020-10-07 10:03:17 CEST
OK
Comment 12 Florian Best univentionstaff 2020-10-14 14:11:14 CEST
Just for the notes, during upgrade I see the following message:

Calling joinscript 91univention-saml.inst ...
2020-10-10 17:52:36.670087897+02:00 (in joinscript_init)
Joinscript 91univention-saml.inst finished with exitcode 1
chmod: Zugriff auf '/etc/simplesamlphp/serviceprovider_enabled_groups.json' nicht möglich: Datei oder Verzeichnis nicht gefunden
chown: Zugriff auf '/etc/simplesamlphp/serviceprovider_enabled_groups.json' nicht möglich: Datei oder Verzeichnis nicht gefunden
stunnel4.service is not a native service, redirecting to systemd-sysv-install.