Skip to content

Instantly share code, notes, and snippets.

@pataiji
pataiji / clone.sh
Last active July 5, 2022 02:23
Clone multiple repositories
#!/bin/bash
repos=$(gh repo list hoge_org \
--no-archived \
--limit 1000 \
--json name \
--jq '.[].name')
for repo in $repos;
do
@pataiji
pataiji / create_security_hub_topics_all_region.sh
Created September 22, 2021 04:41
Create eventbridge rule and sns topic for security hub
#!/bin/bash
regions=( \
us-east-1 \
us-east-2 \
us-west-1 \
us-west-2 \
ap-south-1 \
ap-northeast-3 \
ap-northeast-2 \
@pataiji
pataiji / all_s3_buckets_restrict_public_access.sh
Last active September 22, 2021 04:42
Restrict public access to all S3 buckets.
#!/bin/bash
aws s3api list-buckets | \
jq '.Buckets[].Name' -r | \
AWS_PAGER="" xargs -IXXX aws s3api put-public-access-block \
--bucket XXX \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
@pataiji
pataiji / default_sg_restrict_all_traffic.sh
Last active September 22, 2021 02:07
Revoke all ingress/egress permissions from default security groups in all regions
#!/bin/bash
# * EC2.2 The VPC default security group should not allow inbound and outbound traffic
# * https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards-fsbp-controls.html#ec2-2-remediation
# * 4.3 Ensure the default security group of every VPC restricts all traffic
# * https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cis-controls.html#cis-4.3-remediation
regions=$(aws ec2 describe-regions --query Regions[*].RegionName --output text)
for region in ${regions[@]}
do
@pataiji
pataiji / list_iam_user_policies.sh
Last active September 7, 2021 08:00
List IAM User Policies
#!/bin/bash
users=$(aws iam list-users --query 'Users[].UserName' --output text)
for user in $users; do
mkdir -p "$user"
policyNames=$(aws iam list-user-policies --user-name "$user" --query 'PolicyNames[]' --output text)
for policyName in $policyNames; do
aws iam get-user-policy --user-name "$user" --policy-name "$policyName" --output json > "${user}/${policyName}"
package main
import (
"fmt"
)
func main() {
for i := 1000; i <= 100000; i += 1000 {
n := scramble(uint32(i))
rn := scramble(n)
@pataiji
pataiji / _shortUUID.go
Last active June 18, 2020 10:47
Generate a short unique string from UUID in Go
package main
import (
"encoding/base32"
"fmt"
"github.com/google/uuid"
)
func main() {
@pataiji
pataiji / example.sh-session
Created May 27, 2020 01:52
github.com/stretchr/testify/suite setup and teardown order
$ go test -v ./tests/example/
=== RUN TestExampleTestSuite
TestExampleTestSuite: example_test.go:14: SetupSuite
=== RUN TestExampleTestSuite/TestExample1
TestExampleTestSuite/TestExample1: example_test.go:18: SetupTest
TestExampleTestSuite/TestExample1: example_test.go:22: BeforeTest suiteName=ExampleTestSuite testName=TestExample1
TestExampleTestSuite/TestExample1: example_test.go:26: TestExample1
TestExampleTestSuite/TestExample1: example_test.go:34: AfterTest suiteName=ExampleTestSuite testName=TestExample1
TestExampleTestSuite/TestExample1: example_test.go:38: TearDownTest
=== RUN TestExampleTestSuite/TestExample2
@pataiji
pataiji / run.sh
Created May 19, 2020 00:53
List VPC CidrBlocks
$ aws ec2 describe-vpcs | jq '.Vpcs[] | { CidrBlock: .CidrBlock, Name: .Tags[] | select(.Key == "Name").Value }'
@pataiji
pataiji / ec2ips
Last active July 19, 2019 12:58
Get IPs of EC2 Instances across AWS profiles
#!/bin/bash
# Required
# - awscli
# - jq
PROGNAME=$(basename $0)
export IDENTIFYING_TAG_NAME='Name'