Add fuzz tests (#585)
Description
Why is this change being made?
Added some fuzz targets to this project. I started with the usual suspects: methods that take in arbitrary strings. I followed the suggestions in Go’s documentation here. I picked:
- The
NewSecretDescriptorListmethod- The file permission validation method
- The method that retrieves secret values from a JSON path in a secret
- The method that handles secret mount requests to start.
What is changing?
- Added fuzz tests
- Added seed corpuses. The seed corpuses were generated using an LLM which I proofread. Some of the corpus seed entries are intentionally invalid. I am very interested in any ideas you might have to expand those seed corpuses.
- For the
FuzzGetJsonSecretsfuzz test, I had to do some additional input validation to ensure that the underlying library we use for JSON path traversal (go-jmespath) does not panic when provided invalid input. These panics don’t really help us with finding bugs in our code since they occur in the library. I’m really debating the value of this fuzz test. It passes now and does exercise the other logic in the method so I guess that’s something.- The secret descriptor did find a null pointer deference if nil input is passed to the method. In practice this shouldn’t happen and/or would cause a failure to get returned to the end user, so not too concerning. I’ve gone ahead and added a null check for completeness.
- Added a CI step to run these fuzz targets which passes on my fork.
Code patch coverage failed due to the bug fix done in step 4. I had to add a unit test to cover my change.
Related Links
- Issue #, if available:
Testing
How was this tested?
- CI step, the whole PR is adding tests.
When testing locally, provide testing artifact(s):
Reviewee Checklist
Update the checklist after submitting the PR
- I have reviewed, tested and understand all changes If not, why:
- I have filled out the Description and Testing sections above If not, why:
- Build and Unit tests are passing If not, why:
- Unit test coverage check is passing If not, why:
- Integration tests pass locally If not, why:
- I have updated integration tests (if needed)
If not, why: No changes needed to integ tests since this is all testing changes. The null check is not exercised by the integ tests.
- I have ensured no sensitive information is leaking (i.e., no logging of sensitive fields, or otherwise) If not, why:
- I have added explanatory comments for complex logic, new classes/methods and new tests If not, why:
- I have updated README/documentation (if needed)
If not, why: Monitoring CI failures is already called out in CONTRIBUTING.md. I don’t think we need additional instructions beyond that but I am open to differing opinions.
- I have clearly called out breaking changes (if any) If not, why: No breaking changes
Reviewer Checklist
All reviewers please ensure the following are true before reviewing:
- Reviewee checklist has been accurately filled out
- Code changes align with stated purpose in description
- Test coverage adequately validates the changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
AWS Secrets Manager and Config Provider for Secret Store CSI Driver
AWS offers two services to manage secrets and parameters conveniently in your code. AWS Secrets Manager allows you to easily rotate, manage, and retrieve database credentials, API keys, certificates, and other secrets throughout their lifecycle. AWS Systems Manager Parameter Store provides hierarchical storage for configuration data. The AWS provider for the Secrets Store CSI Driver allows you to make secrets stored in Secrets Manager and parameters stored in Parameter Store appear as files mounted in Kubernetes pods.
Installation
Requirements
--set grpcSupportedProviders="aws"flag on the install step.Note this step can be skipped if installing from Helm. The Helm chart for the ASCP by default automatically installs a compatible version of the Secrets Store CSI driver as a helm dependency. This can be disabled by setting
secrets-store-csi-driver.install=false.[^1]: The CSI Secret Store driver runs as a DaemonSet, and as described in the AWS documentation, DaemonSet is not supported on Fargate.
Installing the AWS Provider and Config Provider (ASCP)
Option 1: Using helm
Option 2: Using kubectl
Separate CSI Driver Installation
If you install the secrets-store-csi-driver separately (not via this Helm chart), you must configure
tokenRequestsin the CSI driver for the AWS provider to authenticate with AWS services:Or if using kubectl, add the following to your CSIDriver manifest:
Usage
Set the region name and name of your cluster to use in the bash commands that follow:
Where <REGION> is the region in which your Kubernetes cluster is running and <CLUSTERNAME> is the name of your cluster.
Create a test secret:
Create an access policy for the pod scoped down to just the secrets it should have and save the policy ARN in a shell variable:
Note, when using SSM parameters the permission “ssm:GetParameters” is needed in the policy. To simplify this example we use wild card matches above but you could lock this down further using the full ARN from the output of create-secret above.
Option 1: Using IAM Roles For Service Accounts (IRSA)
Create the IAM OIDC provider for the cluster if you have not already done so:
Next, create the service account to be used by the pod and associate the above IAM policy with that service account. For this example we use nginx-irsa-deployment-sa for the service account name:
For a private cluster, ensure that the VPC the cluster is in has an AWS STS endpoint. For more information, see Interface VPC endpoints in the AWS IAM User Guide.
Create the SecretProviderClass which tells the AWS provider which secrets are to be mounted in the pod. The ExampleSecretProviderClass-IRSA.yaml in the examples directory will mount “MySecret” created above:
Finally, we can deploy our pod. The ExampleDeployment-IRSA.yaml in the examples directory contains a sample nginx deployment that mounts the secrets under /mnt/secrets-store in the pod:
To verify the secret has been mounted properly, See the example below:
Option 2: Using EKS Pod Identity
Note: EKS Pod Identity option is only supported for EKS in the Cloud. It’s not supported for Amazon EKS Anywhere, Red Hat Openshift Service on AWS (ROSA) and self-managed Kubernetes clusters on Amazon Elastic Compute Cloud (Amazon EC2) instances.
To verify the secret has been mounted properly, See the example below:
Troubleshooting
Most errors can be viewed by describing the pod deployment. For the deployment, find the pod names using get pods (use -n <NAMESPACE> if you are not using the default namespace):
Then describe the pod (substitute the pod ID from above for <PODID>, as before use -n if you are not using the default namespace):
Additional information may be available in the provider logs:
Where <PODID> in this case is the id of the csi-secrets-store-provider-aws pod.
SecretProviderClass options
The SecretProviderClass has the following format:
The parameters section contains the details of the mount request and contain one of the three fields:
topology.kubernetes.io/regionlabel on the node. This lookup adds overhead to mount requests so clusters using large numbers of pods will benefit from providing the region here.The primary objects field of the SecretProviderClass can contain the following sub-fields:
objectName: This field is required. It specifies the name of the secret or parameter to be fetched. For Secrets Manager this is the SecretId parameter and can be either the friendly name or full ARN of the secret. For SSM Parameter Store, this is the Name of the parameter and can be either the name or full ARN of the parameter.
objectType: This field is optional when using a Secrets Manager ARN for objectName, otherwise it is required. This field can be either “secretsmanager” or “ssmparameter”.
objectAlias: This optional field specifies the file name under which the secret will be mounted. When not specified the file name defaults to objectName.
filePermission: This optional field expects a 4 digit string which specifies the file permission for the secret that will be mounted. When not specified this will default to “0644” permisions. Ensure the 4 digit string is a valid octal file permission.
objectVersion: This field is optional, and generally not recommended since updates to the secret require updating this field. For Secrets Manager this is the VersionId. For SSM Parameter Store, this is the optional version number.
objectVersionLabel: This optional field specifies the alias used for the version. Most applications should not use this field since the most recent version of the secret is used by default. For Secrets Manager this is the VersionStage. For SSM Parameter Store this is the optional Parameter Label.
failoverObject: An optional field when using the failoverRegion feature. See the Automated Failover Regions section in this readme for more information. The failover object can contain the following sub-fields:
jmesPath: This optional field specifies the specific key-value pairs to extract from a JSON-formatted secret. You can use this field to mount key-value pairs from a properly formatted secret value as individual secrets. For example: Consider a secret “MySecret” with JSON content as follows:
To mount the username and password key pairs of this secret as individual secrets, use the jmesPath field as follows:
If either the ‘path’ or the ‘objectAlias’ fields contain a hyphen, then they must be escaped with a single quote:
If you use the jmesPath field, you must provide the following two sub-fields:
You may pass an additional sub-field to specify the file permission:
Additional Considerations
Rotation
When using the optional alpha rotation reconciler feature of the Secrets Store CSI driver the driver will periodically remount the secrets in the SecretProviderClass. This will cause additional API calls which results in additional charges. Applications should use a reasonable poll interval that works with their rotation strategy. A one hour poll interval is recommended as a default to reduce excessive API costs.
Anyone wishing to test out the rotation reconciler feature can enable it using helm:
Automated Failover Regions
In order to provide availability during connectivity outages or for disaster recovery configurations, this provider supports an automated failover feature to fetch secrets or parameters from a secondary region. To define an automated failover region, define the failoverRegion in the SecretProviderClass.yaml file:
When the failoverRegion is defined, the driver will attempt to get the secret value from both regions.
It is possible to use different secrets or parameters between the primary and failover regions. This example will use different ARNs depending on which region it is pulling from:
If ‘failoverObject’ is defined, then objectAlias is required.
Using EKS Pod Identity to Access Cross-Account AWS Resources
EKS Pod Identity CreatePodIdentityAssociation requires the IAM role to reside in the same AWS account as the EKS cluster.
To mount AWS Secrets Manager secrets from a different AWS account than your EKS cluster, follow cross-account access to set up resource policy for the secret, key policy for the KMS key, and IAM role used in Pod Identity association. Fetching cross-account parameters from SSM Parameter Store is only supported for parameters in the advanced parameter tier. See Working with Shared Parameters for details.
Private Builds
You can pull down this git repository and build and install this plugin into your account’s AWS ECR registry using the following steps. First clone the repository:
Next, set your region and repository name in bash shell variables to be used later:
Where <REGION> is the AWS region in which your Kubernetes cluster is running, and <ACCOUNT> is your AWS account Id. Next create your ECR repository if you have not already done so:
Now run make to build the plugin and push it into your account’s repo:
Once the image is in your repo you can install it into your cluster from your repo rather than the public repo:
Configure the Underlying Secrets Manager Client to Use FIPS Endpoint
If you use Helm chart to install the provider, append the
--set useFipsEndpoint=trueflag on the install step. Your install command would be something likeClient-Side Rate-Limitting to Kubernetes API server
To mount each secret on each pod, the AWS CSI provider lookups the region of the pod and the role ARN associated with the service account by calling the Kubernetes APIs. You can increase the value of qps and burst if you notice the provider is throttled by client-side limit to the API server.
If you use Helm chart to install the provider, append the
--set-json 'k8sThrottlingParams={"qps": "<custom qps>", "burst": "<custom qps>"}'flag in the install step.HTTP timeout for Pod Identity
In order to configure the HTTP timeout for Pod Identity authentication, pass the
pod-identity-http-timeoutflag during the install step:The timeout value must be a valid Go duration string (e.g.
2s,500ms). The timeout value uses the AWS SDK default by default.Security Considerations
The AWS Secrets Manager and Config Provider provides compatibility for legacy applications that access secrets as mounted files in the pod. Security conscious applications should use the native AWS APIs to fetch secrets and optionally cache them in memory rather than storing them in the file system.
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.