diff --git a/.gitignore b/.gitignore index 5ff6309..409ee51 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,6 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +logs/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index c38f773..0c47827 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +### Setup +1. Replace IPs in `docker-compose.yml` +2. run like a compose project + + ### Supply chain - `com.github.docker-java:docker-java:3.4.1` [GitHub](https://github.com/docker-java/docker-java) \ Warning: [Numerous CVEs.](https://mvnrepository.com/artifact/com.github.docker-java/docker-java/3.4.1) [Project seems dead](https://github.com/docker-java/docker-java/issues) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8d1f917 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + networks: + - app + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - webroot:/var/www/html + + nginx: + image: nginx:1.27 + restart: unless-stopped + networks: + - nginx + volumes: + - ./nginx:/etc/nginx:ro + - webroot:/var/www/html:ro + - ssl-certs:/etc/ssl/nginx:ro + ports: # change IPs here + - "127.0.0.1:80:80" + - "127.0.0.1:443:443" + - "127.0.0.1:443:443/udp" + - "[::1]:80:80" + - "[::1]:443:443" + - "[::1]:443:443/udp" + depends_on: + - app + +volumes: + webroot: + ssl-certs: \ No newline at end of file diff --git a/nginx/conf.d/server.conf b/nginx/conf.d/server.conf new file mode 100644 index 0000000..9731ed6 --- /dev/null +++ b/nginx/conf.d/server.conf @@ -0,0 +1,16 @@ +server { + listen 443 ssl; + listen 443 quic; + listen [::]:443 ssl; + listen [::]:443 quic; + + ssl_certificate /etc/ssl/nginx/$hostname/fullchain.pem; + ssl_certificate_key /etc/ssl/nginx/$hostname/key.pem; + + root /var/www/html/$hostname; + index index.html; + + location /.well-known/acme-challenge { + root /var/www/acme-challenge/$hostname; + } +} \ No newline at end of file diff --git a/nginx/mime.types b/nginx/mime.types new file mode 100644 index 0000000..065d891 --- /dev/null +++ b/nginx/mime.types @@ -0,0 +1,98 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..40ca583 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,85 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_user [$time_local] "$request" ' + '$status $body_bytes_sent bytes "$http_referer" ' + '"$http_x_forwarded_for"'; + + # While I removed PII from the above log format, still better not logging + access_log /dev/null main; # /var/log/nginx/access.log main; + + + server_tokens off; + + sendfile on; + tcp_nopush on; + + quic_retry on; + quic_gso on; + ssl_early_data on; # READ https://blog.cloudflare.com/introducing-0-rtt/#whats-the-catch + + keepalive_timeout 65; + + gzip on; + gzip_types *; + gzip_min_length 1000; + gzip_proxied any; + + http2 on; + + add_header Alt-Svc 'h3=":443"; ma=86400'; + + # modern configuration + ssl_protocols TLSv1.3; + ssl_ecdh_curve X25519:prime256v1:secp384r1; + ssl_prefer_server_ciphers off; + + # Make sure to generate it first + ssl_dhparam dhparam.pem; + + # OCSP stapling + ssl_stapling on; + ssl_stapling_verify on; + + # replace with the IP address of your resolver; + # async 'resolver' is important for proper operation of OCSP stapling + resolver [2001:4860:4860::8888] [2001:4860:4860::8844] 8.8.8.8 8.8.4.4; + + # If certificates are marked OCSP Must-Staple, consider managing the + # OCSP stapling cache with an external script, e.g. certbot-ocsp-fetcher + + # HTTPS redirect + server { + listen 80 default_server; + listen [::]:80 default_server; + + return 301 https://$host$request_uri; + } + + # default HTTPS server + server { + listen 443 ssl default_server; + listen 443 quic reuseport default_server; + listen [::]:443 ssl default_server; + + server_name _; + + # Make sure to generate + ssl_certificate snakeoil.pem; + ssl_certificate_key snakeoil.key; + } + + include /etc/nginx/conf.d/*.conf; +} diff --git a/src/main/java/eu/m724/Main.java b/src/main/java/eu/m724/Main.java index 42da78c..ce960cf 100644 --- a/src/main/java/eu/m724/Main.java +++ b/src/main/java/eu/m724/Main.java @@ -42,7 +42,10 @@ public class Main { } } + if (containerInfo != null) { + LOGGER.info("{}", containerInfo.toString()); + var mounts = containerInfo.getJSONArray("Mounts"); LOGGER.debug("Detected {} mounts:", mounts.length()); for (int i=0; i createContainer(String name, JSONObject data) { return dao.requestJson("containers/create", Map.of("name", name), data); } + + public CompletableFuture createImage(String image, String tag) { + return dao.requestJson("images/create", Map.of("fromImage", image, "tag", tag), new JSONObject()); + } } diff --git a/src/main/java/eu/m724/docker/proxy/ConnectionThread.java b/src/main/java/eu/m724/docker/proxy/ConnectionThread.java index de94228..41042d1 100644 --- a/src/main/java/eu/m724/docker/proxy/ConnectionThread.java +++ b/src/main/java/eu/m724/docker/proxy/ConnectionThread.java @@ -69,9 +69,13 @@ public class ConnectionThread extends Thread { }); // Wait for both directions to complete - clientToRemote.get(); - remoteToClient.get(); - } catch (InterruptedException | ExecutionException e) { + try { + clientToRemote.get(); + remoteToClient.get(); + } catch (InterruptedException e) { + // TODO + } + } catch (ExecutionException e) { throw new IOException("Transfer interrupted", e); } }