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

Add support for multiple public certificates to AWS IID node attestor #4124

Merged

Conversation

maxlambrecht
Copy link
Member

@maxlambrecht maxlambrecht commented May 1, 2023

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Add support for all regions to the AWS_IID Node Attestor.

Description of change

Backward compatibility

The SPIRE Server also supports the use of RSA-1024 certificates: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/verify-signature.html
The "default" certificate is the one currently used by SPIRE, which expires on Jun-2024. The certificates for specific regions were also added as part of this PR.

SPIRE Agent will send both type of signatures: the signature from the path instance-identity/signature, that can be validated using RSA-1024 certificates); and the the signature from the path instance-identity/rsa2048, that can be validated using RSA-2048 certificates).

SPIRE Server will use the RSA-2048 signature if present, if not, will fall back to RSA-1024.

In a nutshell:
New SPIRE Server attests new SPIRE Agents, using RSA-2048 certificates and signature.
Old SPIRE Server attests new SPIRE Agents, using only one "default" RSA-1024 certificate, supporting only a set of regions.
New SPIRE Server attests old SPIRE Agents, using RSA-1024 certificates, supporting all regions.

Which issue this PR fixes

Fixes #2126

Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

Thanks, @maxlambrecht ! Just a few comments...

func getAWSCACertificate(region string, keyType PublicKeyType) (*x509.Certificate, error) {
var cert string
if keyType == KeyTypeUnset {
return nil, fmt.Errorf("signature type is unset")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("signature type is unset")
return nil, fmt.Errorf("signature key type is unset")

@@ -223,14 +227,10 @@ func (p *IIDAttestorPlugin) Configure(ctx context.Context, req *configv1.Configu
return nil, status.Errorf(codes.InvalidArgument, "unable to decode configuration: %v", err)
}

// Get the AWS CA public key. We do this lazily on configure so deployments
// Function to get the AWS CA certificate. We do this lazily on configure so deployments
Copy link
Member

Choose a reason for hiding this comment

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

Did you measure the startup cost if we parse all of the certificates in advance? I'd be surprised if the impact was substantial. I'd also much prefer to pay that cost once instead of every time we attest a new node. My vote would be to either 1) just parse them all on startup, or 2) cache them once parsed so we don't pay the cost continuously.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer option 2. Rather than parsing all 45 certificates on startup, I'd choose parsing and caching the certificates on demand. This way, only the certificates that are actually used will be parsed and cached, avoiding unnecessary overhead.

@@ -106,14 +110,14 @@ type IIDAttestorConfig struct {
AssumeRole string `hcl:"assume_role"`
pathTemplate *agentpathtemplate.Template
trustDomain spiffeid.TrustDomain
awsCAPublicKey *rsa.PublicKey
getAWSCACertificate func(string, PublicKeyType) (*x509.Certificate, error)
Copy link
Member

Choose a reason for hiding this comment

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

We talked about maybe providing a way in the config for operators to specify an override for the signing certificate for a given region. Is that not needed anymore due to the very long expiration dates on the RSA2048 CAs?

Copy link
Member Author

Choose a reason for hiding this comment

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

We talked about providing a way to specify a cert for region, and my understanding is that we prefer to have all the certs and select automatically which one to use based on the region, which I think is not bad idea considering the very long expiration dates.

var attestationData caws.IIDAttestationData
var doc imds.InstanceIdentityDocument
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: variables should be defined closer to the point of use

@@ -56,8 +60,14 @@ var (
ebsType = ec2types.DeviceTypeEbs
)

var testAWSCACert *x509.Certificate
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: these two vars should go in the var block above

Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
@maxlambrecht maxlambrecht force-pushed the aws_iid_attestor_multiple_certs_support branch from 89a43c5 to 2bfd1fe Compare May 14, 2023 17:00
Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

Thanks @maxlambrecht !

@azdagron azdagron added this to the 1.7.0 milestone May 19, 2023
@azdagron azdagron merged commit 8275f14 into spiffe:main May 19, 2023
Neniel pushed a commit to Neniel/spire that referenced this pull request Aug 24, 2023
…spiffe#4124)

Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
Signed-off-by: Neniel <11655196+Neniel@users.noreply.github.com>
@maxlambrecht maxlambrecht deleted the aws_iid_attestor_multiple_certs_support branch June 28, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS node attestor needs to use different cert for different regions
2 participants