Giter VIP home page Giter VIP logo

secretpruner's Introduction

Docker Swarm Secret Pruner

This is a little python script which will loop over docker secrets looking for names that match a pattern, then remove the oldest ones up to a given limit. Note: The script needs access to the docker socket, so make sure to scan through the code to make sure you trust it.

The script is pretty specific to our way of naming secrets, but hopefully it might give you an idea of how to prune your own ones.

Details

Every time we deploy to swarm we generate a new secret with the environment variables needed by the app. This is the format we use for our dotenv files, so that's the default in the script :

stackname-prod-dotenv-2020-03-20-14-50-33

After a while we end up with a lot of old secrets and it gets a bit messy debugging/listing them - so this script will break the secret name up and the date it was last updated. Then if there are more than a certain number of them - it will prune the oldest until it hits the limit (defined as 'keep' in the script).

Usage

First off, build the image that will run the script :

docker build -t secretpruner:some-tag .

And on a swarm master run the image :

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock secretpruner:some-tag

It will print out the names of any secrets it removed. You can also run it in as a dry run by setting a PRUNE_DRY_RUN=1 environment variable, eg :

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e PRUNE_DRY_RUN=1 secretpruner:some-tag

Exit codes

The script will exit with 0 if there were no problems, 1 if something went wrong.

secretpruner's People

Contributors

ohnotnow avatar

Watchers

 avatar  avatar  avatar

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.