mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-21 18:42:36 +00:00
ipn/store/awsstore: allow providing a KMS key
Implements a KMS input for AWS parameter to support encrypting Tailscale state Fixes #14765 Change-Id: I39c0fae4bfd60a9aec17c5ea6a61d0b57143d4ba Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Lee Briggs <lee@leebriggs.co.uk>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
ef906763ee
commit
74d7d8a77b
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux
|
||||
//go:build linux && !ts_omit_aws
|
||||
|
||||
package awsstore
|
||||
|
||||
@@ -65,7 +65,11 @@ func TestNewAWSStore(t *testing.T) {
|
||||
Resource: "parameter/foo",
|
||||
}
|
||||
|
||||
s, err := newStore(storeParameterARN.String(), mc)
|
||||
opts := storeOptions{
|
||||
kmsKey: "arn:aws:kms:eu-west-1:123456789:key/MyCustomKey",
|
||||
}
|
||||
|
||||
s, err := newStore(storeParameterARN.String(), opts, mc)
|
||||
if err != nil {
|
||||
t.Fatalf("creating aws store failed: %v", err)
|
||||
}
|
||||
@@ -73,7 +77,7 @@ func TestNewAWSStore(t *testing.T) {
|
||||
|
||||
// Build a brand new file store and check that both IDs written
|
||||
// above are still there.
|
||||
s2, err := newStore(storeParameterARN.String(), mc)
|
||||
s2, err := newStore(storeParameterARN.String(), opts, mc)
|
||||
if err != nil {
|
||||
t.Fatalf("creating second aws store failed: %v", err)
|
||||
}
|
||||
@@ -162,3 +166,54 @@ func testStoreSemantics(t *testing.T, store ipn.StateStore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseARNAndOpts(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
arg string
|
||||
wantARN string
|
||||
wantKey string
|
||||
}{
|
||||
{
|
||||
name: "no-key",
|
||||
arg: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam",
|
||||
wantARN: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam",
|
||||
},
|
||||
{
|
||||
name: "custom-key",
|
||||
arg: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam?kmsKey=alias/MyCustomKey",
|
||||
wantARN: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam",
|
||||
wantKey: "alias/MyCustomKey",
|
||||
},
|
||||
{
|
||||
name: "bare-name",
|
||||
arg: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam?kmsKey=Bare",
|
||||
wantARN: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam",
|
||||
wantKey: "alias/Bare",
|
||||
},
|
||||
{
|
||||
name: "arn-arg",
|
||||
arg: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam?kmsKey=arn:foo",
|
||||
wantARN: "arn:aws:ssm:us-east-1:123456789012:parameter/myTailscaleParam",
|
||||
wantKey: "arn:foo",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
arn, opts, err := ParseARNAndOpts(tt.arg)
|
||||
if err != nil {
|
||||
t.Fatalf("New: %v", err)
|
||||
}
|
||||
if arn != tt.wantARN {
|
||||
t.Errorf("ARN = %q; want %q", arn, tt.wantARN)
|
||||
}
|
||||
var got storeOptions
|
||||
for _, opt := range opts {
|
||||
opt(&got)
|
||||
}
|
||||
if got.kmsKey != tt.wantKey {
|
||||
t.Errorf("kmsKey = %q; want %q", got.kmsKey, tt.wantKey)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user