-
Notifications
You must be signed in to change notification settings - Fork 985
(feat): adds publish support for aws secrets manager and parameter store #1953
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
Open
bruce-szalwinski-he
wants to merge
25
commits into
getsops:main
Choose a base branch
from
bruce-szalwinski-he:feature/aws-publishing-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
05e6728
support for aws secrets manager and parameter store
bruce-szalwinski-he 40b95a1
parameter store is json-based storage
bruce-szalwinski-he 047e3b6
feat: add AWS Secrets Manager key/value format testing and comprehens…
bruce-szalwinski-he bdd4676
remove unused
bruce-szalwinski-he 09d51b7
fix: make AWS Parameter Store Upload method consistent with other des…
bruce-szalwinski-he 217cb1b
throw not implemented for upload
bruce-szalwinski-he 7dd858e
test: update Parameter Store integration test to match new Upload beh…
bruce-szalwinski-he 292c9b0
remove unused
bruce-szalwinski-he 88fe4ae
remove unused
bruce-szalwinski-he 8a54645
docs on systems manager and parameter store
bruce-szalwinski-he cf02b0b
parameter store is always secureString
bruce-szalwinski-he 9427fab
words matter
bruce-szalwinski-he 60d2dba
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he b3880aa
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 6381192
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 8c372ed
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 92b333d
tidy
bruce-szalwinski-he 8b6814b
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he e5ea0d9
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 2a9721a
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 5510949
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he e6f0dc4
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he 7d5dddd
tidy
bruce-szalwinski-he 91b5bb7
Merge branch 'main' into feature/aws-publishing-support
bruce-szalwinski-he fc0767d
tidy
bruce-szalwinski-he File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1215,15 +1215,28 @@ This command requires a ``.sops.yaml`` configuration file. Below is an example: | |
| vault_kv_version: 2 # default | ||
| path_regex: vault/* | ||
| omit_extensions: true | ||
| - aws_secrets_manager_secret_name: "my-secret" | ||
| aws_region: "us-west-2" | ||
| path_regex: aws-secrets/* | ||
| - aws_parameter_store_path: "/sops/" | ||
| aws_region: "us-west-2" | ||
| path_regex: aws-params/* | ||
|
|
||
| The above configuration will place all files under ``s3/*`` into the S3 bucket ``sops-secrets``, | ||
| all files under ``gcs/*`` into the GCS bucket ``sops-secrets``, and the contents of all files under | ||
| ``vault/*`` into Vault's KV store under the path ``secrets/sops/``. For the files that will be | ||
| published to S3 and GCS, it will decrypt them and re-encrypt them using the | ||
| ``F69E4901EDBAD2D1753F8C67A64535C4163FB307`` pgp key. | ||
| all files under ``gcs/*`` into the GCS bucket ``sops-secrets``, the contents of all files under | ||
| ``vault/*`` into Vault's KV store under the path ``secrets/sops/``, files under ``aws-secrets/*`` | ||
| into AWS Secrets Manager as JSON secrets, and files under ``aws-params/*`` into AWS Parameter Store | ||
| as SecureString parameters. For the files that will be published to S3 and GCS, it will decrypt them | ||
| and re-encrypt them using the ``F69E4901EDBAD2D1753F8C67A64535C4163FB307`` pgp key. Files published to Vault | ||
| will be decrypted and stored as JSON data encrypted by Vault. Files published to AWS Secrets Manager and AWS Parameter Store | ||
| will be decrypted and stored as JSON data encrypted by AWS KMS. | ||
|
|
||
| You would deploy a file to S3 with a command like: ``sops publish s3/app.yaml`` | ||
|
|
||
| Similarly, you can publish to AWS Secrets Manager: ``sops publish aws-secrets/database-config.yaml`` | ||
|
|
||
| Or to AWS Parameter Store: ``sops publish aws-params/app-config.yaml`` | ||
|
|
||
| To publish all files in selected directory recursively, you need to specify ``--recursive`` flag. | ||
|
|
||
| If you don't want file extension to appear in destination secret path, use ``--omit-extensions`` | ||
|
|
@@ -1275,6 +1288,77 @@ Below is an example of publishing to Vault (using token auth with a local dev in | |
| example_number 42 | ||
| example_string bar | ||
|
|
||
| Publishing to AWS Secrets Manager | ||
| ********************************** | ||
|
|
||
| AWS Secrets Manager is a service that helps you protect secrets needed to access your applications, | ||
| services, and IT resources. SOPS can publish decrypted data directly to AWS Secrets Manager as JSON secrets. | ||
|
|
||
| There are a few settings for AWS Secrets Manager that you can place in your destination rules: | ||
|
|
||
| * ``aws_secrets_manager_secret_name`` - The name of the secret in AWS Secrets Manager. If not specified, the filename will be used as the secret name. | ||
| * ``aws_region`` - The AWS region where the secret should be stored. This is required. | ||
|
|
||
| SOPS uses the AWS SDK for Go v2, which automatically uses your configured AWS credentials from the AWS CLI, | ||
| environment variables, or IAM roles. | ||
|
|
||
| If the destination secret already exists in AWS Secrets Manager and contains the same data as the source | ||
| file, it will be skipped to avoid creating unnecessary versions. | ||
|
|
||
| Note: Recreation rules (re-encryption with different keys) are not supported for AWS Secrets Manager. | ||
| The data is decrypted from the source file and stored as plaintext JSON in the secret. | ||
|
|
||
| Below is an example of publishing to AWS Secrets Manager: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ export AWS_REGION=us-west-2 | ||
| $ sops decrypt aws-secrets/database-config.yaml | ||
| database: | ||
| host: db.example.com | ||
| port: 5432 | ||
| username: myuser | ||
| password: mypassword | ||
| $ sops publish aws-secrets/database-config.yaml | ||
| uploading /home/user/sops_directory/aws-secrets/database-config.yaml to AWS Secrets Manager secret database-config in us-west-2 ? (y/n): y | ||
| Successfully created secret database-config | ||
|
|
||
| Publishing to AWS Parameter Store | ||
| ********************************** | ||
|
|
||
| AWS Systems Manager Parameter Store provides secure, hierarchical storage for configuration data | ||
| and secrets management. SOPS can publish decrypted data directly to Parameter Store as JSON parameters encrypted by AWS KMS. | ||
|
|
||
| There are a few settings for AWS Parameter Store that you can place in your destination rules: | ||
|
|
||
| * ``aws_parameter_store_path`` - The parameter path in AWS Parameter Store. If it ends with ``/``, the filename will be appended. If not specified, the filename will be used as the parameter name with a leading ``/``. | ||
| * ``aws_region`` - The AWS region where the parameter should be stored. This is required. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should align to |
||
|
|
||
| All parameters are stored as ``SecureString`` type for security, since SOPS files may contain sensitive data. | ||
|
|
||
| SOPS uses the AWS SDK for Go v2, which automatically uses your configured AWS credentials from the AWS CLI, | ||
| environment variables, or IAM roles. | ||
|
|
||
| If the destination parameter already exists in AWS Parameter Store and contains the same data as the source | ||
| file, it will be skipped to avoid creating unnecessary versions. | ||
|
|
||
| Note: Recreation rules (re-encryption with different keys) are not supported for AWS Parameter Store. | ||
| The data is decrypted from the source file and stored as JSON in the SecureString parameter, encrypted by AWS KMS. | ||
|
|
||
| Below is an example of publishing to AWS Parameter Store: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ export AWS_REGION=us-west-2 | ||
| $ sops decrypt aws-params/app-config.yaml | ||
| app: | ||
| debug: false | ||
| database_url: postgres://user:pass@localhost/db | ||
| api_key: secret-api-key | ||
| $ sops publish aws-params/app-config.yaml | ||
| uploading /home/user/sops_directory/aws-params/app-config.yaml to AWS Parameter Store parameter /app-config in us-west-2 ? (y/n): y | ||
| Successfully created parameter /app-config | ||
|
|
||
|
|
||
| Important information on types | ||
| ------------------------------ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package config | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. config_test was getting a little long, so added aws config tests as separate file. |
||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var sampleConfigWithAWSSecretsManagerDestinationRules = []byte(` | ||
| creation_rules: | ||
| - path_regex: foobar* | ||
| kms: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012" | ||
| destination_rules: | ||
| - aws_secrets_manager_region: "us-east-1" | ||
| aws_secrets_manager_secret_name: "myapp/database" | ||
| path_regex: "^secrets/.*" | ||
| - aws_secrets_manager_region: "us-west-2" | ||
| path_regex: "^west-secrets/.*" | ||
| `) | ||
|
|
||
| var sampleConfigWithAWSParameterStoreDestinationRules = []byte(` | ||
| creation_rules: | ||
| - path_regex: foobar* | ||
| kms: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012" | ||
| destination_rules: | ||
| - aws_parameter_store_region: "us-east-1" | ||
| aws_parameter_store_path: "/myapp/config" | ||
| aws_parameter_store_type: "SecureString" | ||
| path_regex: "^parameters/.*" | ||
| - aws_parameter_store_region: "us-west-2" | ||
| aws_parameter_store_path: "/myapp/west/" | ||
| aws_parameter_store_type: "String" | ||
| path_regex: "^west-parameters/.*" | ||
| `) | ||
|
|
||
| var sampleConfigWithMixedAWSDestinationRules = []byte(` | ||
| creation_rules: | ||
| - path_regex: foobar* | ||
| kms: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012" | ||
| destination_rules: | ||
| - aws_secrets_manager_region: "us-east-1" | ||
| aws_secrets_manager_secret_name: "myapp/database" | ||
| path_regex: "^secrets/.*" | ||
| - aws_parameter_store_region: "us-east-1" | ||
| aws_parameter_store_path: "/myapp/config" | ||
| path_regex: "^parameters/.*" | ||
| - s3_bucket: "mybucket" | ||
| path_regex: "^s3/.*" | ||
| `) | ||
|
|
||
| func TestLoadConfigFileWithAWSSecretsManagerDestinationRules(t *testing.T) { | ||
| conf, err := parseDestinationRuleForFile(parseConfigFile(sampleConfigWithAWSSecretsManagerDestinationRules, t), "secrets/database.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| path := conf.Destination.Path("database.yaml") | ||
| assert.Contains(t, path, "arn:aws:secretsmanager:us-east-1:*:secret:myapp/database") | ||
|
|
||
| // Test with region but no specific secret name - this should match the second rule | ||
| conf, err = parseDestinationRuleForFile(parseConfigFile(sampleConfigWithAWSSecretsManagerDestinationRules, t), "west-secrets/api.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| path = conf.Destination.Path("api.yaml") | ||
| assert.Contains(t, path, "arn:aws:secretsmanager:us-west-2:*:secret:api.yaml") | ||
| } | ||
|
|
||
| func TestLoadConfigFileWithAWSParameterStoreDestinationRules(t *testing.T) { | ||
| conf, err := parseDestinationRuleForFile(parseConfigFile(sampleConfigWithAWSParameterStoreDestinationRules, t), "parameters/app.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| assert.Equal(t, "/myapp/config", conf.Destination.Path("app.yaml")) | ||
|
|
||
| // Test with path ending with slash | ||
| conf, err = parseDestinationRuleForFile(parseConfigFile(sampleConfigWithAWSParameterStoreDestinationRules, t), "west-parameters/config.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| assert.Equal(t, "/myapp/west/config.yaml", conf.Destination.Path("config.yaml")) | ||
| } | ||
|
|
||
| func TestLoadConfigFileWithMixedAWSDestinationRules(t *testing.T) { | ||
| // Test AWS Secrets Manager | ||
| conf, err := parseDestinationRuleForFile(parseConfigFile(sampleConfigWithMixedAWSDestinationRules, t), "secrets/database.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| assert.Contains(t, conf.Destination.Path("database.yaml"), "arn:aws:secretsmanager:us-east-1:*:secret:myapp/database") | ||
|
|
||
| // Test AWS Parameter Store | ||
| conf, err = parseDestinationRuleForFile(parseConfigFile(sampleConfigWithMixedAWSDestinationRules, t), "parameters/config.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| assert.Equal(t, "/myapp/config", conf.Destination.Path("config.yaml")) | ||
|
|
||
| // Test S3 | ||
| conf, err = parseDestinationRuleForFile(parseConfigFile(sampleConfigWithMixedAWSDestinationRules, t), "s3/backup.yaml", nil) | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, conf.Destination) | ||
| assert.Contains(t, conf.Destination.Path("backup.yaml"), "s3://mybucket/backup.yaml") | ||
| } | ||
|
|
||
| func TestValidateMultipleDestinationsInRule(t *testing.T) { | ||
| invalidConfig := []byte(` | ||
| destination_rules: | ||
| - aws_secrets_manager_region: "us-east-1" | ||
| aws_parameter_store_region: "us-east-1" | ||
| path_regex: "^invalid/.*" | ||
| `) | ||
|
|
||
| _, err := parseDestinationRuleForFile(parseConfigFile(invalidConfig, t), "invalid/test.yaml", nil) | ||
| assert.NotNil(t, err) | ||
| assert.Contains(t, err.Error(), "more than one destinations were found") | ||
| } | ||
|
|
||
| func TestValidateConflictingAWSDestinations(t *testing.T) { | ||
| invalidConfig := []byte(` | ||
| destination_rules: | ||
| - aws_secrets_manager_region: "us-east-1" | ||
| s3_bucket: "mybucket" | ||
| path_regex: "^invalid/.*" | ||
| `) | ||
|
|
||
| _, err := parseDestinationRuleForFile(parseConfigFile(invalidConfig, t), "invalid/test.yaml", nil) | ||
| assert.NotNil(t, err) | ||
| assert.Contains(t, err.Error(), "more than one destinations were found") | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should align to
aws_secrets_manager_region