Bug #13749
closedGetting avatar from openldap seems to be broken
Description
I created a user with the following ldif:
dn: cn=dgoetz,ou=users,dc=localdomain objectClass: inetOrgPerson cn: dgoetz sn: Goetz description: Dirk Goetz userPassword: {SSHA}SmI4N/QECJfMFprv9sMnTD7KZUq46Yw8 givenName: Dirk mail: dgoetz@localdomain uid: dgoetz jpegPhoto:< file:///root/dgoetz.jpg
When I login with the user the avatar is downloaded and the file is created but is not a valid picture.
# file /var/lib/foreman/public/assets/avatars/6e15a0e85405ddd9f25abc3aee0b212ea2ca6bfb.jpg /var/lib/foreman/public/assets/avatars/6e15a0e85405ddd9f25abc3aee0b212ea2ca6bfb.jpg: data
If I search the ldap I get:
# dgoetz, users, localdomain dn: cn=dgoetz,ou=users,dc=localdomain objectClass: inetOrgPerson cn: dgoetz sn: Goetz description: Dirk Goetz userPassword:: e1NTSEF9U21JNE4vUUVDSmZNRnBydjlzTW5URDdLWlVxNDZZdzg= givenName: Dirk mail: dgoetz@localdomain uid: dgoetz jpegPhoto:: /9j/4AAQSkZJRgABAQEBZwFnAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAA BtbnRyUkdCIFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAQA A9tYAAQAAAADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAABFjcHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaA AACGAAAABRnWFlaAAACLAAAABRiWFlaAAACQAAAABRkbW5kAAACVAAAAHBkbWRkAAACxAAAAIh2dW VkAAADTAAAAIZ2aWV3AAAD1AAAACRsdW1pAAAD+AAAABRtZWFzAAAEDAAAACR0ZWNoAAAEMAAAAAx yVFJDAAAEPAAACAxnVFJDAAAEPAAACAxiVFJDAAAEPAAACAx0ZXh0AAAAAENvcHlyaWdodCAoYykg MTk5OCB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AAgBAgEBPwEH/8QAKRAAAgEDAgQFBQAAAAAAAAAAAQIDAAQRITEFEBITIiMyUWFDUnGBof/aAAgB AQAGPwKjCmrKMt8URsw59yLvPcHGFjbHh+aEjPI7OPq7jli4fu3RGVto/Ufz7CpZuNPNYhdYGtCcg fb+6lxbCXhhPlwE+JF23pns3IkT1wyaMtX11KcvJMx/ugrUZ5PNbP0OydBx7V//xAAhEAEAAQMDBQ EAAAAAAAAAAAABEQAhMRBBUWFxgZHBsf/aAAgBAQABPyGohA6ZiDipTNyfdYU2KYscHN6G0G0N5h9 ukyGTQNn9D4mhWchwy7TPVzxRCeSPMAi+7EsmVoAdEbu43OpTM7wOCzsAB4q8gs5xUqeskijIflf/ 2gAMAwEAAgADAAAAEIBJBJJIBP/EABQRAQAAAAAAAAAAAAAAAAAAAED/2gAIAQMBAT8QB//EABQRA QAAAAAAAAAAAAAAAAAAAED/2gAIAQIBAT8QB//EAB0QAQEAAgIDAQAAAAAAAAAAAAERACExYRBBUZ H/2gAIAQEAAT8QzhIjdTppqx61zgv7AdtHgPsd/j88mGSFiSuhFBbtwLMaiEaB34tg7tFqKdMj7GM QmJH+EYqhXKyfriMZJ8dnIbYLCVxzogN3CCivsTgY6xhJuzNA6ZPgw1uKCor7nYY7QAKVPrs5/9k=
And if I copy the base64 string to a file, join the lines and decode it, I get a valid jpeg back.
# cat /tmp/base64 | base64 -d > /tmp/dgoetz.jpg # file /tmp/dgoetz.jpg /tmp/dgoetz.jpg: JPEG image data, JFIF standard 1.01
So something seems to be broken, but looking in the code I have no idea what. When I tried to remove the decoding and output the file in binary I already got some content not maching the base64 string and if output was not written binary I got an empty file. Also removing the to_utf8 for testing showed the same result.
Updated by John Beranek over 7 years ago
I'm seeing this issue too, the avatars obtained from our Active Directory are not being saved correctly:
$ od -c /var/lib/foreman/public/assets/avatars/54cf8135e2114eb915bcbfaf162f324eeab26293.jpg [18:14:38]
0000000 $ R 005 034 p 276 \b 257 ( 270 %
0000013
There is also another issue, as when the Foreman pages try to download the avatar image they get a 404:
foreman-ssl_access_ssl.log:10.4.4.48 - - [22/Apr/2017:18:12:44 +0100] "GET /images/avatars/54cf8135e2114eb915bcbfaf162f324eeab26293.jpg HTTP/1.1" 404 1564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
This is with Foreman 1.14.3/Katello 3.3.1
Updated by Thomas Steudten over 7 years ago
- Priority changed from Low to Normal
Hi
foreman-1.15.0 contains the same bug. I tried a little bit to find out what happen.
My fix is this:
Edit in this file: /usr/share/foreman/app/models/auth_sources/auth_source_ldap.rb like this:
def store_avatar(avatar)
#avatar = avatar.to_utf8
avatar_hash = Digest::SHA1.hexdigest(avatar)
avatar_file = "#{avatar_path}/#{avatar_hash}.jpg"
unless FileTest.exist? avatar_file
FileUtils.mkdir_p(avatar_path)
#File.open(avatar_file, 'wb') { |f| f.write(Base64.decode64(avatar)) }
File.open(avatar_file, 'wb') { |f| f.write(avatar) }
end
avatar_hash
end
Maybe you have to add one more symbolic-link here: /var/lib/foreman/public/images -> assets.
Keep sure, to set the owner and group to foreman:foreman.
Restart foreman and httpd and it will give you the avatar picture back.
file 4043ebc4b8943415326ff6d78f887c7a040ebb62.jpg
4043ebc4b8943415326ff6d78f887c7a040ebb62.jpg: JPEG image data, JFIF standard 1.01
Thomas
Updated by Tomer Brisker about 7 years ago
- Has duplicate Bug #15127: Photo attribute configured for LDAP source, image not displayed added
Updated by Dirk Götz almost 7 years ago
I can confirm the mentioned fix works.
For the code change I could create a pull request, but I have no idea where the symlink has to be created or if it would be better to change the URL instead (where I could not find the origin of).
Updated by Derek Wright almost 7 years ago
Did some testing on this and the issue appears to be that net/ldap
will automatically convert the base64 data to binary representation (Net::BER::BerIdentifiedString
). We can check the type by doing the following in app/models/auth_sources/auth_source_ldap.rb(line 218)
:
avatar = avatar.instance_of?(Net::BER::BerIdentifiedString) ? avatar : avatar.to_utf8
Now, where I'm getting hung up is how we want to handle writing the data, I don't want to move the base64 decode up sooner in the logic as it will increase overhead on every login. There is also the possibility to maybe use MimeMagic and detect the current filetype and if its not image/jpeg, overwrite the file (this will also have a small performance penalty). Looking for some thoughts on how best to implement that part from the Devs.
app/models/auth_sources/auth_source_ldap.rb(line 224)
:
File.open(avatar_file, 'wb') { |f| f.write(Base64.decode64(avatar)) } # This base64 will only need to be done if its NOT instance_of Net::BER::BerIdentifiedString
Updated by The Foreman Bot over 6 years ago
- Status changed from New to Ready For Testing
- Assignee set to Daniel Lobato Garcia
- Pull request https://github.com/theforeman/foreman/pull/5630 added
Updated by Tomer Brisker over 6 years ago
- Translation missing: en.field_release set to 353
Updated by Daniel Lobato Garcia over 6 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 87194fab8d485084cbad7c407a6579d9618aac56.
Updated by Ondřej Pražák over 6 years ago
- Triaged set to No
- Pull request https://github.com/theforeman/foreman/pull/5717 added
Updated by Ondřej Pražák over 6 years ago
- Translation missing: en.field_release changed from 353 to 330