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
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • 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, 2022May 24, 2023 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-nimtechnology-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] Using FSx Lustre to enhance disk performance for large-scale applications. AWS - Amazon Web Service
[Terraform] Solve “Redundant ignore_changes element” on EKSmodule AWS - Amazon Web Service
[AWS] Creating EKS windows on AWS and Running windows pods AWS - Amazon Web Service
[AWS] Provision AWS IAM Admin User as EKS Admin AWS - Amazon Web Service
[Terraform] ResourceAlreadyExistsException: The specified log group already exists AWS - Amazon Web Service
[Kafka/MSK] Install kafka or MSK on aws through terraform. 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

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • 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
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.