Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS KMS Server Keymanager #2066

Merged
merged 33 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c14aae6
adds initial implementation for aws kms keymanager plugin
kunzimariano Sep 22, 2020
18d1eeb
Added kmsClientFake and initial test case.
Andres-GC Oct 8, 2020
81220b3
awskms improvements:
kunzimariano Oct 30, 2020
7c4dd57
adds unit tests for awskmw
Andres-GC Oct 21, 2020
782093b
- Fixes unit tests for awskms
Nov 5, 2020
d045ef3
- makes awskms plugin builtin
kunzimariano Dec 2, 2020
2fd9ca2
Adds AWS KMS KeyManager documentation
Jan 20, 2021
d938dfe
renames and updates plugin_server_keymanager_awskms.md
kunzimariano Jan 22, 2021
3f63a1f
address comments
kunzimariano Feb 10, 2021
09b28de
updates aws-sdk-go to v2
kunzimariano Feb 23, 2021
e319826
address comments
kunzimariano Feb 23, 2021
bc1a9a8
- makes use of ctx when creating a new client
kunzimariano Feb 24, 2021
481701d
addresses comments
kunzimariano Mar 1, 2021
71acd3a
extract aliases fetching into a function
kunzimariano Mar 4, 2021
c7c43d5
cleans tests setup
kunzimariano Mar 4, 2021
a5de27a
adds tests for schedule delete
kunzimariano Mar 4, 2021
b09793e
address comments
kunzimariano Mar 8, 2021
8d74df5
address last comments
kunzimariano Mar 9, 2021
c087b86
makes use of arn instead of alias and key id
kunzimariano Mar 12, 2021
8203576
adds better unused keys dispose
kunzimariano Mar 24, 2021
52d5f59
Merge remote-tracking branch 'origin/master' into kunzimariano-awskms
azdagron Mar 25, 2021
adc723c
Apply KeyManager Facade related changes to AWS KMS KeyManager
azdagron Mar 25, 2021
c586d94
address comments
kunzimariano Mar 25, 2021
089a6f6
tests improvements for tasks
kunzimariano Apr 1, 2021
c54858e
adds `SPIRE_SERVER/` to alias prefix
kunzimariano Apr 1, 2021
8cea751
adds description to tasks
kunzimariano Apr 1, 2021
9d96dff
- Changed the `server_id_file_path` setting to be `key_metadata_file`
amartinezfayo Apr 1, 2021
de0d98e
Wordsmithing and testkey usage improvement
azdagron Apr 2, 2021
49f5a97
Merge remote-tracking branch 'origin/master' into kunzimariano-awskms
azdagron Apr 2, 2021
aef3294
fix imports and tidy
azdagron Apr 2, 2021
0af8f7e
fix linting
azdagron Apr 2, 2021
d04eaec
Only do deep validation on aliases we manage
azdagron Apr 4, 2021
b422c13
Merge branch 'master' into awskms
azdagron Apr 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conf/server/server_full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ plugins {
}
}

# KeyManager "aws_kms": A key manager for signing SVIDs which only generates and stores keys in AWS KMS
# KeyManager "aws_kms" {
# plugin_data {
# region: AWS Region to use.
# region = ""
#
# key_prefix: A unique prefix per server
# server_id_file_path = "./file_path"
# }
# }

# KeyManager "disk": A disk-based key manager for signing SVIDs.
# KeyManager "disk" {
# plugin_data {
Expand Down
52 changes: 52 additions & 0 deletions doc/plugin_server_keymanager_aws_kms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Server plugin: KeyManager "aws_kms"

The `aws_kms` key manager plugin leverages the AWS Key Management Service (KMS) to create, maintain and rotate key pairs (as [Customer master keys](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys), or CMKs), and sign SVIDs as needed, with the private key never leaving KMS.

## Configuration

The plugin accepts the following configuration options:

