Skip to content

Commit 7e1ec1a

Browse files
authored
Merge pull request #35 from ovotech/add-lambda-handler
Add lambda handler
2 parents 210e5f2 + 6c666c9 commit 7e1ec1a

19 files changed

+965
-687
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
ckr.yaml
2-
config.*
2+
!*.go
3+
*config*.json
34
*.asc
5+
*cloud-key-rotator*
6+
key.json

.goreleaser.yml

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
# .goreleaser.yml
2-
archive:
3-
format: binary
1+
archives:
2+
- format: binary
3+
builds:
4+
- binary-build
5+
- format: zip
6+
builds:
7+
- lambda-build
8+
files:
9+
- none*
10+
name_template: "{{ .ProjectName }}_{{ .Version }}_lambda"
411
builds:
5-
- main: ./
12+
- id: binary-build
13+
main: ./
614
goos:
715
- windows
816
- darwin
917
- linux
1018
goarch:
1119
- amd64
20+
- id: lambda-build
21+
main: ./
22+
goos:
23+
- linux
24+
goarch:
25+
- amd64
1226
checksum:
1327
name_template: "{{ .ProjectName }}_checksums.txt"

README.md

+62-49
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@
33
This is a Golang program to assist with the reporting of Service Account key
44
ages, and rotating said keys once they pass a specific age threshold.
55

6+
The tool can update keys held in the following locations:
7+
8+
* GitHub
9+
* CircleCI
10+
* K8S (GKE only)
11+
12+
The tool is packaged as an executable file for native invocation, and as a zip
13+
file for deployment as an AWS Lambda.
14+
615
## Install
716

817
### From Binary Releases
918

