Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift backend support #207

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

constantinius
Copy link
Contributor

Adding OpenStack Swift cache backend using modified keystone-client and swift-client libraries.

@constantinius
Copy link
Contributor Author

I used these libraries as a baseline to access swift/keystone:

I'd love to have some feedback on how I integrated it into mapcache. Currently this functionality is not really tested in production, so this PR stays a draft.

keystone-client uses json-c (added as cmake dependency), I'm not sure if this is done correctly. I'm aware, that mapcache ships with its own JSON implementation (cJSON), but I did not yet make an effort to replace either.

Copy link
Member

@tbonfort tbonfort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going into the actual swift logic, here are a few comments. The error checking and connection pool releasing applies to the whole cache_swift.c file, not just the reviewed lines.

@@ -0,0 +1,200 @@
#ifndef KEYSTONE_CLIENT_H_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing licence on imported files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

Besides: Do you think that it is alright to include a source file like that? The repo says it is GPL v3.


keystone_err = keystone_authenticate(conn->keystone_context, cache->auth_url, cache->tenant, cache->username, cache->password);
if (keystone_err != KSERR_SUCCESS) {
ctx->set_error(ctx, 500, "failed to keystone_authenticate()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error conditions should halt execution. add a return here and after all ctx->set_error calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check all possible paths and fix these issues.

}
}

mapcache_connection_pool_release_connection(ctx, pc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called before all exit paths (i.e. it is currently not called on error condition exits)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll need to check those as-well.

*
* Project: MapServer
* Purpose: MapCache tile caching support file: swift cache backend.
* Author: Michael Downey and the MapServer team.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct author?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No 😅

@constantinius
Copy link
Contributor Author

@tbonfort

I updated the source code and now support keystone v3 API.
In principle, this works, we already use it in a staging environment. Unfortuately, we run into realloc(): invalid next size when using with mapcache_seed (and sometimes in the Apache module too).

With gdb, we got this stack trace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007fde75254801 in __GI_abort () at abort.c:79
#2  0x00007fde7529d897 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7fde753cab9a "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#3  0x00007fde752a490a in malloc_printerr (str=str@entry=0x7fde753c8ed3 "realloc(): invalid next size") at malloc.c:5350
#4  0x00007fde752a99b4 in _int_realloc (av=av@entry=0x7fde5c000020, oldp=oldp@entry=0x7fde5c024080, oldsize=oldsize@entry=64, nb=nb@entry=64)
    at malloc.c:4534
#5  0x00007fde752acf9b in __GI___libc_realloc (oldmem=0x7fde5c024090, bytes=56) at malloc.c:3230
#6  0x00007fde7719376e in swift_set_object () from /usr/lib/x86_64-linux-gnu/libmapcache.so.1
#7  0x00007fde7716fb62 in ?? () from /usr/lib/x86_64-linux-gnu/libmapcache.so.1
#8  0x00007fde77165f4e in mapcache_cache_tile_exists () from /usr/lib/x86_64-linux-gnu/libmapcache.so.1
#9  0x00005602271e7d7d in examine_tile ()
#10 0x00005602271e807b in cmd_recurse ()
#11 0x00005602271e866c in feed_worker ()
#12 0x00005602271e872b in ?? ()
#13 0x00007fde6dbb96db in start_thread (arg=0x7fde6257a700) at pthread_create.c:463
#14 0x00007fde7533588f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

This points to an issue in swift_set_object, where I basically duplicate a string (the re-allocation). From my perspective it looks clean but I'm suspecting, that there is some issue with connection pooling (construction, destruction), but I can't figure it out. Could you maybe have a look at it and tell me if I use the interfaces correctly?

@constantinius
Copy link
Contributor Author

I think I found the issue, a classic buffer overflow (re-)allocating strlen bytes, but strcpy writes a final '\0' character out of the allocated area.

This PR is good to go from my perspective. @tbonfort please let me know if need anything in addition.

@constantinius constantinius marked this pull request as ready for review April 2, 2020 12:24
Base automatically changed from master to main January 15, 2021 22:57
@jbo-ads
Copy link
Member

jbo-ads commented Mar 10, 2021

Have you figured out the causes of failed checks?

@jmckenna jmckenna added this to the 1.12.0 milestone Mar 10, 2021
@constantinius
Copy link
Contributor Author

@jbo-ads

Yes, I think I solved the issues

@jbo-ads
Copy link
Member

jbo-ads commented Apr 6, 2021

I've checked your updates following @tbonfort's comments and it looks OK in my opinion.

About licenses, I think there is nothing wrong with using LGPLv3 source code in a bigger MIT licensed project.

I don't know the prefered way of mentioning it: copy license text at the beginning of related code (only swift-client.h and swift-client.c, since no license is mentioned in keystone-client repo), or include it in MapCache LICENSE file with a note indicating that only swift-client is concerned with LGPLv3. @jmckenna any advice on this?

@jmckenna
Copy link
Member

jmckenna commented Apr 6, 2021

@jbo-ads I prefer the second option, but I think it should be noted in several places:

  • source LICENSE file
  • source README.rst (so it displays nicely on Github)
  • add a 'copyright.txt' file in the MapCache documentation, similar to the one for MapServer at https://mapserver.org/copyright.html (so web users can see the full license for MapCache)

@jbo-ads
Copy link
Member

jbo-ads commented Apr 6, 2021

@constantinius - Please don't forget to update the documentation with this new feature: https://mapserver.org/mapcache/caches.html

@Schpidi
Copy link
Member

Schpidi commented Nov 19, 2021

Unfortunately the latest commit breaks building for me:

[ 95%] Linking C executable mapcache.fcgi
cd /build/mapcache-1.10.0/obj-x86_64-linux-gnu/cgi && /usr/bin/cmake -E cmake_link_script CMakeFiles/mapcache.fcgi.dir/link.txt --verbose=1
/usr/bin/cc -g -O2 -fdebug-prefix-map=/build/mapcache-1.10.0=. -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wdate-time -D_FORTIFY_SOURCE=2 -Wall -Werror=declaration-after-statement  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -rdynamic CMakeFiles/mapcache.fcgi.dir/mapcache.c.o  -o mapcache.fcgi -Wl,-rpath,/build/mapcache-1.10.0/obj-x86_64-linux-gnu: ../libmapcache.so.1.10.0 -lfcgi -lpng -lz -ljpeg -lcurl -lapr-1 -laprutil-1 -lpixman-1 -lgdal -lpcre -lsqlite3 -lpq -ltiff -ljson-c -ldl -lm 
../libmapcache.so.1.10.0: undefined reference to `keystone_get_service_url'
../libmapcache.so.1.10.0: undefined reference to `keystone_set_auth_version'
../libmapcache.so.1.10.0: undefined reference to `keystone_start'
../libmapcache.so.1.10.0: undefined reference to `keystone_end'
../libmapcache.so.1.10.0: undefined reference to `keystone_authenticate'
../libmapcache.so.1.10.0: undefined reference to `keystone_get_auth_token'
../libmapcache.so.1.10.0: undefined reference to `keystone_set_debug'
collect2: error: ld returned 1 exit status

@jmckenna jmckenna removed this from the 1.12.0 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants