-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Add] Added AWS secret manager support (#10)
* Added Badges for Project Signed-off-by: iamabhishek-dubey <[email protected]> * Added Badges for Project Signed-off-by: iamabhishek-dubey <[email protected]> * Added Badges for Project Signed-off-by: iamabhishek-dubey <[email protected]> * Added Badges for Project Signed-off-by: iamabhishek-dubey <[email protected]> * Added AWS secret manager support Signed-off-by: iamabhishek-dubey <[email protected]> * Added an example for AWS Signed-off-by: iamabhishek-dubey <[email protected]> * Added AWS information in README Signed-off-by: iamabhishek-dubey <[email protected]> * Added AWS information in README Signed-off-by: iamabhishek-dubey <[email protected]> * Updated docs with latest information Signed-off-by: iamabhishek-dubey <[email protected]>
- Loading branch information
1 parent
52cbee2
commit 78f86f1
Showing
25 changed files
with
301 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type aws struct { | ||
config struct { | ||
enabled bool | ||
region string | ||
secretName string | ||
previousVersion string | ||
roleARN string | ||
} | ||
} | ||
|
||
func (aws *aws) mutateContainer(container corev1.Container) corev1.Container { | ||
container = aws.setArgs(container) | ||
return container | ||
} | ||
|
||
func (aws *aws) setArgs(c corev1.Container) corev1.Container { | ||
args := []string{"aws"} | ||
args = append(args, fmt.Sprintf("--region=%s", aws.config.region)) | ||
|
||
if aws.config.secretName != "" { | ||
args = append(args, fmt.Sprintf("--secret-name=%s", aws.config.secretName)) | ||
} | ||
|
||
if aws.config.roleARN != "" { | ||
args = append(args, fmt.Sprintf("--role-arn=%s", aws.config.roleARN)) | ||
} | ||
|
||
if aws.config.secretName != "" { | ||
args = append(args, fmt.Sprintf("--previous-version=%s", aws.config.previousVersion)) | ||
} | ||
|
||
args = append(args, "--") | ||
c.Args = append(args, c.Args...) | ||
return c | ||
} |
This file contains 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 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 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 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,79 @@ | ||
# AWS Secret Manager | ||
|
||
Let's try to create a deployment to inject secrets directly from AWS Secret Manager. For example, purpose we are taking mysql as deployment and then we will try to set mysql root password using k8s-vault-webhook. | ||
|
||
We can use our [example](https://github.com/OT-CONTAINER-KIT/k8s-vault-webhook/tree/master/example) folder. | ||
|
||
The environment variables will get substitute automatically, we just have to provide some custom annotations. | ||
|
||
```yaml | ||
template: | ||
metadata: | ||
labels: | ||
app: k8s-aws-mysql | ||
tier: mysql | ||
annotations: | ||
aws.opstree.secret.manager/enabled: "true" | ||
aws.opstree.secret.manager/region: "us-west-2" | ||
# Use this role-arn if cluster is configured in AWS | ||
# aws.opstree.secret.manager/role-arn: "arn:aws:iam::999:role/secretManager" | ||
aws.opstree.secret.manager/secret-name: "test-secret" | ||
spec: | ||
containers: | ||
- image: opstree/mysql:latest | ||
name: mysql | ||
# If running outside AWS | ||
env: | ||
- name: AWS_ACCESS_KEY_ID | ||
valueFrom: | ||
secretKeyRef: | ||
name: aws-secret | ||
key: AWS_ACCESS_KEY_ID | ||
- name: AWS_SECRET_ACCESS_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: aws-secret | ||
key: AWS_SECRET_ACCESS_KEY | ||
``` | ||
Let's try to apply the deployment manifest. | ||
```shell | ||
$ kubectl apply -f example/aws-mysql-example.yaml | ||
... | ||
deployment.apps/k8s-aws-mysql configured | ||
``` | ||
|
||
Verify the mysql pods are running or not by using `kubectl` command line. | ||
|
||
```shell | ||
$ kubectl get pods | ||
... | ||
NAME READY STATUS RESTARTS AGE | ||
k8s-aws-mysql-5fcb986486-npjql 1/1 Running 0 16h | ||
``` | ||
|
||
Now let's try to get inside the `mysql` pod and see if the AWS Secret Manager's password is working fine or not. | ||
|
||
```shell | ||
$ kubectl exec -it k8s-aws-mysql-5fcb986486-npjql \ | ||
-- mysql -u root -pawspassword -e "show databases;" | ||
... | ||
Warning: Using a password on the command line interface can be insecure. | ||
+--------------------+ | ||
| Database | | ||
+--------------------+ | ||
| information_schema | | ||
| mysql | | ||
| performance_schema | | ||
+--------------------+ | ||
``` | ||
|
||
Also, try to check the value in environment variable of MySQL pod. | ||
|
||
```shell | ||
$ kubectl exec -it k8s-aws-mysql-5fcb986486-npjql \ | ||
-- env | grep ROOT | ||
... | ||
No output | ||
``` |
This file contains 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,25 @@ | ||
# AWS Secret Manager | ||
|
||
For integrating AWS Secret Manager with the K8s Vault Webhook, first we need to setup AWS Secret Manager inside AWS account. | ||
|
||
Here we will talk about the integration of AWS Secret Manager inside Kubernetes. | ||
|
||
## Secret Manager Setup | ||
|
||
Login into the [AWS Management Console](https://console.aws.amazon.com/console/home?nc2=h_ct&src=header-signin) and select [AWS Secret Manager](https://aws.amazon.com/secrets-manager/) service. | ||
|
||
![](./images/aws-secret-manager-aws.png) | ||
|
||
Create a secret in the secret-manager and select the secret type `Other type of secrets` and specify the key value pairs with these details. | ||
|
||
|**Key**|**Value**| | ||
|-------|---------| | ||
| MYSQL_ROOT_PASSWORD | awspassword | | ||
|
||
![](./images/aws-secret-manager-config.png) | ||
|
||
You should provide and description as well to the secret. | ||
|
||
![](./images/aws-secret-manager-name.png) | ||
|
||
Create the secret after all configuration to use it inside Kubernetes. |
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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
Oops, something went wrong.