From 9c31ceb2c5fb30d164717b17795e49129e37df8c Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sun, 3 Apr 2022 06:17:51 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 41c1152..107a914 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,41 @@ You need to create an OAuth Client id from console.cloud.google.com, download th ```go run main.go --provider gdrive --basedir /tmp/ --gdrive-client-json-filepath /[credential_dir] --gdrive-local-config-path [directory_to_save_config] ``` +## Shell functions + +### Bash and zsh (multiple files uploaded as zip archive) +##### Add this to .bashrc or .zshrc or its equivalent +```bash +transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer \n ... | transfer ">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;} +``` + +#### Now you can use transfer function +``` +$ transfer hello.txt +``` + + +### Zsh (with delete url outpu) +##### Add this to .zshrc or its equivalent +```bash +transfer() +{ + local file="${1}" + local filename="${file##*/}" + # show delete link from the response header after upload. the command "sed" is necessary to clean up the output, "gsub()" in "awk" does not work. + curl --request PUT --progress-bar --dump-header - --upload-file "${file}" "https://transfer.sh/${filename}" | sed "s/#//g" | awk '/x-url-delete/ { print "Delete command: curl --request DELETE " $2 } END{ print "Download link: " $1 }' +} +``` + +#### Sample ouput +```bash +$ transfer image.img +######################################################################################################################################################################################################################################## 100.0% +Delete command: curl --request DELETE https://transfer.sh/Ge9cuW/image.img/ +Download link: https://transfer.sh/Ge9cuW/image.img +``` + + ## Contributions Contributions are welcome. From bb0891cd7d71a827a64246815d46d6d60dc08757 Mon Sep 17 00:00:00 2001 From: jeanluc <2163936+lkubb@users.noreply.github.com> Date: Sun, 3 Apr 2022 12:55:15 +0000 Subject: [PATCH 2/2] Docker: Allow selection of (unprivileged) UID/GID at build time (#418) * Docker: use custom non-root UID/GID (build-arg) --- .github/workflows/build-docker-images.yml | 11 +++++++++++ Dockerfile | 17 ++++++++++++++++- README.md | 21 ++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml index c871344..1b5a17b 100644 --- a/.github/workflows/build-docker-images.yml +++ b/.github/workflows/build-docker-images.yml @@ -34,9 +34,11 @@ jobs: fi TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" + TAGS_NOROOT="--tag ${DOCKER_IMAGE}:${VERSION}-noroot" if [ $VERSION = edge -o $VERSION = nightly ]; then TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" + TAGS_NOROOT="$TAGS_NOROOT --tag ${DOCKER_IMAGE}:latest-noroot" fi echo ::set-output name=docker_image::${DOCKER_IMAGE} @@ -46,6 +48,12 @@ jobs: --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ --build-arg VCS_REF=${GITHUB_SHA::8} \ ${TAGS} . + echo ::set-output name=buildx_args_noroot::--platform ${DOCKER_PLATFORMS} \ + --build-arg VERSION=${VERSION} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + --build-arg VCS_REF=${GITHUB_SHA::8} \ + --build-arg RUNAS=noroot \ + ${TAGS_NOROOT} . - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -64,6 +72,7 @@ jobs: name: Docker Buildx (build) run: | docker buildx build --no-cache --pull --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args_noroot }} - name: Docker Login if: success() && github.event_name != 'pull_request' @@ -77,11 +86,13 @@ jobs: if: success() && github.event_name != 'pull_request' run: | docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args_noroot }} - name: Docker Check Manifest if: always() && github.event_name != 'pull_request' run: | docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}-noroot - name: Clear if: always() && github.event_name != 'pull_request' diff --git a/Dockerfile b/Dockerfile index c8a42bd..196ea75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,27 @@ ENV GO111MODULE=on # build & install server RUN CGO_ENABLED=0 go build -tags netgo -ldflags "-X github.com/dutchcoders/transfer.sh/cmd.Version=$(git describe --tags) -a -s -w -extldflags '-static'" -o /go/bin/transfersh +ARG PUID=5000 \ + PGID=5000 \ + RUNAS + +RUN mkdir -p /tmp/useradd && \ + if [ ! -z "$RUNAS" ]; then \ + echo "${RUNAS}:x:${PUID}:${PGID}::/nonexistent:/sbin/nologin" >> /tmp/useradd/passwd && \ + echo "${RUNAS}:!:::::::" >> /tmp/useradd/shadow && \ + echo "${RUNAS}:x:${PGID}:" >> /tmp/useradd/group && \ + echo "${RUNAS}:!::" >> /tmp/useradd/groupshadow; else touch /tmp/useradd/unused; fi + FROM scratch AS final LABEL maintainer="Andrea Spacca " +ARG RUNAS -COPY --from=build /go/bin/transfersh /go/bin/transfersh +COPY --from=build /tmp/useradd/* /etc/ +COPY --from=build --chown=${RUNAS} /go/bin/transfersh /go/bin/transfersh COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +USER ${RUNAS} + ENTRYPOINT ["/go/bin/transfersh", "--listener", ":8080"] EXPOSE 8080 diff --git a/README.md b/README.md index 107a914..44ccb5c 100644 --- a/README.md +++ b/README.md @@ -140,12 +140,31 @@ $ go build -o transfersh main.go ## Docker -For easy deployment, we've created a Docker container. +For easy deployment, we've created an official Docker container. There are two variants, differing only by which user runs the process. + +The default one will run as `root`: ```bash docker run --publish 8080:8080 dutchcoders/transfer.sh:latest --provider local --basedir /tmp/ ``` +The one tagged with the suffix `-noroot` will use `5000` as both UID and GID: +```bash +docker run --publish 8080:8080 dutchcoders/transfer.sh:latest-noroot --provider local --basedir /tmp/ +``` + +### Building the Container +You can also build the container yourself. This allows you to choose which UID/GID will be used, e.g. when using NFS mounts: +```bash +# Build arguments: +# * RUNAS: If empty, the container will run as root. +# Set this to anything to enable UID/GID selection. +# * PUID: UID of the process. Needs RUNAS != "". Defaults to 5000. +# * PGID: GID of the process. Needs RUNAS != "". Defaults to 5000. + +docker build -t transfer.sh-noroot --build-arg RUNAS=doesntmatter --build-arg PUID=1337 --build-arg PGID=1338 . +``` + ## S3 Usage For the usage with a AWS S3 Bucket, you just need to specify the following options: