From: Yuval Lifshitz Date: Sun, 1 Nov 2020 10:49:26 +0000 (+0200) Subject: rgw/lua: support packages via luarocks X-Git-Tag: v16.1.0~218^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6ef3e52a3f15465726255ba55f6d5fc89222a92f;p=ceph.git rgw/lua: support packages via luarocks Signed-off-by: Yuval Lifshitz --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a81c9e1003..86510ac8c02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -382,6 +382,7 @@ option(WITH_RADOSGW_BEAST_FRONTEND "Rados Gateway's Beast frontend is enabled" O option(WITH_RADOSGW_BEAST_OPENSSL "Rados Gateway's Beast frontend uses OpenSSL" ON) option(WITH_RADOSGW_AMQP_ENDPOINT "Rados Gateway's pubsub support for AMQP push endpoint" ON) option(WITH_RADOSGW_KAFKA_ENDPOINT "Rados Gateway's pubsub support for Kafka push endpoint" ON) +option(WITH_RADOSGW_LUA_PACKAGES "Rados Gateway's support for dynamically adding lua packagess" ON) if(WITH_RADOSGW) find_package(EXPAT REQUIRED) @@ -581,6 +582,10 @@ if(WITH_SEASTAR) list(APPEND BOOST_COMPONENTS filesystem timer) endif() +if(WITH_RADOSGW AND WITH_RADOSGW_LUA_PACKAGES) + list(APPEND BOOST_COMPONENTS filesystem) +endif() + set(Boost_USE_MULTITHREADED ON) # require minimally the bundled version if(WITH_SYSTEM_BOOST) diff --git a/ceph.spec.in b/ceph.spec.in index 9ac67112f486..f2ec3c04c5a7 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -81,6 +81,19 @@ %endif %endif +%if 0%{?suse_version} +%if !0%{?is_opensuse} +# SLE does not support luarocks +%bcond_with lua_packages +%else +%global luarocks_package_name lua53-luarocks +%bcond_without lua_packages +%endif +%else +%global luarocks_package_name luarocks +%bcond_without lua_packages +%endif + %{!?_udevrulesdir: %global _udevrulesdir /lib/udev/rules.d} %{!?tmpfiles_create: %global tmpfiles_create systemd-tmpfiles --create} %{!?python3_pkgversion: %global python3_pkgversion 3} @@ -187,6 +200,9 @@ BuildRequires: librabbitmq-devel %if 0%{with kafka_endpoint} BuildRequires: librdkafka-devel %endif +%if 0%{with lua_packages} +BuildRequires: %{luarocks_package_name} +%endif %if 0%{with make_check} BuildRequires: jq BuildRequires: libuuid-devel @@ -1194,6 +1210,9 @@ ${CMAKE} .. \ %else -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF \ %endif +%if 0%{without lua_packages} + -DWITH_RADOSGW_LUA_PACKAGES=OFF +%endif %if 0%{with zbd} -DWITH_ZBD=ON \ %endif diff --git a/debian/control b/debian/control index 4a89172aff9e..370d7420ff6a 100644 --- a/debian/control +++ b/debian/control @@ -63,6 +63,7 @@ Build-Depends: cmake (>= 3.10.2), # Crimson libyaml-cpp-dev, librabbitmq-dev, librdkafka-dev, + luarocks, # Make-Check libxmlsec1, # Make-Check libxmlsec1-nss, # Make-Check libxmlsec1-openssl, diff --git a/doc/radosgw/lua-scripting.rst b/doc/radosgw/lua-scripting.rst index a5dbc8710e16..81147f4e5008 100644 --- a/doc/radosgw/lua-scripting.rst +++ b/doc/radosgw/lua-scripting.rst @@ -10,6 +10,15 @@ This feature allows users to upload Lua scripts to different context in the rado operation was taken, and "postRequest" that will execute after each operation is taken. Script may be uploaded to address requests for users of a specific tenant. The script can access fields in the request and modify some fields. All Lua language features can be used in the script. +By default, all lua standard libraries are available in the script, however, in order to allow for other lua modules to be used in the script, we support adding packages to an allowlist: + + - All packages in the allowlist are being re-installed using the luarocks package manager on radosgw restart. Therefore a restart is needed for adding or removing of packages to take effect + - To add a package that contains C source code that needs to be compiled, use the `--allow-compilation` flag. In this case a C compiler needs to be available on the host + - Lua packages are installed in, and used from, a directory local to the radosgw. Meaning that lua packages in the allowlist are separated from any lua packages available on the host. + By default, this directory would be `/tmp/luarocks/`, and could be set to a different location via the `rgw_luarocks_location` configuration parameter. + Note that this parameter should not be set to one of the default locations where luarocks install packages (e.g. `$HOME/.luarocks`, `/usr/lib64/lua`, `/usr/share/lua`) + + .. toctree:: :maxdepth: 1 @@ -38,6 +47,30 @@ To remove the script: # radosgw-admin script rm --context={preRequest|postRequest} [--tenant={tenant-name}] +Package Management via CLI +-------------------------- + +To add a package to the allowlist: + +:: + + # radosgw-admin script-package add --package={package name} [--allow-compilation] + + +To remove a package from the allowlist: + +:: + + # radosgw-admin script-package rm --package={package name} + + +To print the list of packages in the allowlist: + +:: + + # radosgw-admin script-package list + + Context Free Functions ---------------------- Debug Log @@ -324,3 +357,37 @@ In the `postRequest` context we look at the metadata: RGWDebugLog("key=" .. k .. ", " .. "value=" .. v) end +- Use modules to create Unix socket based, JSON encoded, "access log": + +First we should add the following packages to the allowlist: + +:: + + # radosgw-admin script-package add --package=luajson + # radosgw-admin script-package add --package=luasocket --allow-compilation + + +Then, do a restart for the radosgw and upload the following script to the `postRequest` context: + +.. code-block:: lua + + if Request.RGWOp == "get_obj" then + local json = require("json") + local socket = require("socket") + local unix = require("socket.unix") + local s = assert(unix()) + E = {} + + msg = {bucket = (Request.Bucket or (Request.CopyFrom or E).Bucket).Name, + time = Request.Time, + operation = Request.RGWOp, + http_status = Request.Response.HTTPStatusCode, + error_code = Request.Response.HTTPStatus, + object_size = Request.Object.Size, + trans_id = Request.TransactionId} + + assert(s:connect("/tmp/socket")) + assert(s:send(json.encode(msg).."\n")) + assert(s:close()) + end + diff --git a/src/common/options.cc b/src/common/options.cc index 7de01868ccfd..2574f7ebd9a4 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -7246,6 +7246,16 @@ std::vector