10-
Darwin, Linux and Windows Binaries can be downloaded from the [Releases](https://github.com/ovotech/cloud-key-rotator/releases) page.
19+
Darwin, Linux and Windows Binaries can be downloaded from the
20+
[Releases](https://github.com/ovotech/cloud-key-rotator/releases) page.
1121

1222
Try it out:
1323

1424
```
1525
$ cloud-key-rotator -h
1626
```
1727

18-
### Docker image
19-
20-
An alpine based Docker image is available [here](https://hub.docker.com/r/ovotech/cloud-key-rotator).
28+
### Docker Image
2129

30+
An Alpine-based Docker image is available [here](https://hub.docker.com/r/ovotech/cloud-key-rotator).
2231

2332
## Getting Started
2433

@@ -28,25 +37,32 @@ An alpine based Docker image is available [here](https://hub.docker.com/r/ovotec
2837
to update with new keys, from config.
2938

3039
Check out [examples](examples) for example config files. [Viper](https://github.com/spf13/viper)
31-
is used as the Config framework, so config can be stored as JSON, TOML, YAML, or
32-
HCL. To work, the file just needs to be called "config" (before whatever
40+
is used as the config framework, so config can be stored as JSON, TOML, YAML or
41+
HCL.
42+
43+
For native invocation, the file needs to be called "config" (before whatever
3344
extension you're using), and be present either in `/etc/cloud-key-rotator/` or
34-
in the same directory the binary runs in.
45+
in the same directory the binary runs in. For AWS Lambda invocation, the config needs
46+
to be set as a plaintext secret in the AWS Secrets Manager, using a default key name
47+
of "ckr-config".
3548

3649
### Authentication/Authorisation
3750

3851
You'll need to provide `cloud-key-rotator` with the means of authenticating into
3952
any key provider that it'll be updating.
4053

4154
Authorisation is handled by the Default Credential Provider Chains for both
42-
[GCP](https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-go) and [AWS](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default).
55+
[GCP](https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-go) and
56+
[AWS](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default).
4357

4458
### Mode Of Operation
4559

46-
`cloud-key-rotator` can operate in 2 different modes. Rotation mode, in which
47-
keys are rotated, and non-rotation mode, which only posts the ages of the keys to
48-
the Datadog metric API. You can specify which mode to operate in by using the
49-
`RotationMode` boolean field in config.
60+
`cloud-key-rotator` can operate in two different modes:
61+
62+
1. Rotation mode - in which keys are rotated; and
63+
2. Non-rotation mode - which only posts the ages of keys to the Datadog Metric API.
64+
65+
The boolean field `RotationMode` config controls the mode of operation.
5066

5167
### Age Thresholds
5268

@@ -55,47 +71,43 @@ You can set the age threshold to whatever you want in the config, using the
5571
per-service-account-basis with the `RotationAgeThresholdMins` field. Key ages
5672
are always measured in minutes.
5773

58-
`cloud-key-rotator` won't attempt to rotate a key until it's passed the age
74+
`cloud-key-rotator` will not attempt to rotate a key until it's passed the age
5975
threshold you've set (either default or the key-specific). This allows you to
60-
run it as frequently as you want without worrying about keys being rotated too
61-
much.
76+
run it the tool frequently as you want without worrying about keys being rotated
77+
too excessively.
6278

6379
### Key Locations
6480

65-
Key locations is the term used for the places that keys are stored, that
66-
ultimately get updated with new keys that are generated.
81+
"Key locations" is the term used for the places where keys are stored, which will
82+
ultimately be updated with the new keys that are generated.
6783

6884
Currently, the following locations are supported:
6985

70-
- EnvVars CircleCI
71-
- Secrets in GKE
72-
- Files (encrypted via [mantle](https://github.com/ovotech/mantle) which
86+
* EnvVars CircleCI
87+
* Secrets in GKE
88+
* Files (encrypted via [mantle](https://github.com/ovotech/mantle) which
7389
integrates with KMS) in GitHub
7490

7591
## Rotation Process
7692

77-
By design, the rotation process is sensitive; it attempts to verify its actions
78-
as much as possible, and aborts immediately if it sees any errors. The idea
79-
behind this approach is that it should be quick to re-run the tool (with new
80-
keys being created) once issues have been resolved. Cloud Providers usually
81-
limit the number of keys you can have attached to a Service Account at any one
82-
time, so worth bearing this in mind when re-running manually after seeing errors.
93+
The tool attempts to verify its actions as much as possible and aborts
94+
immediately if it encounters an error. By design, the tool does **not** attempt to
95+
handle errors gracefully and continue, since this can lead to a "split-brain effect",
96+
with keys out-of-sync in various locations.
8397

84-
The alternative to this, is for `cloud-key-rotator` to attempt to gracefully
85-
handle errors, and for someone to manually patch things up afterwards. This
86-
approach could lead to split-brain effect of key sources (places where the keys
87-
are used) and confusion around what needs to be done before the old key can be
88-
deleted. After all sources are using the new key, the same thing may happen on
89-
the next key rotation, which doesn't lend itself well to automation.
98+
It should be quick to re-run the tool (with new keys being created) once issues
99+
have been resolved. Note that cloud providers usually limit the number of
100+
keys you can have attached to a Service Account at any one time, so it is
101+
worth bearing this in mind when re-running manually after seeing errors.
90102

91-
Only the first key of a Service Account is handled by `cloud-key-rotator`. If it
92-
handled more than one key, it could lead to complications when updating single
93-
sources multiple times.
103+
Only the first key of a Service Account is handled by `cloud-key-rotator`. If
104+
it handled more than one key, it could lead to complications when updating
105+
single sources multiple times.
94106

95107
## Key Sources
96108

97109
The `AccountKeyLocations` section of config holds details of the places where the keys
98-
are stored. E.g.:
110+
are stored, e.g.:
99111

100112
```JSON
101113
"AccountKeyLocations": [{
@@ -124,18 +136,18 @@ are stored. E.g.:
124136

125137
`cloud-key-rotator` has integrations into GitHub and CircleCI, which allows it
126138
not only to update those sources with the new key, but also to verify that a
127-
deployment has been successful after committing to a GitHub repo. If that
139+
deployment has been successful after committing to a GitHub repository. If that
128140
verification isn't required, you can disable it using the `VerifyCircleCISuccess`
129141
boolean.
130142

131-
For any GitHub key source that's configured, the whole process will be aborted
132-
if there's no `KmsKey` value set. Unencrypted keys shouldn't ever be committed
143+
For any GitHub key location, the whole process will be aborted
144+
if there is no `KmsKey` value set. Unencrypted keys should **never** be committed
133145
to a Git repository.
134146

135147
## GPG Commit Signing
136148

137149
Commits to GitHub repositories are required to be GPG signed. In order to
138-
achieve this, you just need to provide 4 things:
150+
achieve this, you need to provide 4 things:
139151

140152
* `Username` of the GitHub user commits will be made on behalf of, set in config
141153
* `Email` address of GitHub user, set in config
@@ -180,18 +192,19 @@ Service Account's email address.
180192

181193
## Rotation Flow
182194

183-
- Reduce keys to those of service accounts deemed to be valid (e.g. strip out
195+
1. Reduce keys to those of service accounts deemed to be valid (e.g. strip out
184196
user accounts if in rotation-mode)
185-
- Filter keys to those deemed to be eligible (e.g. according to filtering rules
197+
2. Filter keys to those deemed to be eligible (e.g. according to filtering rules
186198
configured by the user)
187-
- For each eligible key:
188-
- Create new key
189-
- Update key locations
190-
- Verify update has worked (where possible)
191-
- Delete old key
199+
3. For each eligible key:
200+
201+
* Create new key
202+
* Update key locations
203+
* Verify update has worked (where possible)
204+
* Delete old key
192205

193206
## Contributions
194207

195-
Contributions are more than welcome. It should be straight forward plugging in
196-
new integrations of new key providers and/or locations, so for that,
208+
Contributions are more than welcome. It should be straightforward plugging in
209+
integrations of new key providers and/or locations, so for that,
197210
or anything else, please branch or fork and raise a PR.

0 commit comments

Comments
 (0)