Skip to content

Instantly share code, notes, and snippets.

@kajoj2
Last active January 10, 2021 20:39
Show Gist options
  • Save kajoj2/3237059ef978801d6db18872c78dfc40 to your computer and use it in GitHub Desktop.
Save kajoj2/3237059ef978801d6db18872c78dfc40 to your computer and use it in GitHub Desktop.

Originalna

{
    "Version": "2012-10-17",
    "Statement": [
        { // ta sekcja jest nie potrzebna działamy tylko na 1 buckecie
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListAllMyBuckets"
            ],
            "Resource": "*"
        }, 
        { 
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket/*"
            ]
        }
    ]
}

Poprawiona

{
    "Version": "2012-10-17",
    "Statement": [
        { 
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket/*"
            ]
        }
    ]
}

Zgodna z wymaganiami z zadania

Wymagania:

  • umieszczenie danych w s3
  • wylistowanie ich
{
    "Version": "2012-10-17",
    "Statement": [
        { 
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::chmurowiskobucket/*"
            ]
        }
    ]
}

Przetestowanie czy działa

  • Stworzenie roli z policy
  • podpięcie pod ec2 (w konsoli ec2 -> wybrac instancje -> Actions -> Security -> Modify IAM Role) Najlepiej instancja z amazon linux
  • Połączenie się z vm
  • komendy do sprawdzenia
    • wypisanie obiektów (jeśli bukcet pusty nie powinno nic być)
    aws s3 ls s3://chmurowiskobucket
    
    • stowrzenie pliku lokalnie i kopia jego do s3
    touch test
    aws s3 cp test  s3://chmurowiskobucket/test
    
    • wypisanie obiektów 2 raz (powinien być nasz plik)
    aws s3 ls s3://chmurowiskobucket
    

Dodadkowo policy można testowac przez policy simulator jest w konsoli IAM po prawej stronie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment