GithubHelp home page GithubHelp logo

After dump of certificates is there anyway to have script change either owner (chown) and/or mode (chmod)? about traefik-certs-dumper HOT 4 OPEN

ldez avatar ldez commented on August 25, 2024 2
After dump of certificates is there anyway to have script change either owner (chown) and/or mode (chmod)?

from traefik-certs-dumper.

Comments (4)

Archenoth avatar Archenoth commented on August 25, 2024 1

If someone comes across this and doesn't want --watch, but still wants to chown things before they get out, I used this workaround:

tmpfile=$(mktemp)

cat <<EOF >$tmpfile
  chown -R $UID:$(id -g) /shared/certs
  kill 1
EOF

docker run --rm \
  -v $tmpfile:/tmp/chownme \
  ldez/traefik-certs-dumper file \
    --source /data/acme.json \
    --dest /shared/certs \
    --watch --post-hook "sh /tmp/chownme"

rm $tmpfile

(Of course, you'd need additional -vs to mount the data you are working with for your own cases)

The reason for the heredoc'd script is that passing in --post-hook "sh -c 'chown -R $UID:$(id -g) /shared/certs && kill 1'" appears to drop the final ', not allowing the command to run, and it also seems like you can't run multiple commands outside of a sh.

The kill 1 is to kill the root process (the cert dumper) after --watch successfully triggers the --post-hook, since watch mode is required for the --post-hook to run. That means that this container runs, and exits after it does its thing!

I'd also love an option to set the ownership of files generated after running this--but until then, I hope this workaround is useful to someone else~

from traefik-certs-dumper.

ESh4d0w avatar ESh4d0w commented on August 25, 2024

Maybe adding a flag to change permissions of the cert and key ?
One for key and one for certs would be optimal.

Currently it wirtes with static permissions at least for v2. Didin't look further into it.

err := ioutil.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600)

return ioutil.WriteFile(certPath, cert.Certificate, 0666)

return ioutil.WriteFile(keyPath, cert.Key, 0600)

from traefik-certs-dumper.

lammensj avatar lammensj commented on August 25, 2024

I was able to change the permissions via the "--post-hook" option:
traefik-certs-dumper file --watch --version v2 --source /data/acme.json --dest /shared/certs --post-hook "chown -R $PUID:$PGID /shared/certs"

from traefik-certs-dumper.

vasyl83 avatar vasyl83 commented on August 25, 2024

is it possible to go even further and execute a script with --post-hook? every time I try to execute a bash script it stops parsing when it encounters a firs space in the command. For example my script file (named posthook.sh) is:
chown -R $PUID:$PGID /shared/certs && scp /shared/certs/* [email protected]:/mnt/data/

it always fails at scp. Also I did add scp to the container by modifying entrypoint: from apk add jq to apk add jq openssh-client.

edit: the scp command by itself works flawlessly when executed inside the container (I have known_hosts and keys mapped inside the container)

from traefik-certs-dumper.

Related Issues (20)

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.