modsec.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. (define-module (staging modsec)
  2. #:use-module ((guix licenses) #:prefix license:)
  3. #:use-module (guix packages)
  4. #:use-module (guix download)
  5. #:use-module (guix git-download)
  6. #:use-module (guix utils)
  7. #:use-module (gnu packages apr)
  8. #:use-module (gnu packages autotools)
  9. #:use-module (gnu packages web)
  10. #:use-module (gnu packages compression)
  11. #:use-module (gnu packages curl)
  12. #:use-module (gnu packages gettext)
  13. #:use-module (gnu packages tls)
  14. #:use-module (gnu packages libevent)
  15. #:use-module (gnu packages texinfo)
  16. #:use-module (gnu packages pcre)
  17. #:use-module (gnu packages perl)
  18. #:use-module (gnu packages pkg-config)
  19. #:use-module (gnu packages python)
  20. #:use-module (gnu packages version-control)
  21. #:use-module (gnu packages xml)
  22. #:use-module (guix build-system gnu)
  23. #:use-module (guix build-system trivial))
  24. (define-public gnulib
  25. (let ((commit "de255f87357354e0f2422d9321fe9701b776ead5")
  26. (revision "1"))
  27. (package
  28. (name "gnulib")
  29. (version "0.0.0")
  30. (source (origin
  31. (method git-fetch)
  32. (uri (git-reference
  33. (url "https://git.savannah.gnu.org/git/gnulib.git")
  34. (commit commit)))
  35. (file-name (git-file-name name version))
  36. (sha256
  37. (base32
  38. "00zjjldhj8ckr47fkqmb4d0lkpn6awwi8k8pngkfn2g30ccz7hji"))))
  39. (build-system gnu-build-system)
  40. (arguments
  41. `(#:tests? #f
  42. #:phases (modify-phases %standard-phases
  43. (delete 'configure)
  44. (delete 'build)
  45. (add-after 'install 'patch-yet-again
  46. (lambda* (#:key outputs #:allow-other-keys)
  47. (for-each patch-shebang (find-files (assoc-ref outputs "out")))
  48. #t))
  49. (replace 'install
  50. (lambda* (#:key inputs outputs #:allow-other-keys)
  51. (let ((source (assoc-ref inputs "source"))
  52. (out (assoc-ref outputs "out")))
  53. (copy-recursively source out)
  54. #t))))))
  55. (home-page "https://www.gnu.org/software/gnulib/")
  56. (synopsis "")
  57. (description "")
  58. ;; TODO: omg wtf
  59. (license #f))))
  60. (define-public pax-utils
  61. (package
  62. (name "pax-utils")
  63. (version "1.2.4")
  64. (source (origin
  65. (method url-fetch)
  66. (uri (string-append
  67. "http://distfiles.gentoo.org/distfiles/pax-utils-"
  68. version ".tar.xz"))
  69. (sha256
  70. (base32
  71. "01kr6l2c3bhbgdrmwgzh6jk0jjkw3pi9xrzzl9cpn0ibyf68p1aj"))))
  72. (build-system gnu-build-system)
  73. (home-page "https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities")
  74. (synopsis "ELF utils that can check files for security relevant properties")
  75. (description "A suite of ELF tools to aid auditing systems.
  76. Contains various ELF related utils for ELF32, ELF64 binaries useful
  77. for displaying PaX and security info on a large groups of binary
  78. files.")
  79. (license license:gpl2+)))
  80. (define-public vtest
  81. (let ((commit "86e65f1024453b1074d239a88330b5150d3e44bb")
  82. (revision "1"))
  83. (package
  84. (name "vtest")
  85. (version (git-version "0.0.0" revision commit))
  86. (source (origin
  87. (method git-fetch)
  88. (uri (git-reference
  89. (url "https://github.com/vtest/VTest.git")
  90. (commit commit)))
  91. (file-name (git-file-name name version))
  92. (sha256
  93. (base32
  94. "13z2j7gnbivzapp3rdf0pjk33rw8kw6rich4aidsi9kr3rc0f3g9"))))
  95. (build-system gnu-build-system)
  96. (arguments
  97. `(#:tests? #f
  98. #:make-flags (list "CC=gcc")
  99. #:phases (modify-phases %standard-phases
  100. (delete 'configure)
  101. (replace 'install
  102. (lambda* (#:key outputs #:allow-other-keys)
  103. (let* ((out (assoc-ref outputs "out"))
  104. (bin-dir (string-append out "/bin")))
  105. (mkdir-p bin-dir)
  106. (install-file "vtest" bin-dir)
  107. #t))))))
  108. (inputs
  109. `(("zlib" ,zlib)
  110. ("pcre" ,pcre)))
  111. (native-inputs `(("python" ,python-minimal)))
  112. (home-page "https://github.com/vtest/VTest")
  113. (synopsis "HTTP test-program")
  114. (description "VTest is the (almost) unvarnished varnishtest
  115. program, made available as a stand-alone program because it can be
  116. used to test all sorts of HTTP clients, servers and proxies.")
  117. (license (list license:bsd-2 license:bsd-3)))))
  118. (define-public haproxy
  119. (package
  120. (name "haproxy")
  121. (version "2.0.7")
  122. (source (origin
  123. (method url-fetch)
  124. (uri
  125. (string-append "https://www.haproxy.org/download/"
  126. (version-major+minor version)
  127. "/src/haproxy-" version ".tar.gz"))
  128. (sha256
  129. (base32
  130. "1p0kn7f6gq4n9hik8bq9hckfj816m40lw5yx0qjvvlcf09rcswrq"))))
  131. (build-system gnu-build-system)
  132. (arguments
  133. `(#:tests? #f
  134. #:make-flags
  135. (list "TARGET=linux-glibc"
  136. "USE_OPENSSL=yes"
  137. "USE_PCRE=yes"
  138. "USE_PCRE_JIT=yes"
  139. "USE_ZLIB=yes"
  140. (string-append "PREFIX=" (assoc-ref %outputs "out")))
  141. #:phases (modify-phases %standard-phases
  142. (delete 'configure)
  143. ;; TODO: package "VTest" from https://github.com/vtest/VTest
  144. ;; (replace 'check
  145. ;; (lambda _
  146. ;; (invoke "scripts/run-regtests.sh")))
  147. )))
  148. (inputs
  149. `(("zlib" ,zlib)
  150. ("openssl" ,openssl)
  151. ("pcre:bin" ,pcre "bin")
  152. ("gettext" ,gnu-gettext)))
  153. (native-inputs `(("python" ,python)))
  154. (home-page "https://www.haproxy.org/")
  155. (synopsis "High performance tcp/http load balancer")
  156. (description "High performance tcp/http load balancer.")
  157. (license (list license:gpl2+ license:lgpl2.1+))))
  158. (define-public modsecurity-standalone
  159. (package
  160. (name "modsecurity-standalone")
  161. (version "2.9.3")
  162. (source (origin
  163. (method url-fetch)
  164. (uri (string-append "https://www.modsecurity.org/tarball/" version
  165. "/modsecurity-" version ".tar.gz"))
  166. (sha256
  167. (base32
  168. "0611nskd2y6yagrciqafxdn4rxbdk2v4swf45kc1sgwx2sfh34j1"))))
  169. (build-system gnu-build-system)
  170. (arguments
  171. `(#:configure-flags
  172. (list (string-append "--with-curl=" (assoc-ref %build-inputs "curl"))
  173. (string-append "--with-apxs=" (assoc-ref %build-inputs "httpd") "/bin/apxs")
  174. (string-append "--with-pcre=" (assoc-ref %build-inputs "pcre:bin") "/bin/pcre-config")
  175. (string-append "--with-apr=" (assoc-ref %build-inputs "apr"))
  176. (string-append "--with-apu=" (assoc-ref %build-inputs "apr-util"))
  177. (string-append "--with-libxml=" (assoc-ref %build-inputs "libxml2"))
  178. "--disable-apache2-module"
  179. "--enable-standalone-module"
  180. "--enable-pcre-study"
  181. "--without-lua"
  182. "--enable-pcre-jit")
  183. #:modules ((srfi srfi-26)
  184. ,@%gnu-build-system-modules)
  185. #:phases (modify-phases %standard-phases
  186. (replace 'build
  187. (lambda _
  188. (invoke "make"
  189. "standalone")))
  190. (add-after 'install 'install-plugin-headers
  191. (lambda* (#:key outputs #:allow-other-keys)
  192. (let* ((out (assoc-ref outputs "out"))
  193. (include-dir (string-append out "/include"))
  194. (install-include (cut install-file <> include-dir)))
  195. (mkdir-p include-dir)
  196. (for-each install-include
  197. (find-files "standalone" "\\.h$"))
  198. (for-each install-include
  199. (find-files "apache2" "\\.h$"))))))))
  200. (inputs
  201. `(("apr" ,apr)
  202. ("apr-util" ,apr-util)
  203. ("curl" ,curl)
  204. ("httpd" ,httpd)
  205. ("pcre" ,pcre)
  206. ("libxml2" ,libxml2)
  207. ("libyajl" ,libyajl)
  208. ("pcre:bin" ,pcre "bin")))
  209. (native-inputs
  210. `(("perl" ,perl)
  211. ("pkg-config" ,pkg-config)))
  212. (home-page "https://www.modsecurity.org")
  213. (synopsis "Web application firewall")
  214. (description "ModSecurity is an open source, cross-platform web
  215. application firewall (WAF) module. Known as the \"Swiss Army Knife\"
  216. of WAFs, it enables web application defenders to gain visibility into
  217. HTTP(S) traffic and provides a power rules language and API to
  218. implement advanced protections.")
  219. (license license:asl2.0)))
  220. (define-public apr-union
  221. (package
  222. (name "apr-union")
  223. (version (package-version apr))
  224. (source #f)
  225. (build-system trivial-build-system)
  226. (arguments
  227. '(#:modules ((guix build union))
  228. #:builder (begin
  229. (use-modules (ice-9 match)
  230. (guix build union))
  231. (match %build-inputs
  232. (((names . directories) ...)
  233. (union-build (assoc-ref %outputs "out")
  234. directories)
  235. #t)))))
  236. (inputs `(("apr" ,apr)
  237. ("apr-util" ,apr-util)))
  238. (synopsis "Union of APR libraries")
  239. (description
  240. "A union of APR and its extension utilities. A union is required
  241. because haproxy SPOA builds assume that all of the headers and
  242. libraries are in the same directory.")
  243. (home-page (package-home-page apr))
  244. (license (package-license apr))))
  245. (define-public haproxy-modsecurity
  246. (package
  247. (inherit haproxy)
  248. (name "haproxy-modsecurity")
  249. (arguments
  250. `(#:tests? #f
  251. #:phases (modify-phases %standard-phases
  252. (delete 'configure)
  253. (replace 'build
  254. (lambda* (#:key inputs #:allow-other-keys)
  255. (let* ((modsecurity (assoc-ref inputs "modsecurity"))
  256. (modsec-includes (string-append modsecurity "/include"))
  257. (modsec-lib (string-append modsecurity "/lib"))
  258. (httpd (assoc-ref inputs "httpd"))
  259. (httpd-includes (string-append httpd "/include"))
  260. (apr (assoc-ref inputs "apr-union"))
  261. (apr-includes (string-append apr "/include/apr-1"))
  262. (libxml (assoc-ref inputs "libxml2"))
  263. (libxml-includes (string-append libxml "/include/libxml2"))
  264. (libevent (assoc-ref inputs "libevent"))
  265. (libevent-includes (string-append libevent "/include")))
  266. (invoke "make" "-C" "contrib/modsecurity" "CC=gcc"
  267. (string-append "MODSEC_INC=" modsec-includes)
  268. (string-append "MODSEC_LIB=" modsec-lib)
  269. (string-append "APACHE2_INC=" httpd-includes)
  270. (string-append "APR_INC=" apr-includes)
  271. (string-append "LIBXML_INC=" libxml-includes)
  272. (string-append "EVENT_INC=" libevent-includes))
  273. #t)))
  274. (replace 'install
  275. (lambda* (#:key outputs #:allow-other-keys)
  276. (let* ((out (assoc-ref outputs "out"))
  277. (bin-dir (string-append out "/bin")))
  278. (mkdir-p bin-dir)
  279. (install-file "contrib/modsecurity/modsecurity" bin-dir)
  280. #t))))))
  281. (inputs
  282. `(("modsecurity" ,modsecurity-standalone)
  283. ("apr-union" ,apr-union)
  284. ("httpd" ,httpd)
  285. ("libevent" ,libevent)
  286. ("libyajl" ,libyajl)
  287. ("curl" ,curl)
  288. ("pcre" ,pcre )
  289. ("libxml2" ,libxml2)))))