| Key | Type | Required | Description | Default |
| ------------------- | ------ | ------------------------------------- | ------------------------------------------------------- | ---------------------------------------------------- |
| access_key_id | string | see [AWS KMS Access](#aws-kms-access) | The Access Key Id used to authenticate to KMS | Value of AWS_ACCESS_KEY_ID environment variable |
| secret_access_key | string | see [AWS KMS Access](#aws-kms-access) | The Secret Access Key used to authenticate to KMS | Value of AWS_SECRET_ACCESS_KEY environment variable |
| region | string | yes | The region where the keys will be stored | |
| server_id_file_path | string | yes | A file path location where the server id will be persisted | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a section in the docs describing what this is and what it's used for

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggested change is both technically accurate and less confusing when read in the context of a key manager configuration. It also gives the reader a hint at what it's used for and what might happen if it's lost.

When I read "location where the server id will be persisted", I wondered "what's a server id" , "can I not set it?", "what is it used for?", "why does it have to be a file", etc... I think a change similar to the one below avoids a lot of that. The name of the configurable too could probably benefit from an update like key_metadata_file

Suggested change
| server_id_file_path | string | yes | A file path location where the server id will be persisted | |
| server_id_file_path | string | yes | A file path location where information about generated keys will be persisted | |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key_metadata_file sounds much better to me. I also think we need to describe at a high level what its used for, the implications of what happens when it is lost, and how we recover, clean up our own mess. We should probably include a section in the documentation that elaborates on our purge strategy. These are the kinds of these we end up answering in slack over and over.


### AWS KMS Access

Access to AWS KMS can be given by either setting the `access_key_id` and `secret_access_key`, or by ensuring that the plugin runs on an EC2 instance with a given IAM role that has a specific set of permissions.

The IAM role must have an attached policy with the following permissions:

- `kms:CreateAlias`
- `kms:CreateKey`
- `kms:DescribeKey`
- `kms:GetPublicKey`
- `kms:ListKeys`
- `kms:ListAliases`
- `kms:ScheduleKeyDeletion`
- `kms:Sign`
- `kms:UpdateAlias`
- `kms:DeleteAlias`

## Sample plugin configuration

```
KeyManager "aws_kms" {
plugin_data {
region = "us-east-2"
server_id_file_path = "./server_id"
}
}
```

## Supported key types and TTL

The plugin creates CMKs of the same key type configured in the SPIRE Server. At the time of this writing the plugin supports all the set of keys supported by SPIRE: `rsa-2048`, `rsa-4096`, `ec-p256`, and `ec-p384`. It defaults to `ec-p256` if not specified.

In order to configure it you can set the `ca_key_type` value in the SPIRE Server config file.

You can also set the TTL that the plugin will use to rotate the CMKs by setting the `ca_ttl` config in the same config file.

For more info refer to the [Server configuration section](https://github.com/spiffe/spire/blob/master/doc/spire_server.md#server-configuration-file) in the SPIRE Server documentation and to the [full server config file](https://github.com/spiffe/spire/blob/master/conf/server/server_full.conf) for a complete Server config example.
1 change: 1 addition & 0 deletions doc/spire_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This document is a configuration reference for SPIRE Server. It includes informa
| DataStore | [sql](/doc/plugin_server_datastore_sql.md) | An sql database storage for SQLite, PostgreSQL and MySQL databases for the SPIRE datastore |
| KeyManager | [disk](/doc/plugin_server_keymanager_disk.md) | A disk-based key manager for signing SVIDs |
| KeyManager | [memory](/doc/plugin_server_keymanager_memory.md) | A key manager for signing SVIDs which only stores keys in memory and does not actually persist them anywhere |
| KeyManager | [aws_kms](/doc/plugin_server_keymanager_awskms.md) | A key manager for signing SVIDs which only generates and stores keys in AWS KMS |
| NodeAttestor | [aws_iid](/doc/plugin_server_nodeattestor_aws_iid.md) | A node attestor which attests agent identity using an AWS Instance Identity Document |
| NodeAttestor | [azure_msi](/doc/plugin_server_nodeattestor_azure_msi.md) | A node attestor which attests agent identity using an Azure MSI token |
| NodeAttestor | [gcp_iit](/doc/plugin_server_nodeattestor_gcp_iit.md) | A node attestor which attests agent identity using a GCP Instance Identity Token |
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ require (
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129
github.com/armon/go-metrics v0.3.2
github.com/aws/aws-sdk-go v1.28.9
github.com/aws/aws-sdk-go-v2 v1.2.0
github.com/aws/aws-sdk-go-v2/config v1.1.1
github.com/aws/aws-sdk-go-v2/credentials v1.1.1
github.com/aws/aws-sdk-go-v2/service/kms v1.1.1
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff/v3 v3.0.0
github.com/containerd/containerd v1.3.2 // indirect
Expand All @@ -32,7 +36,7 @@ require (
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.2
github.com/google/go-cmp v0.5.0
github.com/google/go-cmp v0.5.4
github.com/hashicorp/go-hclog v0.14.0
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/golang-lru v0.5.1
Expand Down Expand Up @@ -61,6 +65,7 @@ require (
go.uber.org/goleak v0.10.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4
Expand Down
25 changes: 25 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.28.9 h1:grIuBQc+p3dTRXerh5+2OxSuWFi0iXuxbFdTSg0jaW0=
github.com/aws/aws-sdk-go v1.28.9/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go-v2 v1.2.0 h1:BS+UYpbsElC82gB+2E2jiCBg36i8HlubTB/dO/moQ9c=
github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo=
github.com/aws/aws-sdk-go-v2/config v1.1.1 h1:ZAoq32boMzcaTW9bcUacBswAmHTbvlvDJICgHFZuECo=
github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y=
github.com/aws/aws-sdk-go-v2/credentials v1.1.1 h1:NbvWIM1Mx6sNPTxowHgS2ewXCRp+NGTzUYb/96FZJbY=
github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2 h1:EtEU7WRaWliitZh2nmuxEXrN0Cb8EgPUFGIoTMeqbzI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2/go.mod h1:3hGg3PpiEjHnrkrlasTfxFqUsZ2GCk/fMUn4CbKgSkM=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2 h1:4AH9fFjUlVktQMznF+YN33aWNXaR4VgDXyP28qokJC0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8=
github.com/aws/aws-sdk-go-v2/service/kms v1.1.1 h1:rK1edW1dLtSGr1551ttHqQopajK4Pv9C4ez70dVMQaI=
github.com/aws/aws-sdk-go-v2/service/kms v1.1.1/go.mod h1:6K5oOoDdnkW/h+Jv+xOA+tvgI6lwGBT9igkJGL1ypaY=
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1 h1:37QubsarExl5ZuCBlnRP+7l1tNwZPBSTqpTBrPH98RU=
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1 h1:TJoIfnIFubCX0ACVeJ0w46HEH5MwjwYN4iFhuYIhfIY=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM=
github.com/aws/smithy-go v1.1.0 h1:D6CSsM3gdxaGaqXnPgOBCeL6Mophqzu7KJOu7zW78sU=
github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -310,8 +328,11 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
Expand Down Expand Up @@ -412,6 +433,10 @@ github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
ds_sql "github.com/spiffe/spire/pkg/server/plugin/datastore/sql"
"github.com/spiffe/spire/pkg/server/plugin/hostservices"
"github.com/spiffe/spire/pkg/server/plugin/keymanager"
km_awskms "github.com/spiffe/spire/pkg/server/plugin/keymanager/awskms"
km_disk "github.com/spiffe/spire/pkg/server/plugin/keymanager/disk"
km_memory "github.com/spiffe/spire/pkg/server/plugin/keymanager/memory"
"github.com/spiffe/spire/pkg/server/plugin/nodeattestor"
Expand Down Expand Up @@ -72,6 +73,7 @@ var (
// KeyManagers
km_disk.BuiltIn(),
km_memory.BuiltIn(),
km_awskms.BuiltIn(),
// Notifiers
no_k8sbundle.BuiltIn(),
no_gcs_bundle.BuiltIn(),
Expand Down
Loading