Skip to content

Commit

Permalink
add stats and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Jan 26, 2023
1 parent 3fa26d4 commit 6fe304b
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
shell: bash
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/
~/go/bin/
key: ${{ runner.os }}-go-cache-${{ hashFiles('go.sum', 'hack/toolchain.sh') }}
- name: Verify
run: make toolchain verify
16 changes: 16 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,19 @@ jobs:
with:
name: aca
path: dist/*
- run: |
RELEASE_VERSION=${GITHUB_REF#refs/*/}
git config user.name "Release"
git config user.email "[email protected]"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPO}
git config pull.rebase false
BRANCH_NAME="release-${RELEASE_VERSION}"
git checkout -b "${BRANCH_NAME}"
git add README.md
git commit -m "Release updates ${RELEASE_VERSION}."
git push --set-upstream origin "${BRANCH_NAME}"
gh pr create --title "chore: Release ${RELEASE_VERSION}" --body "Release ${RELEASE_VERSION}" --base main --head "release-${RELEASE_VERSION}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BUILD_DIR ?= $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))/build
VERSION ?= $(shell git describe --tags --always --dirty)
PREV_VERSION ?= $(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
GOOS ?= $(shell uname | tr '[:upper:]' '[:lower:]')
GOARCH ?= $(shell [[ `uname -m` = "x86_64" ]] && echo "amd64" || echo "arm64" )
GOPROXY ?= "https://proxy.golang.org|direct"
Expand Down Expand Up @@ -31,7 +32,11 @@ licenses: ## Verifies dependency licenses
go mod download
! go-licenses csv ./... | grep -v -e 'MIT' -e 'Apache-2.0' -e 'BSD-3-Clause' -e 'BSD-2-Clause' -e 'ISC' -e 'MPL-2.0'

update-readme: ## Updates readme to refer to latest release
sed -E -i.bak "s|$(shell echo ${PREV_VERSION} | tr -d 'v' | sed 's/\./\\./g')([\"_/])|$(shell echo ${VERSION} | tr -d 'v')\1|g" README.md
rm -f *.bak

help: ## Display help
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: all build test verify help licenses fmt version
.PHONY: all build test verify help licenses fmt version update-readme
80 changes: 46 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,49 @@ Examples:
Flags:
-a, --api string API maps to EventName within CloudTrail Examples are DescribeInstances, TerminateInstances, etc
-c, --call-source string CallSource maps to SourceIP in CloudTrail but AWS services will include a named source IP like eks.amazonaws.com or autoscaling.amazonaws.com
-e, --end-time string End time for event filtering. Default: 30m ago (default "2023-01-26T14:28:12-06:00")
-e, --end-time string End time for event filtering. Default: 30m ago (default 3fa26d4-dirty"2023-01-26T22:55:52Z3fa26d4-dirty")
--event-source string EventSource is the top-level service where the API call is made from (i.e. ec2.amazonaws.com)
-h, --help help for aca
-i, --identity-user-name string IdentityUserName is included in the CloudTrailEvent.userIdentity.sessionContext.sessionIssuer.userName and is useful to scope the filtering to a specific instance of an application making API calls
-o, --output string Output (json|chart) Default: json (default "json")
-o, --output string Output (json|chart|stats) Default: json (default 3fa26d4-dirty"json3fa26d4-dirty")
-r, --region string AWS Region
-s, --start-time string Start time for event filtering. Default: now (default "2023-01-26T13:58:12-06:00")
-s, --start-time string Start time for event filtering. Default: now (default 3fa26d4-dirty"2023-01-26T22:25:52Z3fa26d4-dirty")
-u, --user-agent string UserAgent partial will check if the passed string is contained within the user-agent field
```

## Installation

Packages, binaries, and archives are published for all major platforms (Mac amd64/arm64 & Linux amd64/arm64):
Packages, binaries, and archives are published for all major platforms (Mac amd643fa26d4-dirty/arm64 & Linux amd643fa26d4-dirty/arm64):

Debian / Ubuntu:
Debian 3fa26d4-dirty/ Ubuntu:

```
[[ `uname -m` == "aarch64" ]] && ARCH="arm64" || ARCH="amd64"
wget https://github.com/bwagner5/api-call-analyzer/releases/download/v0.0.1/api-call-analyzer_0.0.1_linux_${ARCH}.deb
dpkg --install aca_0.0.1_linux_${ARCH}.deb
[[ `uname -m` == 3fa26d4-dirty"aarch643fa26d4-dirty" ]] && ARCH=3fa26d4-dirty"arm643fa26d4-dirty" || ARCH=3fa26d4-dirty"amd643fa26d4-dirty"
wget https:3fa26d4-dirty/3fa26d4-dirty/github.com3fa26d4-dirty/bwagner53fa26d4-dirty/api-call-analyzer3fa26d4-dirty/releases3fa26d4-dirty/download3fa26d4-dirty/v0.0.13fa26d4-dirty/api-call-analyzer3fa26d4-dirty_0.0.13fa26d4-dirty_linux3fa26d4-dirty_${ARCH}.deb
dpkg --install aca3fa26d4-dirty_0.0.13fa26d4-dirty_linux3fa26d4-dirty_${ARCH}.deb
```

RedHat:

```
[[ `uname -m` == "aarch64" ]] && ARCH="arm64" || ARCH="amd64"
rpm -i https://github.com/bwagner5/api-call-analyzer/releases/download/v0.0.1/api-call-analyzer_0.0.1_linux_${ARCH}.rpm
[[ `uname -m` == 3fa26d4-dirty"aarch643fa26d4-dirty" ]] && ARCH=3fa26d4-dirty"arm643fa26d4-dirty" || ARCH=3fa26d4-dirty"amd643fa26d4-dirty"
rpm -i https:3fa26d4-dirty/3fa26d4-dirty/github.com3fa26d4-dirty/bwagner53fa26d4-dirty/api-call-analyzer3fa26d4-dirty/releases3fa26d4-dirty/download3fa26d4-dirty/v0.0.13fa26d4-dirty/api-call-analyzer3fa26d4-dirty_0.0.13fa26d4-dirty_linux3fa26d4-dirty_${ARCH}.rpm
```

Download Binary Directly (Linux / Mac):
Download Binary Directly (Linux 3fa26d4-dirty/ Mac):

```
[[ `uname -m` == "aarch64" ]] && ARCH="arm64" || ARCH="amd64"
[[ `uname -m` == 3fa26d4-dirty"aarch643fa26d4-dirty" ]] && ARCH=3fa26d4-dirty"arm643fa26d4-dirty" || ARCH=3fa26d4-dirty"amd643fa26d4-dirty"
OS=`uname | tr '[:upper:]' '[:lower:]'`
wget -qO- https://github.com/bwagner5/api-call-analyzer/releases/download/v0.0.1/api-call-analyzer_0.0.1_${OS}_${ARCH}.tar.gz | tar xvz
wget -qO- https:3fa26d4-dirty/3fa26d4-dirty/github.com3fa26d4-dirty/bwagner53fa26d4-dirty/api-call-analyzer3fa26d4-dirty/releases3fa26d4-dirty/download3fa26d4-dirty/v0.0.13fa26d4-dirty/api-call-analyzer3fa26d4-dirty_0.0.13fa26d4-dirty_${OS}3fa26d4-dirty_${ARCH}.tar.gz | tar xvz
chmod +x aca
```

## Examples:

```
> aca --start-time 5m --call-source eks.amazonaws.com -o chart
2023/01/26 14:24:30 Filtered to 214 events out of 376
20233fa26d4-dirty/013fa26d4-dirty/26 14:24:30 Filtered to 214 events out of 376
EVENT SOURCE API CALL SOURCE IDENTITY USER AGENT
ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-ServiceRole-012345678901234567 eks.amazonaws.com
ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-ServiceRole-012345678901234567 eks.amazonaws.com
Expand All @@ -70,7 +70,7 @@ ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-Ser

```
> aca --start-time 5m --api DescribeInstances -o chart
2023/01/26 14:24:30 Filtered to 214 events out of 376
20233fa26d4-dirty/013fa26d4-dirty/26 14:24:30 Filtered to 214 events out of 376
EVENT SOURCE API CALL SOURCE IDENTITY USER AGENT
ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-ServiceRole-012345678901234567 eks.amazonaws.com
ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-ServiceRole-012345678901234567 eks.amazonaws.com
Expand All @@ -82,24 +82,36 @@ ec2.amazonaws.com CreateTags eks.amazonaws.com eksctl-my-demo-us-east-2-clus-Ser

```
> aca --start-time 5m --user-agent 'karpenter.sh-v0.23.0' -o chart
2023/01/26 14:27:20 Filtered to 9 events out of 405
20233fa26d4-dirty/013fa26d4-dirty/26 14:27:20 Filtered to 9 events out of 405
EVENT SOURCE API CALL SOURCE IDENTITY USER AGENT
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeSubnets 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeSubnets 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeSubnets 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypes 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeSubnets 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
ec2.amazonaws.com DescribeInstanceTypeOfferings 3.22.70.109 username-karpenter-dev-us-east-2-karpenter aws-sdk-go3fa26d4-dirty/1.44.154 (go1.19.4; linux; amd64) karpenter.sh-v0.23.0-3-gaece5998
```

```
> aca --start-time 15m --user-agent 'karpenter.sh-v0.23.0' -o stats
2023/01/26 17:07:12 Filtered to 33 events out of 1976. The last event's timestamp is 2023-01-26T23:04:48Z and the endtime filter was 2023-01-26T23:06:39Z
EVENT SOURCE API CALLS
ec2.amazonaws.com DescribeSubnets 3
ec2.amazonaws.com DescribeInstanceTypeOfferings 6
ec2.amazonaws.com DescribeInstanceTypes 24
TOTAL 33
```
Loading

0 comments on commit 6fe304b

Please sign in to comment.