Giter Club home page Giter Club logo

pcs-sizing-scripts's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcs-sizing-scripts's Issues

AWS Organizations integration fails after scanning the first member account

Describe the bug

When run using org mode, the first member account will be scanned. All of the other accounts will fail.

Expected behavior

It should scan all of the member accounts

Current behavior

Warning: Failed to assume role into Member Account …, skipping ...

If you remove the 2>/dev/null which discards the error output from the aws sts assume-role command you'll see this additional detail:

Unable to locate credentials. You can configure credentials by running "aws configure".

Possible solution

Reviewing the code from #2, I believe the problem is related to the way assume_role() overwrites its current credentials with the assumed role credentials, which allows that account to be scanned but then causes all subsequent accounts to fail since you'd need to call sts:AssumeRole using the original credentials.

SESSION_JSON=$(aws_sts_assume_role "${ACCOUNT_ASSUME_ROLE_ARN}")
if [ $? -ne 0 ] || [ -z "${SESSION_JSON}" ]; then
ASSUME_ROLE_ERROR="true"
echo " Warning: Failed to assume role into Member Account ${ACCOUNT_NAME} (${ACCOUNT_ID}), skipping ..."
else
# Export environment variables used to connect to this member account.
AWS_ACCESS_KEY_ID=$(echo "${SESSION_JSON}" | jq .Credentials.AccessKeyId 2>/dev/null | sed -e 's/^"//' -e 's/"$//')
AWS_SECRET_ACCESS_KEY=$(echo "${SESSION_JSON}" | jq .Credentials.SecretAccessKey 2>/dev/null | sed -e 's/^"//' -e 's/"$//')
AWS_SESSION_TOKEN=$(echo "${SESSION_JSON}" | jq .Credentials.SessionToken 2>/dev/null | sed -e 's/^"//' -e 's/"$//')
export AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY
export AWS_SESSION_TOKEN
fi
fi

Steps to reproduce

  1. Run resource-count-aws.sh org with credentials in the Organization master account for an IAM user which has permission to assume the OrganizationAccountAccessRole in each member account.

[Community Health Assessment] Changes needed

Health Check Pass Score More Info
Contains a meaningful README.md file 20 / 20 More info
SUPPORT.md file exists 20 / 20 More info
Repo has a description 15 / 15 More info
Has a recognized open source license 15 / 15 More info
Has a descriptive repo name 15 / 15 More info
Required topics attached to repo 15 / 15 More info
CONTRIBUTING.md file with contribution guidelines 5 / 5 More info
Has custom issue and pull request templates 0 / 5 More info

Current score: 105
Target threshold: 100
Total possible: 110

The EC2 count is incorrect which case has multiple AMI Launch Index Value.

Describe the bug

resource-count-aws.sh

If there is an AMI launch Index, the EC2 count is different.

About AMI Lunch Index.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMI-launch-index-examples.html

Expected behavior

Multiple EC2 instances in the AMI Launch Index are counted.

Current behavior

Multiple EC2 instances in the AMI Launch Index are not counted.

Possible solution

I am not good at jq.
For example, I think it is possible to implement the following using grep and wc.

resource-count-aws.sh
line 293
RESOURCE_COUNT=$(aws_ec2_describe_instances "${i}" | grep InstanceId | wc -l' 2>/dev/null)

Support for ELBv2

Is your feature request related to a problem?

It seems we are only checking for elb, and not including elbv2 as part of our API queries.

Describe the solution you'd like

I would like us to include support for aws elbv2 describe-load-balancers.

Describe alternatives you've considered

Asking the client for how many ELBs they are using.

Additional context

This issue was identified by a client during a PoC. They ran the script, and it returned zero for the ELB service. However, the client knows that they have several ELBs.

ECS Task is not counted correctly.

Describe the bug

In cwp mode, ECS Task is not counted correctly.
The number of ECS Fargate Tasks cannot be obtained correctly in aws-resource-count.sh with cwp option.

Expected behavior

To obtain the correct ECS cluster name and count the number of individual Fargate tasks.

Current behavior

FargateTask per cluster is not get correctly.

Possible solution

Modify the script function "get_ecs_fargate_task_count()".
For example, how about modifying the following?

https://github.com/PaloAltoNetworks/pcs-sizing-scripts/blob/main/aws/resource-count-aws.sh#L241-L253

  **ECS_FARGATE_CLUSTERS=($(aws_ecs_list_clusters "${REGION}" | jq -r '.clusterArns[]' 2>/dev/null))**

  XIFS=$IFS
  # shellcheck disable=SC2206
  **IFS=$'\n' ECS_FARGATE_CLUSTERS_LIST=(${ECS_FARGATE_CLUSTERS[@]})**
  IFS=$XIFS

  ECS_FARGATE_TASK_LIST_COUNT=0
  RESULT=0

  for CLUSTER in "${ECS_FARGATE_CLUSTERS_LIST[@]}"
  do
    **ECS_FARGATE_TASK_LIST_COUNT=($(aws_ecs_list_tasks "${REGION}" "${CLUSTER}" | jq -r '[.taskArns[]] | length' 2>/dev/null))**

Steps to reproduce

./resource-count-aws.sh cwp

AWS accounts beginning in 0 generate error at line 190

Describe the bug

If an AWS account within an organization begins with a zero, it reports an error at line 190 in the aws/resource-count-aws.sh.as follows:
./resource-count-aws.sh: line 190: [[: 012345678983: value too great for base (error token is "012345678983")

Expected behavior

Value is the test should be their string equivalent.

Current behavior

./resource-count-aws.sh: line 190: [[: 012345678983: value too great for base (error token is "012345678983")

Possible solution

Remove the double bracket test and use single brackets. See https://stackoverflow.com/questions/24777597/value-too-great-for-base-error-token-is-08

Steps to reproduce

At line 189, insert something like: ACCOUNT_ID=012345678983

Screenshots

Context

Your Environment

Aliyun Sizing Script

Describe the bug

On testing, I found there is a bug in Aliyun CLI which affects the sizing tool. With the bug, the sizing script would just return all 0 in the counting.

Expected behavior

The Aliyun Sizing Script is reading the "Total Count" attribute from the json obtained by "aliyun ecs describeinstances". The "Total Count" should report the total ECS (VM) instances number.

Current behavior

But perhaps an API bug from Alicloud side, the "Total Count" is always 0 even there are vm listed.
image

Possible solution

Amend the script function "get_instance_count()", skip relying on the "Total Count" attribute. Instead, add the new lines to count the instances number instead.

get_instance_count() {
COUNT=0
RESULT=$(abc_compute_instances_list "${1}")
// COUNT=$(echo "${RESULT}" | jq -r '.TotalCount' 2>/dev/null) //commented this original line
INSTANCES=($(echo "${RESULT}" | jq -r '.Instances.Instance[].InstanceId' 2>/dev/null)) //add new line 1
COUNT=$((COUNT + ${#INSTANCES[@]})) //add new line 2
echo "${COUNT}"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.