Skip to content

Commit 5f7d324

Browse files
authored
Merge pull request #693 from mozilla/develop
v3.6.0 RC (develop -> master)
2 parents 4bc27f6 + 6b9e168 commit 5f7d324

39 files changed

+2189
-602
lines changed

.circleci/config.yml

+86-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
version: 2
1+
version: 2.1
2+
3+
workflows:
4+
build-and-deploy:
5+
jobs:
6+
- build
7+
- push:
8+
filters:
9+
tags:
10+
only: /^v.*/
11+
branches:
12+
ignore: /.*/
213
jobs:
314
build:
415
working_directory: /go/src/go.mozilla.org/sops
516
docker:
617
- image: circleci/golang:1.13
18+
resource_class: large
719
steps:
820
- checkout
921
- setup_remote_docker
@@ -12,10 +24,79 @@ jobs:
1224
command: |
1325
docker build -t mozilla/sops .
1426
docker tag mozilla/sops "mozilla/sops:$CIRCLE_SHA1"
27+
28+
push:
29+
machine: true
30+
resource_class: large
31+
steps:
32+
- checkout
33+
- run:
34+
name: semver check
35+
command: |
36+
MAJOR=$(echo ${CIRCLE_TAG#v} | cut -d"." -f1)
37+
MINOR=$(echo ${CIRCLE_TAG#v} | cut -d"." -f2)
38+
PATCH=$(echo ${CIRCLE_TAG#v} | cut -d"." -f3)
39+
echo "export MAJOR=${MAJOR}" >> $BASH_ENV
40+
echo "export MINOR=${MINOR}" >> $BASH_ENV
41+
echo "export PATCH=${PATCH}" >> $BASH_ENV
42+
43+
if [ -z $MAJOR ];then
44+
cat \<< EOF
45+
Failure Info:
46+
47+
This job uses the semver from the git TAG as the public version to publish.
48+
49+
- This should only run on workflows triggered by a tag.
50+
- The tag name should be a semver like 'v1.2.3'
51+
- The version should follow conventions documented at https://github.com/fsaintjacques/semver-tool
52+
EOF
53+
exit 1
54+
fi
55+
- run:
56+
name: Build containers
57+
command: |
58+
docker build -t mozilla/sops .
59+
docker build -f Dockerfile.alpine -t mozilla/sops:alpine .
1560
- run:
16-
name: Push containers
61+
name: Tag & Push containers
1762
command: |
18-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
19-
${GOPATH}/src/go.mozilla.org/sops/bin/ci/deploy_dockerhub.sh "latest"
20-
${GOPATH}/src/go.mozilla.org/sops/bin/ci/deploy_dockerhub.sh "$CIRCLE_SHA1"
63+
#latest
64+
bin/ci/deploy_dockerhub.sh "latest"
65+
bin/ci/deploy_dockerhub.sh "alpine"
66+
67+
# by sha
68+
echo "Tag and push mozilla/sops:$CIRCLE_SHA1"
69+
docker tag mozilla/sops "mozilla/sops:$CIRCLE_SHA1"
70+
bin/ci/deploy_dockerhub.sh "$CIRCLE_SHA1"
71+
72+
# no sha for alpine
73+
74+
# by semver
75+
# v1.2.3
76+
if [ ! -z $PATCH ];then
77+
echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR.$PATCH"
78+
docker tag mozilla/sops "mozilla/sops:v$MAJOR.$MINOR.$PATCH"
79+
bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR.$PATCH"
80+
81+
echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR.$PATCH-alpine"
82+
docker tag mozilla/sops:alpine "mozilla/sops:v$MAJOR.$MINOR.$PATCH-alpine"
83+
bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR.$PATCH-alpine"
84+
fi
85+
# v1.2
86+
if [ ! -z $MINOR ];then
87+
echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR"
88+
docker tag mozilla/sops "mozilla/sops:v$MAJOR.$MINOR"
89+
bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR"
90+
91+
echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR-alpine"
92+
docker tag mozilla/sops:alpine "mozilla/sops:v$MAJOR.$MINOR-alpine"
93+
bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR-alpine"
2194
fi
95+
# v1
96+
echo "Tag and Push mozilla/sops:v$MAJOR"
97+
docker tag mozilla/sops "mozilla/sops:v$MAJOR"
98+
bin/ci/deploy_dockerhub.sh "v$MAJOR"
99+
100+
echo "Tag and Push mozilla/sops:v$MAJOR-alpine"
101+
docker tag mozilla/sops:alpine "mozilla/sops:v$MAJOR-alpine"
102+
bin/ci/deploy_dockerhub.sh "v$MAJOR-alpine"

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.git
2+
/Dockerfile
3+
/Dockerfile.alpine

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
target
22
Cargo.lock
33
vendor/
4+
coverage.txt
5+
profile.out

.sops.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
creation_rules:
2-
- pgp: 1022470DE3F0BC54BC6AB62DE05550BC07FB1A0A
2+
- pgp: >-
3+
FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4,
4+
D7229043384BCC60326C6FB9D8720D957C3D3074

CHANGELOG.rst

+31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
Changelog
22
=========
33

4+
3.6.0
5+
-----
6+
Features:
7+
8+
* Support for encrypting data through the use of Hashicorp Vault (#655)
9+
* `sops publish` now supports `--recursive` flag for publishing all files in a directory (#602)
10+
* `sops publish` now supports `--omit-extensions` flag for omitting the extension in the destination path (#602)
11+
* sops now supports JSON arrays of arrays (#642)
12+
13+
Improvements:
14+
15+
* Updates and standardization for the dotenv store (#612, #622)
16+
* Close temp files after using them for edit command (#685)
17+
18+
Bug fixes:
19+
20+
* AWS SDK usage now correctly resolves the `~/.aws/config` file (#680)
21+
* `sops updatekeys` now correctly matches config rules (#682)
22+
* `sops updatekeys` now correctly uses the config path cli flag (#672)
23+
* Partially empty sops config files don't break the use of sops anymore (#662)
24+
* Fix possible infinite loop in PGP's passphrase prompt call (#690)
25+
26+
Project changes:
27+
28+
* Dockerfile now based off of golang version 1.14 (#649)
29+
* Push alpine version of docker image to Dockerhub (#609)
30+
* Push major, major.minor, and major.minor.patch tagged docker images to Dockerhub (#607)
31+
* Removed out of date contact information (#668)
32+
* Update authors in the cli help text (#645)
33+
34+
435
3.5.0
536
-----
637
Features:

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.12
1+
FROM golang:1.14
22

33
COPY . /go/src/go.mozilla.org/sops
44
WORKDIR /go/src/go.mozilla.org/sops

Dockerfile.alpine

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.12-alpine3.10 AS builder
2+
3+
RUN apk --no-cache add make
4+
5+
COPY . /go/src/go.mozilla.org/sops
6+
WORKDIR /go/src/go.mozilla.org/sops
7+
8+
RUN CGO_ENABLED=1 make install
9+
10+
11+
FROM alpine:3.10
12+
13+
RUN apk --no-cache add \
14+
vim ca-certificates
15+
ENV EDITOR vim
16+
COPY --from=builder /go/bin/sops /usr/local/bin/sops
17+
ENTRYPOINT ["/usr/local/bin/sops"]

README.rst

+79-11
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ Or whatever variation of the above fits your system and shell.
4848

4949
To use **sops** as a library, take a look at the `decrypt package <https://godoc.org/go.mozilla.org/sops/decrypt>`_.
5050

51-
**Questions?** ping "ulfr" and "autrilla" in ``#security`` on `irc.mozilla.org <https://wiki.mozilla.org/IRC>`_
52-
(use a web client like `mibbit <https://chat.mibbit.com>`_ ).
53-
5451
**What happened to Python Sops?** We rewrote Sops in Go to solve a number of
5552
deployment issues, but the Python branch still exists under ``python-sops``. We
5653
will keep maintaining it for a while, and you can still ``pip install sops``,
@@ -290,6 +287,66 @@ And decrypt it using::
290287
$ sops --decrypt test.enc.yaml
291288

292289

290+
Encrypting using Hashicorp Vault
291+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292+
293+
We assume you have an instance (or more) of Vault running and you have privileged access to it. For instructions on how to deploy a secure instance of Vault, refer to Hashicorp's official documentation.
294+
295+
To easily deploy Vault locally: (DO NOT DO THIS FOR PRODUCTION!!!)
296+
297+
.. code:: bash
298+
299+
$ docker run -d -p8200:8200 vault:1.2.0 server -dev -dev-root-token-id=toor
300+
301+
302+
.. code:: bash
303+
304+
$ # Substitute this with the address Vault is running on
305+
$ export VAULT_ADDR=http://127.0.0.1:8200
306+
307+
$ # this may not be necessary in case you previously used `vault login` for production use
308+
$ export VAULT_TOKEN=toor
309+
310+
$ # to check if Vault started and is configured correctly
311+
$ vault status
312+
Key Value
313+
--- -----
314+
Seal Type shamir
315+
Initialized true
316+
Sealed false
317+
Total Shares 1
318+
Threshold 1
319+
Version 1.2.0
320+
Cluster Name vault-cluster-618cc902
321+
Cluster ID e532e461-e8f0-1352-8a41-fc7c11096908
322+
HA Enabled false
323+
324+
$ # It is required to enable a transit engine if not already done (It is suggested to create a transit engine specifically for sops, in which it is possible to have multiple keys with various permission levels)
325+
$ vault secrets enable -path=sops transit
326+
Success! Enabled the transit secrets engine at: sops/
327+
328+
$ # Then create one or more keys
329+
$ vault write sops/keys/firstkey type=rsa-4096
330+
Success! Data written to: sops/keys/firstkey
331+
332+
$ vault write sops/keys/secondkey type=rsa-2048
333+
Success! Data written to: sops/keys/secondkey
334+
335+
$ vault write sops/keys/thirdkey type=chacha20-poly1305
336+
Success! Data written to: sops/keys/thirdkey
337+
338+
$ sops --hc-vault-transit $VAULT_ADDR/v1/sops/keys/firstkey vault_example.yml
339+
340+
$ cat <<EOF > .sops.yaml
341+
creation_rules:
342+
- path_regex: \.dev\.yaml$
343+
hc_vault_transit_uri: "$VAULT_ADDR/v1/sops/keys/secondkey"
344+
- path_regex: \.prod\.yaml$
345+
hc_vault_transit_uri: "$VAULT_ADDR/v1/sops/keys/thirdkey"
346+
EOF
347+
348+
$ sops --verbose -e prod/raw.yaml > prod/encrypted.yaml
349+
293350
Adding and removing keys
294351
~~~~~~~~~~~~~~~~~~~~~~~~
295352
@@ -546,6 +603,7 @@ can manage the three sets of configurations for the three types of files:
546603
- path_regex: \.prod\.yaml$
547604
kms: 'arn:aws:kms:us-west-2:361527076523:key/5052f06a-5d3f-489e-b86c-57201e06f31e+arn:aws:iam::361527076523:role/hiera-sops-prod,arn:aws:kms:eu-central-1:361527076523:key/cb1fab90-8d17-42a1-a9d8-334968904f94+arn:aws:iam::361527076523:role/hiera-sops-prod'
548605
pgp: 'FBC7B9E2A4F9289AC0C1D4843D16CEE4A27381B4'
606+
hc_vault_uris: "http://localhost:8200/v1/sops/keys/thirdkey"
549607
550608
# gcp files using GCP KMS
551609
- path_regex: \.gcp\.yaml$
@@ -865,21 +923,21 @@ written to disk.
865923
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
866924
"AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
867925
}
868-
926+
869927
# decrypt out.json and run a command
870928
# the command prints the environment variable and runs a script that uses it
871929
$ sops exec-env out.json 'echo secret: $database_password; ./database-import'
872930
secret: jf48t9wfw094gf4nhdf023r
873-
931+
874932
# launch a shell with the secrets available in its environment
875933
$ sops exec-env out.json 'sh'
876934
sh-3.2# echo $database_password
877935
jf48t9wfw094gf4nhdf023r
878-
936+
879937
# the secret is not accessible anywhere else
880938
sh-3.2$ exit
881939
$ echo your password: $database_password
882-
your password:
940+
your password:
883941
884942
885943
If the command you want to run only operates on files, you can use ``exec-file``
@@ -904,7 +962,7 @@ substituted with the temporary file path (whether a FIFO or an actual file).
904962
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
905963
"AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
906964
}
907-
965+
908966
# launch a shell with a variable TMPFILE pointing to the temporary file
909967
$ sops exec-file --no-fifo out.json 'TMPFILE={} sh'
910968
sh-3.2$ echo $TMPFILE
@@ -934,7 +992,7 @@ for added security.
934992
# the encrypted file can't be read by the current user
935993
$ cat out.json
936994
cat: out.json: Permission denied
937-
995+
938996
# execute sops as root, decrypt secrets, then drop privileges
939997
$ sudo sops exec-env --user nobody out.json 'sh'
940998
sh-3.2$ echo $database_password
@@ -968,6 +1026,7 @@ This command requires a ``.sops.yaml`` configuration file. Below is an example:
9681026
vault_kv_mount_name: "secret/" # default
9691027
vault_kv_version: 2 # default
9701028
path_regex: vault/*
1029+
omit_extensions: true
9711030
9721031
The above configuration will place all files under ``s3/*`` into the S3 bucket ``sops-secrets``,
9731032
all files under ``gcs/*`` into the GCS bucket ``sops-secrets``, and the contents of all files under
@@ -977,6 +1036,11 @@ published to S3 and GCS, it will decrypt them and re-encrypt them using the
9771036
9781037
You would deploy a file to S3 with a command like: ``sops publish s3/app.yaml``
9791038
1039+
To publish all files in selected directory recursively, you need to specify ``--recursive`` flag.
1040+
1041+
If you don't want file extension to appear in destination secret path, use ``--omit-extensions``
1042+
flag or ``omit_extensions: true`` in the destination rule in ``.sops.yaml``.
1043+
9801044
Publishing to Vault
9811045
*******************
9821046
@@ -991,6 +1055,9 @@ configuring the client.
9911055
``vault_kv_mount_name`` is used if your Vault KV is mounted somewhere other than ``secret/``.
9921056
``vault_kv_version`` supports ``1`` and ``2``, with ``2`` being the default.
9931057
1058+
If destination secret path already exists in Vault and contains same data as the source file, it
1059+
will be skipped.
1060+
9941061
Below is an example of publishing to Vault (using token auth with a local dev instance of Vault).
9951062
9961063
.. code:: bash
@@ -1293,9 +1360,10 @@ You can import sops as a module and use it in your python program.
12931360
tree = sops.walk_and_decrypt(tree, sops_key)
12941361
sops.write_file(tree, path=path, filetype=pathtype)
12951362
1296-
Note: this uses the previous implemenation of `sops` written in python,
1363+
Note: this uses the previous implementation of `sops` written in python,
1364+
12971365
and so doesn't support newer features such as GCP-KMS.
1298-
To use the current version, call out to `sops` using `subprocess.check_output`
1366+
To use the current version, call out to ``sops`` using ``subprocess.run``
12991367
13001368
Showing diffs in cleartext in git
13011369
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cmd/sops/edit.go

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
132132
if err != nil {
133133
return nil, common.NewExitError(fmt.Sprintf("Could not write output file: %s", err), codes.CouldNotWriteOutputFile)
134134
}
135+
136+
// Close temporary file, since Windows won't delete the file unless it's closed beforehand
137+
defer tmpfile.Close()
135138

136139
// Compute file hash to detect if the file has been edited
137140
origHash, err := hashFile(tmpfile.Name())

0 commit comments

Comments
 (0)