Giter VIP home page Giter VIP logo

entrypoint-demoter's Introduction

CircleCI GitHub release

Motivation

It is highly recommended that processes within containers do not run as root in order to prevent container breakouts; however, that goal is hard to maintain when attached volumes come into play. For example, Synology's DiskStation manages ownership of attachable volumes as regular UNIX users; however, its Docker integration doesn't allow for aligning the container's user with what is normally -u on the docker run command-line.

entrypoint-demoter solves this types of scenarios by allowing the container to momentarily run as root, but demote the initial sub-command to either match the ownership of a given path or be explicitly defined by UID/GID environment variables.

Usage

The command line arguments remaining after the options below are used to execute a sub-command with the demoted user ID (uid) and group ID (gid).

If executed as a non-root user, then this tool skips demoting entirely and just executes the sub-command with the current uid and gid.

Environment variables

  • UID : if set, demotes the sub-command to run with the given user ID
  • GID : if set, demotes the sub-command to run with the given group ID

Command-line

  • --match PATH : uses the ownership of the given path to determine a user and group ID
  • --stdin-on-term MESSAGE : some applications prefer to be gracefully stopped with a command on stdin rather than handling SIGTERM, such as Minecraft servers. The MESSAGE and a newline will be written to the sub-command's stdin when a TERM signal is received.
  • --debug : enables debug logging
  • --version : show version and exit

Example

The following shows how to use entrypoint-demoter in a Debian based Dockerfile. The entry.sh would be where your own entry point script/application would be specified.

ARG DEMOTER_VERSION=0.1.0
ARG DEMOTER_ARCH=amd64

ADD https://github.com/itzg/entrypoint-demoter/releases/download/${DEMOTER_VERSION}/entrypoint-demoter_${DEMOTER_VERSION}_linux_${DEMOTER_ARCH}.deb /usr/src

RUN dpkg -i /usr/src/entrypoint-demoter_${DEMOTER_VERSION}_linux_${DEMOTER_ARCH}.deb

ENTRYPOINT ["/usr/local/bin/entrypoint-demoter", "--match", "/data", "/entry.sh"]

The full context of this example can be seen in this Dockerfile

Testing

On a Linux system with Make and Docker installed invoke:

make test

entrypoint-demoter's People

Contributors

itzg avatar dependabot[bot] avatar strausmann avatar

Stargazers

 avatar RemcoDev avatar  avatar Lungoupao Khongsai avatar  avatar Fedor V avatar  avatar tiankongsang avatar Christopher Viel avatar Michael Vorburger avatar

Watchers

James Cloos avatar  avatar

Forkers

strausmann

entrypoint-demoter's Issues

The log "failed to read stdin" needs to be reworded

When the following log is observed it actually a quite normal situation when the container is created with stdin allocated:

time="2019-09-20T16:42:57Z" level=debug msg="failed to read stdin" error=EOF

The wording should be adjusted to make it less negative sounding and the EOF error does not need to be reported as is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.