Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log & Monitor
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[AWS] Saving your secret on AWS Systems Manager – Parameter Store

Posted on August 31, 2022August 31, 2022 By nim No Comments on [AWS] Saving your secret on AWS Systems Manager – Parameter Store

Mình có câu hỏi nếu công ty sài aws và chưa có vault thì trên AWS có feature take care được việc này hem nhỉ?

Ok nhà nghèo lab thì chơi SSM nhé

Manual by hand

mình sẽ tạo trước 1 key và điền giá trị vào ô value

Khi mà mình tạo là dev/redis/hostname thì bị báo lỗi Parameter name must be a fully qualified name.

Giờ tạo bằng command
https://cloudaffaire.com/how-to-create-parameter-store-in-aws-ssm/

root@LP11-D7891:~# aws ssm put-parameter \
--region> --region us-east-1 \
ame "/d> --name "/dev/mysql/hostname" \
value "> --value "mysql.nimtechnology.com:3306" \
> --type String \
> --tags "Key=env,Value=dev"
{
    "Version": 1,
    "Tier": "Standard"
}

Nếu bạn có nhiều profile thì có thể thêm duôi sau:
--profile tc-fedramp-dev-mdcl-mdaas-engines

Giờ thực hiện get mấy key này

root@LP11-D7891:~# aws ssm get-parameter --region us-east-1 --name "/dev/mysql/hostname" --query "Parameter.Value" --output text
mysql.nimtechnology.com:3306
aaaaa
bbbb
root@LP11-D7891:~# aws ssm get-parameter --region us-east-1 --name "/dev/mysql/hostname" --query "Parameter.Value" --output text | xargs
mysql.nimtechnology.com:3306 aaaaa bbbb

OK giờ mình sẽ tạo 1 user khác để và add policy cho user đó được quyền read secret Parameter Store

# Create IAM User
aws iam create-user --user-name readonly_ssm

# Create
aws iam create-policy \
    --policy-name AmazonParameterStoreReadOnlyPolicy \
    --policy-document \
'{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameter*"
      ],
      "Resource": "arn:aws:ssm:us-east-2:123456789012:parameter/dev*"
    }
  ]
}'
===>
==>output
{
    "Policy": {
        "PolicyName": "AmazonParameterStoreReadOnlyPolicy",
        "PolicyId": "ANPATU2QSHIIT2RROSEYE",
        "Arn": "arn:aws:iam::250887682577:policy/AmazonParameterStoreReadOnlyPolicy",
        "Path": "/",
        "DefaultVersionId": "v1",
        "AttachmentCount": 0,
        "PermissionsBoundaryUsageCount": 0,
        "IsAttachable": true,
        "CreateDate": "2022-08-31T06:39:57+00:00",
        "UpdateDate": "2022-08-31T06:39:57+00:00"
    }
}

Mình đã create được policy theo ý mình, bạn nhờ copy Policy ARN

# Attach ParameterStoreReadOnly Policy to User
aws iam attach-user-policy --policy-arn arn:aws:iam::250XXXX577:policy/AmazonParameterStoreReadOnlyPolicy --user-name readonly_ssm

# Set password for readonly_ssm user
aws iam create-login-profile --user-name readonly_ssm --password @SSMXXXReadOnly --no-password-reset-required


#Credentials for IAM User and make a note of them
aws iam create-access-key --user-name readonly_ssm

# Make a note of Access Key ID and Secret Access Key
User: readonly_ssm
{
    "AccessKey": {
        "UserName": "readonly_ssm",
        "AccessKeyId": "AKIATU2QSHIITN5ALD7E",
        "Status": "Active",
        "SecretAccessKey": "PGwAPd2VOZXXXXXXXXrAwY4GeiZLklBBTXMe+",
        "CreateDate": "2022-08-31T06:47:24+00:00"
    }
}

Giờ mình thực hiện thử get secret bằng user
Mình biết rằng mình đã sai cái Resource của IAM Policy

root@LP11-D7891:~# aws ssm get-parameter --region us-east-1 --name "/dev/redis/hostname" --query "Parameter.Value" --output text --profile default-readonly-ssm

An error occurred (AccessDeniedException) when calling the GetParameter operation: User: arn:aws:iam::250887682577:user/readonly_ssm is not authorized to perform: ssm:GetParameter on resource: arn:aws:ssm:us-east-1:250887682577:parameter/dev/redis/hostname because no identity-based policy allows the ssm:GetParameter action

Để tìm được Resource ARN tạo đại rồi get thử là 1 cách
==> arn:aws:ssm:us-east-1:250887682577:parameter/dev/redis/hostname

Hoặc như trong bài viết bên dưới:
https://docs.aws.amazon.com/systems-manager/latest/userguide/security_iam_service-with-iam.html
arn:aws:ssm:<region>:<account-id>:<maintenancewindow>/<window-id>

Ok giờ mình đã get được ok.

root@LP11-D7891:~# aws ssm get-parameter --region us-east-1 --name "/dev/redis/hostname" --query "Parameter.Value" --output text --profile default-readonly-ssm
redis.nimtechnology.com:6379


AWS - Amazon Web Service

Post navigation

Previous Post: [AWS] VPC PEERING – Connecting between other VPCs.
Next Post: [Demo] Instructing configure AssumeRole – IAM on AWS

More Related Articles

[AWS] EKS IAM Roles for Service Accounts (IRSA) using Terraform AWS - Amazon Web Service
[VPC] The difference between public and private subnets in Amazon VPC? AWS - Amazon Web Service
[AWS] Provision AWS IAM Admin User as EKS Admin AWS - Amazon Web Service
[AWS] Setup Schedule Action for Auto Scaling Group – Saving Cost is based on ASG AWS - Amazon Web Service
[AWS] Solutions Architect Professional: Lesson 1 – Identity & Federation AWS - Amazon Web Service
Manage Kubernetes Secrets With External Secrets Operator AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • Experiences for IP Addresses Shortage on EKS Clusters March 29, 2023
  • [Talisman] Discover the sensitive information in your code. March 28, 2023
  • [Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. March 27, 2023
  • [Kong Gateway] WebSocket connection failed March 26, 2023
  • [Nextcloud] Can’t download files to have a size bigger than 2Gi on NextCloud – RaspBerry March 24, 2023

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • MetalLB
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.