entrypoint.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #!/usr/bin/env sh
  2. # Force security SSH parameters
  3. if [ -d /etc/ssh ]; then
  4. cat > /etc/ssh/sshd_config <<- EOF
  5. # This is the sshd server system-wide configuration file. See
  6. # sshd_config(5) for more information.
  7. # This sshd was compiled with PATH=/bin:/usr/bin:/sbin:/usr/sbin
  8. # The strategy used for options in the default sshd_config shipped with
  9. # OpenSSH is to specify options with their default value where
  10. # possible, but leave them commented. Uncommented options override the
  11. # default value.
  12. #Port 22
  13. #AddressFamily any
  14. #ListenAddress 0.0.0.0
  15. #ListenAddress ::
  16. HostKey /etc/ssh/ssh_host_ed25519_key
  17. # Ciphers and keying
  18. #RekeyLimit default none
  19. # Logging
  20. #SyslogFacility AUTH
  21. #LogLevel INFO
  22. # Authentication:
  23. #LoginGraceTime 2m
  24. PermitRootLogin no
  25. #StrictModes yes
  26. MaxAuthTries 3
  27. #MaxSessions 10
  28. #PubkeyAuthentication yes
  29. # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
  30. # but this is overridden so installations will only check .ssh/authorized_keys
  31. AuthorizedKeysFile .ssh/authorized_keys
  32. #AuthorizedPrincipalsFile none
  33. #AuthorizedKeysCommand none
  34. #AuthorizedKeysCommandUser nobody
  35. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
  36. #HostbasedAuthentication no
  37. # Change to yes if you don't trust ~/.ssh/known_hosts for
  38. # HostbasedAuthentication
  39. #IgnoreUserKnownHosts no
  40. # Don't read the user's ~/.rhosts and ~/.shosts files
  41. #IgnoreRhosts yes
  42. # To disable tunneled clear text passwords, change to no here!
  43. PasswordAuthentication no
  44. PermitEmptyPasswords no
  45. # Change to no to disable s/key passwords
  46. #ChallengeResponseAuthentication yes
  47. # Kerberos options
  48. #KerberosAuthentication no
  49. #KerberosOrLocalPasswd yes
  50. #KerberosTicketCleanup yes
  51. #KerberosGetAFSToken no
  52. # GSSAPI options
  53. #GSSAPIAuthentication no
  54. #GSSAPICleanupCredentials yes
  55. # Set this to 'yes' to enable PAM authentication, account processing,
  56. # and session processing. If this is enabled, PAM authentication will
  57. # be allowed through the ChallengeResponseAuthentication and
  58. # PasswordAuthentication. Depending on your PAM configuration,
  59. # PAM authentication via ChallengeResponseAuthentication may bypass
  60. # the setting of "PermitRootLogin without-password".
  61. # If you just want the PAM account and session checks to run without
  62. # PAM authentication, then enable this but set PasswordAuthentication
  63. # and ChallengeResponseAuthentication to 'no'.
  64. #UsePAM no
  65. #AllowAgentForwarding yes
  66. # Feel free to re-enable these if your use case requires them.
  67. AllowTcpForwarding no
  68. GatewayPorts no
  69. X11Forwarding no
  70. #X11DisplayOffset 10
  71. #X11UseLocalhost yes
  72. #PermitTTY yes
  73. #PrintMotd yes
  74. #PrintLastLog yes
  75. #TCPKeepAlive yes
  76. #PermitUserEnvironment no
  77. #Compression delayed
  78. #ClientAliveInterval 0
  79. #ClientAliveCountMax 3
  80. #UseDNS no
  81. #PidFile /run/sshd.pid
  82. #MaxStartups 10:30:100
  83. #PermitTunnel no
  84. #ChrootDirectory none
  85. #VersionAddendum none
  86. # no default banner path
  87. #Banner none
  88. # override default of no subsystems
  89. Subsystem sftp /usr/lib/ssh/sftp-server
  90. # Example of overriding settings on a per-user basis
  91. #Match User anoncvs
  92. # X11Forwarding no
  93. # AllowTcpForwarding no
  94. # PermitTTY no
  95. # ForceCommand cvs server
  96. # Algorithms
  97. Ciphers chacha20-poly1305@openssh.com
  98. KexAlgorithms curve25519-sha256@libssh.org
  99. MACs hmac-sha2-512-etm@openssh.com
  100. HostKeyAlgorithms=ssh-ed25519
  101. EOF
  102. fi
  103. # Validate environment variables
  104. # Create ssh host key if not present
  105. if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
  106. ssh-keygen -A
  107. fi
  108. # Setup gitolite at volume /var/lib/git
  109. if [ ! -f "/var/lib/git/.ssh/authorized_keys" ]; then
  110. # Configure gitolite
  111. echo "$SSH_KEY" > "/tmp/$SSH_KEY_NAME.pub"
  112. su git -c "gitolite setup -pk \"/tmp/$SSH_KEY_NAME.pub\""
  113. rm "/tmp/$SSH_KEY_NAME.pub"
  114. fi
  115. if [ ! -d /etc/nginx/http.d ]; then
  116. install -d -m755 /etc/nginx/http.d || true
  117. fi
  118. # Init container
  119. if [ ! -f /etc/nginx/http.d/cgit.conf ]; then
  120. # enable random git password
  121. GIT_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32)
  122. echo "git:$GIT_PASSWORD" | chpasswd
  123. # add web user (nginx) to gitolite group (git)
  124. adduser nginx git
  125. ## Config cgit interface
  126. cat > /etc/cgitrc <<- EOF
  127. #
  128. # cgit config
  129. #
  130. virtual-root=/
  131. # Use a custom logo
  132. logo=/cgit.png
  133. # Specify the css url
  134. css=/cgit.css
  135. # Enable configuration from external management, for example: gitolite
  136. enable-git-config=1
  137. # Show extra links for each repository on the index page
  138. enable-index-links=1
  139. # Show owner
  140. enable-index-owner=1
  141. # Enable ASCII art commit history graph on the log pages
  142. enable-commit-graph=1
  143. # Allow http transport git clone
  144. enable-http-clone=1
  145. # Show number of affected files per commit on the log pages
  146. enable-log-filecount=1
  147. # Show number of added/removed lines per commit on the log pages
  148. enable-log-linecount=1
  149. # Enable statistics per week, month and quarter
  150. max-stats=quarter
  151. # Cache
  152. cache-about-ttl=15
  153. cache-dynamic-ttl=5
  154. cache-repo-ttl=5
  155. cache-root=/var/cache/cgit
  156. cache-root-ttl=5
  157. cache-scanrc-ttl=15
  158. cache-size=0
  159. cache-snapshot-ttl=5
  160. cache-static-ttl=-1
  161. # Sort items in the repo list case sensitively. Default value: "1"
  162. case-sensitive-sort=1
  163. # Specifies the maximum size of a blob to display HTML for in KBytes. Default value: "0" (limit disabled)
  164. max-blob-size=2048
  165. # Specifies the number of entries to list per page on the repository index page. Default value: "50".
  166. max-repo-count=250
  167. # Specifies the maximum number of repo description characters to display on the repository index page.
  168. # Default value: "80"
  169. max-repodesc-length=80
  170. # Set the default maximum statistics period. Valid values are "week", "month", "quarter" and "year".
  171. # If unspecified, statistics are disabled. Default value: none
  172. max-stats=year
  173. #
  174. # List of common mimetypes
  175. #
  176. mimetype.gif=image/gif
  177. mimetype.htm=text/html
  178. mimetype.html=text/html
  179. mimetype.ico=image/x-icon
  180. mimetype.jpg=image/jpeg
  181. mimetype.jpeg=image/jpeg
  182. mimetype.md=text/markdown
  183. mimetype.mng=video/x-mng
  184. mimetype.ora=image/openraster
  185. mimetype.pam=image/x-portable-arbitrarymap
  186. mimetype.pbm=image/x-portable-bitmap
  187. mimetype.pdf=application/pdf
  188. mimetype.pgm=image/x-portable-graymap
  189. mimetype.png=image/png
  190. mimetype.pnm=image/x-portable-anymap
  191. mimetype.ppm=image/x-portable-pixmap
  192. mimetype.svg=image/svg+xml
  193. mimetype.svgz=image/svg+xml
  194. mimetype.tga=image/x-tga
  195. mimetype.tif=image/tiff
  196. mimetype.tiff=image/tiff
  197. mimetype.webp=image/webp
  198. mimetype.xbm=image/x-xbitmap
  199. mimetype.xcf=image/x-xcf
  200. mimetype.xpm=image/x-xpixmap
  201. # Enable syntax highlighting and about formatting
  202. source-filter=/usr/lib/cgit/filters/syntax-highlighting.py
  203. about-filter=/usr/lib/cgit/filters/about-formatting.sh
  204. #
  205. # List of common readmes
  206. #
  207. readme=:README.md
  208. readme=:readme.md
  209. readme=:README.mkd
  210. readme=:readme.mkd
  211. readme=:README.rst
  212. readme=:readme.rst
  213. readme=:README.html
  214. readme=:readme.html
  215. readme=:README.htm
  216. readme=:readme.htm
  217. readme=:README.txt
  218. readme=:readme.txt
  219. readme=:README
  220. readme=:readme
  221. readme=:INSTALL.md
  222. readme=:install.md
  223. readme=:INSTALL.mkd
  224. readme=:install.mkd
  225. readme=:INSTALL.rst
  226. readme=:install.rst
  227. readme=:INSTALL.html
  228. readme=:install.html
  229. readme=:INSTALL.htm
  230. readme=:install.htm
  231. readme=:INSTALL.txt
  232. readme=:install.txt
  233. readme=:INSTALL
  234. readme=:install
  235. snapshots=$CGIT_SNAPSHOT
  236. # Direct cgit to repository location managed by gitolite
  237. remove-suffix=0
  238. project-list=/var/lib/git/projects.list
  239. section-from-path=1
  240. scan-path=/var/lib/git/repositories
  241. EOF
  242. # Append clone-prefix
  243. if [ -n "$CGIT_CLONE_PREFIX" ]; then
  244. echo "# Specify some default clone prefixes" >> /etc/cgitrc
  245. echo "clone-prefix=$CGIT_CLONE_PREFIX" >> /etc/cgitrc
  246. fi
  247. if [ -n "$CGIT_ROOT_TITLE" ]; then
  248. echo "# Set the title and heading of the repository index page" >> /etc/cgitrc
  249. echo "root-title=$CGIT_ROOT_TITLE" >> /etc/cgitrc
  250. fi
  251. if [ -n "$CGIT_DESC" ]; then
  252. echo "# Set description repository" >> /etc/cgitrc
  253. echo "root-desc=$CGIT_DESC" >> /etc/cgitrc
  254. fi
  255. # Using highlight syntax
  256. #sed -i.bak \
  257. # -e "s#exec highlight --force -f -I -X -S #\#&#g" \
  258. # -e "s#\#exec highlight --force -f -I -O xhtml#exec highlight --force --inline-css -f -I -O xhtml#g" \
  259. # /usr/lib/cgit/filters/syntax-highlighting.sh
  260. # Nginx configuration
  261. rm -f /etc/nginx/http.d/default.conf || true
  262. cat > /etc/nginx/http.d/cgit.conf <<- EOF
  263. server {
  264. listen 80 default_server;
  265. server_name localhost;
  266. # Logs
  267. access_log /dev/null;
  268. error_log /dev/null;
  269. root /usr/share/webapps/cgit;
  270. try_files \$uri @cgit;
  271. location @cgit {
  272. include fastcgi_params;
  273. # Path to the CGI script that comes with cgit
  274. fastcgi_param SCRIPT_FILENAME \$document_root/cgit.cgi;
  275. fastcgi_param PATH_INFO \$uri;
  276. fastcgi_param QUERY_STRING \$args;
  277. fastcgi_param QUERY_INFO \$uri;
  278. fastcgi_param HTTP_HOST \$server_name;
  279. # Path to the socket file that is created/used by fcgiwrap
  280. fastcgi_pass unix:/run/fcgiwrap/fcgiwrap.socket;
  281. }
  282. # Enable compression for JS/CSS/HTML, for improved client load times.
  283. # It might be nice to compress JSON/XML as returned by the API, but
  284. # leaving that out to protect against potential BREACH attack.
  285. gzip on;
  286. gzip_vary on;
  287. gzip_types # text/html is always compressed by HttpGzipModule
  288. text/css
  289. application/javascript
  290. font/truetype
  291. font/opentype
  292. application/vnd.ms-fontobject
  293. image/svg+xml;
  294. gzip_min_length 1000; # default is 20 bytes
  295. gzip_buffers 16 8k;
  296. gzip_comp_level 2; # default is 1
  297. client_body_timeout 30s; # default is 60
  298. client_header_timeout 10s; # default is 60
  299. send_timeout 10s; # default is 60
  300. keepalive_timeout 10s; # default is 75
  301. resolver_timeout 10s; # default is 30
  302. reset_timedout_connection on;
  303. proxy_ignore_client_abort on;
  304. tcp_nopush on; # send headers in one piece
  305. tcp_nodelay on; # don't buffer data sent, good for small data bursts in real time
  306. # Enabling the sendfile directive eliminates the step of copying the data into the buffer
  307. # and enables direct copying data from one file descriptor to another.
  308. sendfile on;
  309. sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. should be > 800k.
  310. aio threads;
  311. }
  312. EOF
  313. fi
  314. # Start sshd as detach, log to stderr (-e)
  315. /usr/sbin/sshd -e
  316. # launch fcgiwrap via spawn-fcgi, port 1234
  317. spawn-fcgi -s /run/fcgiwrap/fcgiwrap.socket -f /usr/bin/fcgiwrap
  318. chmod 660 /run/fcgiwrap/fcgiwrap.socket
  319. # fix permissions gitolite
  320. chown git:git /var/lib/git
  321. chown git:git -R /var/lib/git
  322. chmod 700 /var/lib/git
  323. chown git:git /var/lib/git/.gitolite.rc
  324. chmod 640 /var/lib/git/.gitolite.rc
  325. # Start git-daemon
  326. git daemon --detach --reuseaddr --base-path=/var/lib/git/repositories /var/lib/git/repositories
  327. # Start nginx
  328. exec nginx -g "daemon off;"