Skip to content

Instantly share code, notes, and snippets.

View z0ph's full-sized avatar
🚀
Love People and use things, because the opposite never works

Victor GRENU z0ph

🚀
Love People and use things, because the opposite never works
View GitHub Profile
@z0ph
z0ph / unusd-cloud-policy.json
Last active September 4, 2023 20:24
unusd.cloud - inline IAM policy
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"ce:GetCostAndUsage",
"ce:GetCostForecast",
"cloudwatch:GetMetricStatistics",
"ec2:Describe*",
"ec2:List*",
"glue:GetDevEndpoints",
@z0ph
z0ph / accessdenied.sql
Created July 4, 2022 12:51
For CopyPasteOps Only - Query for CloudWatch Logs Insights on Cloudtrail LogGroup
filter errorCode="AccessDenied"
| fields eventTime, eventName, eventSource, userIdentity.sessionContext.sessionIssuer.userName
@z0ph
z0ph / sso_assumer.sh
Created June 3, 2022 13:46
Bash script to run an AWS CLI command across all your AWS Accounts (AWS SSO wide)
#!/bin/bash
# From Victor (zoph) Grenu from zoph.io - https://zoph.io
# Twitter: @zoph
TARGET_ROLE_NAME="AdministratorAccess"
## Get list of AWS accounts using SSO
AWS_ACCESS_TOKEN=$(cat $(ls -1d ~/.aws/sso/cache/* | grep -v botocore) | jq -r "{accessToken} | .[]")
ACCOUNTS_IDS=($(aws sso list-accounts --access-token $AWS_ACCESS_TOKEN | jq -r '.accountList[] | .accountId'))
@z0ph
z0ph / loop.sh
Last active July 22, 2022 10:29
Loop on put alternate contacts across AWS Org
#!/bin/bash
# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/account/put-alternate-contact.html
# Parameters
SECURITY_EMAIL="victor@zoph.io"
SECURITY_PHONE=""
SECURITY_TITLE="Owner"
SECURITY_NAME="Victor Grenu"
@z0ph
z0ph / find_loggroups_size.sh
Last active December 16, 2021 21:09
Find AWS CloudWatch LogGroups size + retention | sorted
aws logs describe-log-groups \
--query "logGroups[*].{LogGroup:logGroupName,VolumeSize:storedBytes,RetentionInDays:retentionInDays} | reverse(sort_by(@, &VolumeSize))" \
--output table
import boto3
import re
from urllib.request import urlopen
import logging
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/config.html#ConfigService.Client.put_configuration_recorder
# Purpose:
# Activate Custom AWS Record for AWS Config
# Supported resource type: https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html#supported-resources
@z0ph
z0ph / deprecated-policies.json
Created April 2, 2021 07:39
List of MAMIP Archive deprecated AWS Managed Policies
[
"TagGovernancePolicy",
"AWSLambdaReadOnlyAccess",
"AmazonEC2RolePolicyForApplicationWizard",
"AmazonEverestServicePolicy",
"AmazonEC2SpotFleetRole",
"AWSOpsWorksFullAccess",
"AWSSchemasServiceRolePolicy",
"AmazonMechanicalTurkCrowdReadOnlyAccess",
"AmazonApplicationWizardFullaccess",
@z0ph
z0ph / findings.txt
Last active December 17, 2021 00:17
AWS Access Analyzer - Policy Validation of 837 AWS Managed Policies.
==> Validation of: ./policies/TagGovernancePolicy
==> Finding: [
{
"findingDetails": "Using ForAllValues qualifier with the single-valued condition key organizations:ServicePrincipal can be overly permissive. We recommend that you remove ForAllValues:.",
"findingType": "SECURITY_WARNING",
"issueCode": "FORALLVALUES_WITH_SINGLE_VALUED_KEY",
"learnMoreLink": "https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-policy-checks.html#access-analyzer-reference-policy-checks-security-warning-forallvalues-with-single-valued-key",
"locations": [
{
"path": [
@z0ph
z0ph / unfollow_everyone.py
Created March 15, 2021 17:20
Unfollow everyone on Twitter.
#!/usr/bin/env python
import tweepy
from config import create_api
def unfollow_everyone(api):
friends = api.friends_ids("<your_twitter_screen_name")
for f in friends:
@z0ph
z0ph / s3BucketsEncryptionLookup.sh
Last active June 17, 2020 13:31
Retrieve S3 Buckets Encryption status
for ITEM in $(aws s3api list-buckets --output json |grep "Name" | cut -d":" -f2 | cut -d'"' -f2); do echo $ITEM " --- " $(aws s3api get-bucket-encryption --bucket $ITEM 2>&1); done