forked from 9652040795/aws-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws-secret-manager
140 lines (83 loc) · 3.16 KB
/
aws-secret-manager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Install mentioned below packages
yum update -y
yum install mysql -y
yum install jq -y
# https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-secret-value.html
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson | jq -r .username
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson | jq -r .password
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson | jq -r .host
aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson | jq -r .port
###################################################################################################################################
secret=`aws secretsmanager get-secret-value --secret-id MySQLSecret --region eu-central-1 | jq .SecretString | jq fromjson`
echo $secret
username=`echo $secret | jq -r .username`
echo $username
password=`echo $secret | jq -r .password`
echo $password
host=`echo $secret | jq -r .host`
echo $host
port=`echo $secret | jq -r .port`
echo $port
mysql -h $host -u $username -P $port -p$password
# Secret-Manager-Policy
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
],
"Effect": "Allow",
"Resource": ["arn:aws:secretsmanager:*:*:secret:${var.name}"]
}
]
}
EOF
}
############################################################################
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"secretsmanager:GetSecretValue",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"kms:DescribeKey",
"kms:ListAliases",
"kms:ListKeys",
"rds:DescribeDBClusters",
"rds:DescribeDBInstances",
"tag:GetResources"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
###################################################################################################################
#!/bin/bash
yum update -y
yum install mysql -y
yum install jq -y
secretid='Cloudelligent_Mysql_Password'
secret=`aws secretsmanager get-secret-value --secret-id $secretid --region eu-central-1 | jq .SecretString | jq fromjson`
echo $secret
username=`echo $secret | jq -r .username`
echo $username
password=`echo $secret | jq -r .password`
echo $password
host=`echo $secret | jq -r .host`
echo $host
port=`echo $secret | jq -r .port`
echo $port
mysql -h $host -u $username -P $port -p$password
#END