GithubHelp home page GithubHelp logo

solarhess / rules_build_secrets Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 6.0 10 KB

Bazel build rules to make it easier to incorporate secrets into your build process.

License: MIT License

Python 100.00%
bazel secrets environment-vars environment-variables build

rules_build_secrets's Introduction

rules_build_secrets Secrets in your Bazel Build

The rules_build_secrets will allow you to easily import secrets into your bazel build process. In many existing build environments, the build process needs to access resources protected by password credentials: private docker repos, private maven repos, cloud provider API keys, etc. There should be a way to easily and securely load and use those values with Bazel.

This rule helps you import secrets set in the build environment into your bazel build script. This way you don't hard-code secrets into your codebase or import them into the works.

Usage

Explicitly import secrets from the environment into the workspace. The 'entries' is a string -> string key/value mapping such that the key is the name of the environment variable to import. If the value is the special token '' the build will fail if the variable is unset or empty. Otherwise the value will be used as the default.

WORKSPACE:

    environment_secrets(
        name="env", 
        entries = {
            "MAVEN_REPO_USER": "<REQUIRED>",
            "MAVEN_REPO_PASSWORD": "<REQUIRED>",
            "DOCKER_PASSWORD": "<REQUIRED>",
            "DOCKER_URL": "index.docker.io",
        },
    )

In the example above, DOCKER_URL will use the value 'index.docker.io' if the "DOCKER_URL" environment variable is not set.

Then in build scripts you can reference these by importing a custom bzl file.

BUILD.bazel

    # Import a secret into the local BUILD.bazel environment
    load("@env//:secrets.bzl","MAVEN_REPO_USER")

    # Use the value
    sample_rule(arg=MAVEN_REPO_USER)

Planned Features

Send me your feedback on what would be useful to add.

  • Import secrets from a local encrypted file (in progress see branch simplecrypt-vault)
  • Import secrets from Hashicorp Vault APIs
  • Render secrets into standard secret formats:
    • Docker config.json,
    • Maven settings.xml
    • NPM
    • And more (contact me with ideas)

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.