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

plumb thru root cert tll to the aws ca provider #11449

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/11449.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
ca: Add a configurable TTL to the AWS ACM Private CA provider root certificate.
```
5 changes: 1 addition & 4 deletions agent/connect/ca/provider_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ const (
// leaf cert.
LeafTemplateARN = "arn:aws:acm-pca:::template/EndEntityCertificate/V1"

// RootTTL is the validity duration for root certs we create.
AWSRootTTL = 5 * 365 * 24 * time.Hour

// IntermediateTTL is the validity duration for the intermediate certs we
// create.
AWSIntermediateTTL = 1 * 365 * 24 * time.Hour
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably in a subsequent PR, but I think we can also make this configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the AWSRootTTL is actually replaced by the RootCertTTL option :)

Expand Down Expand Up @@ -211,7 +208,7 @@ func (a *AWSProvider) ensureCA() error {
}

// Self-sign it as a root
certPEM, err := a.signCSR(csrPEM, RootTemplateARN, AWSRootTTL)
certPEM, err := a.signCSR(csrPEM, RootTemplateARN, a.config.RootCertTTL)
if err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions agent/connect/ca/provider_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/acmpca"
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestAWSBootstrapAndSignPrimary(t *testing.T) {
cfg := map[string]interface{}{
"PrivateKeyType": tc.KeyType,
"PrivateKeyBits": tc.KeyBits,
"RootCertTTL": "8761h",
}
provider := testAWSProvider(t, testProviderConfigPrimary(t, cfg))
defer provider.Cleanup(true, nil)
Expand Down Expand Up @@ -69,10 +71,37 @@ func TestAWSBootstrapAndSignPrimary(t *testing.T) {
require.Equal(tc.KeyType, keyType)
require.Equal(tc.KeyBits, keyBits)

// Ensure that the root cert ttl is withing the configured value
// computation is similar to how we are passing the TTL thru the aws client
expectedTime := time.Now().AddDate(0, 0, int(8761*60*time.Minute/day)).UTC()
require.WithinDuration(expectedTime, rootCert.NotAfter, 10*time.Minute, "expected parsed cert ttl to be the same as the value configured")

// Sign a leaf with it
testSignAndValidate(t, provider, rootPEM, nil)
})
}

t.Run("Test default root ttl for aws ca provider", func(t *testing.T) {

provider := testAWSProvider(t, testProviderConfigPrimary(t, nil))
defer provider.Cleanup(true, nil)

// Generate the root
require.NoError(t, provider.GenerateRoot())

// Fetch Active Root
rootPEM, err := provider.ActiveRoot()
require.NoError(t, err)

// Ensure they use the right key type
rootCert, err := connect.ParseCert(rootPEM)
require.NoError(t, err)

// Ensure that the root cert ttl is withing the configured value
// computation is similar to how we are passing the TTL thru the aws client
expectedTime := time.Now().AddDate(0, 0, int(87600*60*time.Minute/day)).UTC()
require.WithinDuration(t, expectedTime, rootCert.NotAfter, 10*time.Minute, "expected parsed cert ttl to be the same as the value configured")
})
}

func testSignAndValidate(t *testing.T, p Provider, rootPEM string, intermediatePEMs []string) {
Expand Down
4 changes: 1 addition & 3 deletions website/content/docs/agent/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,7 @@ bind_addr = "{{ GetPrivateInterfaces | include \"network\" \"10.0.0.0/8\" | attr
Defaults to 10 years as `87600h`. This value, if provided, needs to be higher than the
intermediate certificate TTL.

This setting currently applies only to the consul connect and Vault CA providers. It is
ignored for the AWS acm pca provider. The value for root certificates issued by the AWS
CA provider is 5 years and not configurable at this time.
This setting applies to all Consul CA providers.

For the Vault provider, this value is only used if the backend is not initialized at first.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ The following configuration options are supported by all CA providers:
Defaults to 10 years as `87600h`. This value, if provided, needs to be higher than the
intermediate certificate TTL.

This setting currently applies only to the consul connect and Vault CA providers. It is
ignored for the AWS acm pca provider. The value for root certificates issued by the AWS
CA provider is 5 years and not configurable at this time.
This setting applies to all Consul CA providers.

For the Vault provider, this value is only used if the backend is not initialized at first.

Expand Down