sigs.k8s.io/cluster-api-provider-aws@v1.5.5/scripts/ci-aws-cred-test.sh (about) 1 #!/bin/bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 GROUP_NAME=capa-cred-test-group-$(openssl rand -hex 8) 22 USERNAME=capa-cred-test-user-$(openssl rand -hex 8) 23 24 echo "Group: ${GROUP_NAME} User: ${USERNAME}" 25 26 export AWS_CONFIG_FILE=/etc/aws-cred/credentials 27 28 echo "Creating IAM group" 29 aws iam create-group --group-name "${GROUP_NAME}" 30 31 echo "Attaching Policies" 32 aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name "${GROUP_NAME}" 33 aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name "${GROUP_NAME}" 34 aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name "${GROUP_NAME}" 35 36 echo "Creating User" 37 aws iam create-user --user-name "${USERNAME}" 38 39 echo "Adding User to Group" 40 aws iam add-user-to-group --user-name "${USERNAME}" --group-name "${GROUP_NAME}" 41 42 echo -e "### Clean up ###\n" 43 echo -e "\n" 44 45 echo "Remove user from group" 46 aws iam remove-user-from-group --user-name "${USERNAME}" --group-name "${GROUP_NAME}" 47 48 echo "Delete user" 49 aws iam delete-user --user-name "${USERNAME}" 50 51 echo "Detach policies" 52 aws iam detach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name "${GROUP_NAME}" 53 aws iam detach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name "${GROUP_NAME}" 54 aws iam detach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name "${GROUP_NAME}" 55 56 echo "Delete group" 57 aws iam delete-group --group-name "${GROUP_NAME}" 58 59 echo "All tasks done"